Commit 781fea12 authored by Joanne Hugé's avatar Joanne Hugé

Add option to pass the tx buffer length

parent 2c75283c
......@@ -4,6 +4,7 @@
* Bash options:
*
* -a Run the real time thread on CPU1
* -d TX_BUFFER_LEN Set the length of tx buffer
* -e Set a txtime (to be used in an ETF qdisc)
* -f Set the network interface to be used
* -i USEC Wake up the real time thread every USEC microseconds (Default: 10ms)
......@@ -54,6 +55,7 @@ typedef struct thread_param {
typedef struct main_param {
int refresh_rate;
int packet_priority;
size_t tx_buffer_len;
} main_param_t;
static inline void add_ns(struct timespec *t, uint64_t ns);
......@@ -126,7 +128,7 @@ int main(int argc, char *argv[]) {
// Process bash options
process_options(argc, argv, &param, &main_param);
init_udp_etf(param.enable_etf, param.enable_timestamps, main_param.packet_priority, param.network_if);
init_udp_etf(param.enable_etf, param.enable_timestamps, main_param.packet_priority, param.network_if, main_param.tx_buffer_len);
usleep(10000);
......@@ -150,7 +152,7 @@ int main(int argc, char *argv[]) {
static void process_options(int argc, char *argv[], thread_param_t *param,
main_param_t *main_param) {
for (;;) {
int c = getopt(argc, argv, "aef:i:l:p:q:r:t");
int c = getopt(argc, argv, "ad:ef:i:l:p:q:r:t");
if (c == -1) break;
......@@ -158,6 +160,13 @@ static void process_options(int argc, char *argv[], thread_param_t *param,
case 'a':
param->enable_affinity = 1;
break;
case 'd':
main_param->tx_buffer_len = atoi(optarg);
if( main_param->tx_buffer_len < 1 ) {
fprintf(stderr, "TX_BUFFER_LEN should be greater than 1\n");
exit(EXIT_FAILURE);
}
break;
case 'e':
param->enable_etf = 1;
break;
......
......@@ -44,11 +44,12 @@
static void print_timestamps(struct msghdr *msg, uint64_t txtime);
static void process_timestamps(uint64_t txtime);
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[1024] = "Hi";
static size_t tx_buffer_len = sizeof(tx_buffer);
static unsigned char * tx_buffer;
static size_t tx_buffer_len;
static int fd;
static int64_t tai_offset;
......@@ -69,15 +70,35 @@ static int set_if(char *network_if) {
return ifreq.ifr_ifindex;
}
static void init_tx_buffer(size_t _tx_buffer_len) {
if( _tx_buffer_len < 1) {
fprintf(stderr, "tx buffer length should be greater than 1\n");
exit(EXIT_FAILURE);
}
tx_buffer_len = _tx_buffer_len;
tx_buffer = malloc(tx_buffer_len);
for(int i = 0; i < ( ((int)tx_buffer_len) - 1); i++) {
tx_buffer[i] = (unsigned char) i;
}
tx_buffer[tx_buffer_len - 1] = '\0';
}
/*
* Init UDP socket
*/
void init_udp_etf(int use_etf, int use_timestamps, int packet_priority,
char *network_if) {
char *network_if, size_t _tx_buffer_len) {
int index;
struct timespec ts_mon;
struct timespec ts_tai;
init_tx_buffer(_tx_buffer_len);
clock_gettime(CLOCK_MONOTONIC, &ts_mon);
clock_gettime(CLOCK_TAI, &ts_tai);
tai_offset = (ts_mon.tv_sec - ts_tai.tv_sec) * NSEC_PER_SEC + (ts_mon.tv_nsec - ts_tai.tv_nsec);
......@@ -240,12 +261,13 @@ static void print_timestamps(struct msghdr *msg, uint64_t txtime) {
}
#ifdef DEBUG
/*
* Code from scheduled_tx_tools
*/
static int process_socket_error_queue() {
uint8_t msg_control[CMSG_SPACE(sizeof(struct sock_extended_err))];
unsigned char err_buffer[sizeof(tx_buffer)];
unsigned char err_buffer[256];
struct sock_extended_err *serr;
struct cmsghdr *cmsg;
__u64 tstamp = 0;
......
......@@ -2,8 +2,9 @@
#define SEND_PACKET_H
#include <stdint.h>
#include <stdio.h>
void init_udp_etf(int use_etf, int use_timestamps, int so_priority, char * network_if);
void init_udp_etf(int use_etf, int use_timestamps, int so_priority, char * network_if, size_t tx_buffer_len);
void send_udp_packet(int use_etf, int use_timestamps, uint64_t txtime, const char *server_ip);
#endif
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