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
c73d8534
Commit
c73d8534
authored
May 26, 2020
by
Joanne Hugé
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
WIP
parent
a20f85ef
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
68 deletions
+63
-68
packet-exchange/src/send_packet.c
packet-exchange/src/send_packet.c
+63
-68
No files found.
packet-exchange/src/send_packet.c
View file @
c73d8534
...
...
@@ -41,8 +41,6 @@
#define MESSAGE ((uint32_t)0x00FACADE)
#define NSEC_PER_SEC 1000000000
#define DEBUG
static
int
process_socket_error_queue
(
int
fd
);
static
void
print_timestamps
(
struct
msghdr
*
msg
);
static
void
process_timestamps
(
int
sock
);
...
...
@@ -54,7 +52,7 @@ static size_t tx_buffer_len = sizeof(tx_buffer);
static
int
fd
;
static
int
so_timestamping_flags
=
SOF_TIMESTAMPING_RX_SOFTWARE
|
SOF_TIMESTAMPING_TX_SOFTWARE
|
SOF_TIMESTAMPING_SOFTWARE
|
SOF_TIMESTAMPING_RAW_HARDWARE
;
SOF_TIMESTAMPING_RX_SOFTWARE
|
SOF_TIMESTAMPING_TX_SOFTWARE
|
SOF_TIMESTAMPING_SOFTWARE
;
// Sets the interface
static
int
set_if
(
char
*
network_if
)
{
...
...
@@ -94,8 +92,7 @@ void init_udp_etf(int use_etf, int use_timestamps, int packet_priority,
if
(
use_etf
)
{
sk_txtime
.
clockid
=
CLOCK_ID
;
sk_txtime
.
flags
=
1
;
sk_txtime
.
flags
=
SOF_TXTIME_REPORT_ERRORS
;
sk_txtime
.
flags
=
0
;
if
(
setsockopt
(
fd
,
SOL_SOCKET
,
SO_TXTIME
,
&
sk_txtime
,
sizeof
(
sk_txtime
)))
error
(
EXIT_FAILURE
,
errno
,
"setsockopt SO_TXTIME failed
\n
"
);
...
...
@@ -132,7 +129,7 @@ void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime,
struct
pollfd
poll_fd
=
{
.
fd
=
fd
,
};
int
sendmsgerr
,
pollerr
;
int
sendmsgerr
;
memset
(
&
sin
,
0
,
sizeof
(
sin
));
sin
.
sin_family
=
AF_INET
;
...
...
@@ -165,15 +162,12 @@ void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime,
if
(
sendmsgerr
<
0
)
error
(
EXIT_FAILURE
,
errno
,
"sendmsg failed, ret value: %d
\n
"
,
sendmsgerr
);
for
(
int
i
=
0
;
i
<
(
use_timestamps
+
1
);
i
++
)
{
printf
(
"Polling...
\n
"
);
pollerr
=
poll
(
&
poll_fd
,
1
,
0
);
// If the poll revents containts a POLLERR flag
if
(
pollerr
==
1
&&
(
poll_fd
.
revents
&
POLLERR
))
{
process_socket_error_queue
(
fd
);
}
else
if
(
use_timestamps
)
{
process_timestamps
(
fd
);
}
if
(
use_timestamps
)
{
#ifdef DEBUG
printf
(
"Polling for timestamps...
\n
"
);
#endif
poll
(
&
poll_fd
,
1
,
0
);
process_timestamps
(
fd
);
}
}
...
...
@@ -203,59 +197,6 @@ static void process_timestamps(int sock) {
}
}
/*
* Code from scheduled_tx_tools
*/
static
int
process_socket_error_queue
(
int
fd
)
{
uint8_t
msg_control
[
CMSG_SPACE
(
sizeof
(
struct
sock_extended_err
))];
unsigned
char
err_buffer
[
sizeof
(
tx_buffer
)];
struct
sock_extended_err
*
serr
;
struct
cmsghdr
*
cmsg
;
__u64
tstamp
=
0
;
struct
iovec
iov
=
{.
iov_base
=
err_buffer
,
.
iov_len
=
sizeof
(
err_buffer
)};
struct
msghdr
msg
=
{.
msg_iov
=
&
iov
,
.
msg_iovlen
=
1
,
.
msg_control
=
msg_control
,
.
msg_controllen
=
sizeof
(
msg_control
)};
#ifdef DEBUG
printf
(
"process_socket_error_queue
\n
"
);
#endif
if
(
recvmsg
(
fd
,
&
msg
,
MSG_ERRQUEUE
)
==
-
1
)
{
fprintf
(
stderr
,
"recvmsg failed"
);
return
-
1
;
}
cmsg
=
CMSG_FIRSTHDR
(
&
msg
);
while
(
cmsg
!=
NULL
)
{
serr
=
(
void
*
)
CMSG_DATA
(
cmsg
);
if
(
serr
->
ee_origin
==
SO_EE_ORIGIN_TXTIME
)
{
tstamp
=
((
__u64
)
serr
->
ee_data
<<
32
)
+
serr
->
ee_info
;
switch
(
serr
->
ee_code
)
{
case
SO_EE_CODE_TXTIME_INVALID_PARAM
:
fprintf
(
stderr
,
"packet with tstamp %llu dropped due to invalid params
\n
"
,
tstamp
);
return
0
;
case
SO_EE_CODE_TXTIME_MISSED
:
fprintf
(
stderr
,
"packet with tstamp %llu dropped due to missed deadline
\n
"
,
tstamp
);
return
0
;
default:
return
-
1
;
}
}
cmsg
=
CMSG_NXTHDR
(
&
msg
,
cmsg
);
}
return
0
;
}
static
void
print_timestamps
(
struct
msghdr
*
msg
)
{
struct
cmsghdr
*
cmsg
;
...
...
@@ -309,3 +250,57 @@ static void print_timestamps(struct msghdr *msg) {
printf
(
"
\n
"
);
}
}
/*
* Code from scheduled_tx_tools
*/
static
int
process_socket_error_queue
(
int
fd
)
{
uint8_t
msg_control
[
CMSG_SPACE
(
sizeof
(
struct
sock_extended_err
))];
unsigned
char
err_buffer
[
sizeof
(
tx_buffer
)];
struct
sock_extended_err
*
serr
;
struct
cmsghdr
*
cmsg
;
__u64
tstamp
=
0
;
struct
iovec
iov
=
{.
iov_base
=
err_buffer
,
.
iov_len
=
sizeof
(
err_buffer
)};
struct
msghdr
msg
=
{.
msg_iov
=
&
iov
,
.
msg_iovlen
=
1
,
.
msg_control
=
msg_control
,
.
msg_controllen
=
sizeof
(
msg_control
)};
#ifdef DEBUG
printf
(
"process_socket_error_queue
\n
"
);
#endif
if
(
recvmsg
(
fd
,
&
msg
,
MSG_ERRQUEUE
)
==
-
1
)
{
fprintf
(
stderr
,
"recvmsg failed"
);
return
-
1
;
}
cmsg
=
CMSG_FIRSTHDR
(
&
msg
);
while
(
cmsg
!=
NULL
)
{
serr
=
(
void
*
)
CMSG_DATA
(
cmsg
);
if
(
serr
->
ee_origin
==
SO_EE_ORIGIN_TXTIME
)
{
tstamp
=
((
__u64
)
serr
->
ee_data
<<
32
)
+
serr
->
ee_info
;
switch
(
serr
->
ee_code
)
{
case
SO_EE_CODE_TXTIME_INVALID_PARAM
:
fprintf
(
stderr
,
"packet with tstamp %llu dropped due to invalid params
\n
"
,
tstamp
);
return
0
;
case
SO_EE_CODE_TXTIME_MISSED
:
fprintf
(
stderr
,
"packet with tstamp %llu dropped due to missed deadline
\n
"
,
tstamp
);
return
0
;
default:
return
-
1
;
}
}
cmsg
=
CMSG_NXTHDR
(
&
msg
,
cmsg
);
}
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