Commit ececaef2 authored by Andreas Schmidt's avatar Andreas Schmidt
Browse files

Sender and receiver now use named parameters.

parent b637fe3c
......@@ -13,8 +13,8 @@ check() {
to="timeout -s INT 30 "
valgrind="valgrind --tool=memcheck --track-origins=yes --leak-check=full --show-leak-kinds=all --error-exitcode=1"
$to $valgrind ./bin/receiver 5000 127 receiver.csv &
$to $valgrind ./bin/sender 127.0.0.1 5000 127 sender.csv
$to $valgrind ./bin/receiver -p 5000 -r 127 -o receiver.csv &
$to $valgrind ./bin/sender -t 127.0.0.1 -p 5000 -r 127 -o sender.csv
check "$?" "sender failed"
wait
......
......@@ -29,6 +29,7 @@ PrrtSocket *PrrtSocket_create(const bool is_sender, prrtTimedelta_t target_delay
s->isSender = is_sender;
s->isHardwareTimestamping = false;
s->interfaceName = NULL;
PrrtClock_init(&s->clock);
......
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <argp.h>
#include "util/dbg.h"
#include "proto/socket.h"
PrrtSocket *sock = NULL;
PrrtSocket *s = NULL;
static volatile int keepRunning = true;
static char doc[] = "PRRT Sender";
static struct argp_option options[] = {
{"port", 'p', "PORT", 0, "Target Port" },
{"rounds", 'r', "ROUNDS", 0, "Rounds" },
{"output", 'o', "FILE", 0, "Output to FILE instead of standard output" },
{"hardwaretimestamping", 777, "INTERFACE", 0, "Enable hardware timestamping and bind to interface"},
{ 0 }
};
static struct arguments
{
uint16_t port;
uint16_t rounds;
char* outfile;
char* hardwarestamping_interface;
};
static char args_doc[] = "";
static error_t parse_opt (int key, char *arg, struct argp_state *state)
{
struct arguments *arguments = state->input;
char* pEnd;
switch (key)
{
case 'p':
arguments->port = (uint16_t) strtol(arg, &pEnd, 10);
break;
case 'r':
arguments->rounds = (uint16_t) strtol(arg, &pEnd, 10);
break;
case 'o':
arguments->outfile = arg;
break;
case 777:
arguments->hardwarestamping_interface = arg;
break;
case ARGP_KEY_END:
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
void intHandler(int dummy) {
keepRunning = false;
PrrtSocket_interrupt(sock);
PrrtSocket_interrupt(s);
}
int main(int argc, char *const argv[]) {
int main(int argc, char **argv) {
signal(SIGINT, intHandler);
struct argp argp = { options, parse_opt, args_doc, doc };
struct arguments arguments = {
.port = 5000,
.rounds = 127,
.outfile = "-",
.hardwarestamping_interface = "-"
};
argp_parse (&argp, argc, argv, 0, 0, &arguments);
bool file_output = false;
FILE *out_desc = stdout;
if (!(argc == 3 || argc == 4)) {
printf("Receiver: Wrong arguments. Usage: port rounds [outfile]\n");
return -1;
}
if (argc == 4) {
if (strcmp(arguments.outfile, "-") != 0) {
file_output = true;
out_desc = fopen(argv[3], "w");
out_desc = fopen(arguments.outfile, "w");
}
uint16_t port = (uint16_t) atoi(argv[1]);
uint32_t rounds = (uint32_t) atoi(argv[2]);
uint32_t rounds = arguments.rounds;
#ifdef XLAP
if (rounds >= TS_ROWS) {
printf("Receiver: Too many rounds for use with XLAP (max: %d).\n", TS_ROWS-1);
......@@ -37,23 +91,26 @@ int main(int argc, char *const argv[]) {
}
#endif
sock = PrrtSocket_create(false, HALF_TIMESTAMP-1);
//PrrtSocket_enable_hardware_timestamping(sock, "enp1s0f0");
check(sock != NULL, "Could not create socket.");
check(PrrtSocket_bind(sock, "0.0.0.0", port), "bind failed");
s = PrrtSocket_create(false, HALF_TIMESTAMP-1);
check(s != NULL, "Could not create socket.");
if(strcmp(arguments.hardwarestamping_interface, "-") != 0) {
PrrtSocket_enable_hardware_timestamping(s, arguments.hardwarestamping_interface);
}
check(PrrtSocket_bind(s, "0.0.0.0", arguments.port), "bind failed");
XlapTimestampTable *tstable_data = malloc(sizeof(XlapTimestampTable));
XlapTimestampTable *tstable_redundancy = malloc(sizeof(XlapTimestampTable));
check(tstable_data != NULL, "malloc failed");
check(tstable_redundancy != NULL, "malloc failed");
XlapTimestampTableInstall(sock, ts_data_packet, tstable_data);
XlapTimestampTableInstall(sock, ts_redundancy_packet, tstable_redundancy);
XlapTimestampTableInstall(s, ts_data_packet, tstable_data);
XlapTimestampTableInstall(s, ts_redundancy_packet, tstable_redundancy);
uint32_t i = 0;
while (i < rounds && keepRunning) {
char buffer[MAX_PAYLOAD_LENGTH + 1];
debug(DEBUG_RECEIVER, "About to receive.");
int n = PrrtSocket_recv(sock, buffer);
int n = PrrtSocket_recv(s, buffer);
if (n < 0) {
continue;
}
......@@ -73,8 +130,8 @@ int main(int argc, char *const argv[]) {
fclose(out_desc);
}
PrrtSocket_close(sock);
free(sock);
PrrtSocket_close(s);
free(s);
free(tstable_data);
free(tstable_redundancy);
......
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <argp.h>
#include "util/dbg.h"
#include "proto/socket.h"
int main(int argc, char *const argv[]) {
static char doc[] = "PRRT Sender";
static struct argp_option options[] = {
{"target", 't', "HOST", 0, "Target Host" },
{"port", 'p', "PORT", 0, "Target Port" },
{"rounds", 'r', "ROUNDS", 0, "Rounds" },
{"output", 'o', "FILE", 0, "Output to FILE instead of standard output" },
{"hardwaretimestamping", 777, "INTERFACE", 0, "Enable hardware timestamping and bind to interface"},
{ 0 }
};
static struct arguments
{
char* target;
uint16_t port;
uint16_t rounds;
char* outfile;
char* hardwarestamping_interface;
};
static char args_doc[] = "";
static error_t parse_opt (int key, char *arg, struct argp_state *state)
{
struct arguments *arguments = state->input;
char* pEnd;
switch (key)
{
case 't':
arguments->target = arg;
break;
case 'p':
arguments->port = (uint16_t) strtol(arg, &pEnd, 10);
break;
case 'r':
arguments->rounds = (uint16_t) strtol(arg, &pEnd, 10);
break;
case 'o':
arguments->outfile = arg;
break;
case 777:
arguments->hardwarestamping_interface = arg;
break;
case ARGP_KEY_END:
break;
default:
return ARGP_ERR_UNKNOWN;
}
return 0;
}
int main(int argc, char **argv) {
struct argp argp = { options, parse_opt, args_doc, doc };
struct arguments arguments = {
.target = "127.0.0.1",
.port = 5000,
.rounds = 127,
.outfile = "-",
.hardwarestamping_interface = "-"
};
argp_parse (&argp, argc, argv, 0, 0, &arguments);
bool file_output = false;
FILE *out_desc = stdout;
if (!(argc == 4 || argc == 5)) {
printf("Sender: Wrong arguments. Usage: host port round [outfile].\n");
return -1;
}
if (argc == 5) {
if (strcmp(arguments.outfile, "-") != 0) {
file_output = true;
out_desc = fopen(argv[4], "w");
out_desc = fopen(arguments.outfile, "w");
}
char *host = argv[1];
uint16_t port = (uint16_t) atoi(argv[2]);
uint32_t rounds = (uint32_t) atoi(argv[3]);
uint32_t rounds = arguments.rounds;
#ifdef XLAP
if (rounds >= TS_ROWS) {
printf("Sender: Too many rounds for use with XLAP (max: %d).\n", TS_ROWS-1);
......@@ -32,16 +91,15 @@ int main(int argc, char *const argv[]) {
uint16_t local_port = 6000;
PrrtSocket *socket = PrrtSocket_create(true, 60 * 1000 * 1000);
//PrrtSocket_enable_hardware_timestamping(socket, "enp1s0f0");
check(socket != NULL, "Socket create failed.");
//PrrtSocket_set_coding_parameters(socket, 1, 1); // comment this line to re-enable coding.
if(strcmp(arguments.hardwarestamping_interface, "-") != 0) {
PrrtSocket_enable_hardware_timestamping(socket, arguments.hardwarestamping_interface);
}
check(PrrtSocket_bind(socket, "0.0.0.0", local_port), "bind failed");
check(socket != NULL, "Socket creation failed.");
char *remote_host = host;
uint16_t remote_port = port;
PrrtSocket_connect(socket, remote_host, remote_port);
//PrrtSocket_set_coding_parameters(socket, 1, 1); // comment this line to re-enable coding.
PrrtSocket_connect(socket, arguments.target, arguments.port);
XlapTimestampTable *tstable_data = malloc(sizeof(XlapTimestampTable));
XlapTimestampTable *tstable_redundancy = malloc(sizeof(XlapTimestampTable));
......
Supports Markdown
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