Commit b94ded12 authored by Joanne Hugé's avatar Joanne Hugé

Allow server to receive and print the packet's data

parent cbd2afa6
......@@ -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);
......
......@@ -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;
......
......@@ -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
......@@ -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 {
......
......@@ -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
......@@ -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);
}
}
}
......
......@@ -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);
......
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