Commit 166ec762 authored by Joanne Hugé's avatar Joanne Hugé

Fix rx_timestamps on reception

parent 8b83646b
......@@ -32,7 +32,7 @@
#define BUFFER_SIZE 1024
static void process_timestamps(packet_timestamps_t *packet_ts, int64_t histograms[NB_HISTOGRAMS][MAX_HIST_VAL]);
static void fill_histograms(packet_timestamps_t *packet_ts, int64_t histograms[NB_HISTOGRAMS][MAX_HIST_VAL]);
static char rx_buffer[BUFFER_SIZE];
static int sock_fd;
......@@ -108,17 +108,17 @@ int init_udp_recv(int use_timestamps, char *network_if) {
*/
packet_timestamps_t recv_udp_packet(int use_timestamps, int64_t histograms[NB_HISTOGRAMS][MAX_HIST_VAL]) {
struct cmsghdr *cmsg;
struct msghdr msg; // Message hardware, sent to the socket
struct iovec iov; // The iovec structures stores the RX buffer
struct sockaddr_in sin;
// Poll file descriptor, used to poll for timestamp messages
struct pollfd poll_fd = {sock_fd, POLLPRI, 0};
int recvmsgerr, pollerr;
int recvmsgerr;
packet_timestamps_t packet_ts;
struct timespec ts;
if (use_timestamps) {
clock_gettime(CLOCK_REALTIME, &ts);
packet_ts.enter_user_space = ts_to_uint(ts);
......@@ -142,14 +142,17 @@ packet_timestamps_t recv_udp_packet(int use_timestamps, int64_t histograms[NB_HI
if (recvmsgerr < 0)
error(EXIT_FAILURE, errno, "recvmsg failed, ret value: %d\n", recvmsgerr);
if (use_timestamps) {
pollerr = poll(&poll_fd, 1, 0);
if (pollerr > 0)
process_timestamps(&packet_ts, histograms);
else
fprintf(stderr, "select failed\n");
}
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) {
struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg);
packet_ts.leave_kernel = ts_to_uint(*stamp);
fill_histograms(&packet_ts, histograms);
}
}
}
return packet_ts;
}
......@@ -174,51 +177,6 @@ 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]) {
char data[256];
struct msghdr msg;
struct iovec entry;
struct sockaddr_in from_addr;
struct {
struct cmsghdr cm;
char control[512];
} control;
struct cmsghdr *cmsg;
memset(&msg, 0, sizeof(msg));
msg.msg_iov = &entry;
msg.msg_iovlen = 1;
entry.iov_base = data;
entry.iov_len = sizeof(data);
msg.msg_name = (caddr_t)&from_addr;
msg.msg_namelen = sizeof(from_addr);
msg.msg_control = &control;
msg.msg_controllen = sizeof(control);
if (recvmsg(sock_fd, &msg, MSG_ERRQUEUE | MSG_DONTWAIT) == -1) {
fprintf(stderr, "recvmsg failed\n");
return;
}
for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SO_TIMESTAMPING) {
struct timespec *stamp = (struct timespec *)CMSG_DATA(cmsg);
packet_ts->leave_kernel = ts_to_uint(*stamp);
fill_histograms(packet_ts, histograms);
} else {
#ifdef DEBUG
fprintf(stderr, "process_timestamps: level %d type %d", cmsg->cmsg_level,
cmsg->cmsg_type);
#endif
}
}
}
#ifdef DEBUG
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment