Refactor measuring latency program
This commit is contained in:
parent
99d668f4d6
commit
167f55ba13
5 changed files with 93 additions and 28 deletions
|
@ -11,7 +11,10 @@ RUN mkdir out && \
|
|||
|
||||
FROM fedora:29
|
||||
RUN dnf install -y glib2 tor
|
||||
WORKDIR /home/donar
|
||||
RUN chown -R 1000 /home/donar
|
||||
USER 1000
|
||||
ENV HOME /home/donar
|
||||
COPY --from=builder /home/donar-build/out/donar /usr/local/bin
|
||||
COPY --from=builder /home/donar-build/out/measlat /usr/local/bin
|
||||
COPY ./torrc_simple /etc/torrc
|
||||
USER 1000
|
||||
|
|
|
@ -13,3 +13,9 @@ Leave the rest empty.
|
|||
Uncheck all the checkboxes.
|
||||
```
|
||||
|
||||
## Docker build
|
||||
|
||||
```
|
||||
sudo docker build -t registry.gitlab.inria.fr/qdufour/donar .
|
||||
sudo docker push registry.gitlab.inria.fr/qdufour/donar
|
||||
```
|
||||
|
|
4
scripts/xp1-client
Executable file
4
scripts/xp1-client
Executable file
|
@ -0,0 +1,4 @@
|
|||
#!/bin/bash
|
||||
tor -f /etc/torrc &
|
||||
donar -a naive -c /shared/onion_services.pub -r 9000 &
|
||||
measlat 127.13.3.7 9000 100 100 50
|
2
scripts/xp1-server
Executable file
2
scripts/xp1-server
Executable file
|
@ -0,0 +1,2 @@
|
|||
#!/bin/bash
|
||||
|
104
src/meas_lat.c
104
src/meas_lat.c
|
@ -20,7 +20,7 @@ struct packet_header {
|
|||
struct timespec emit_time;
|
||||
};
|
||||
|
||||
struct measure_conf* create_measure_conf(int udp_sock, char* max_mes, char* plsize) {
|
||||
struct measure_conf* create_measure_conf(int udp_sock, int max_mes, int plsize) {
|
||||
struct measure_conf* mc = malloc(sizeof(struct measure_conf));
|
||||
if (mc == NULL) {
|
||||
perror("Malloc failed");
|
||||
|
@ -35,8 +35,8 @@ struct measure_conf* create_measure_conf(int udp_sock, char* max_mes, char* plsi
|
|||
}
|
||||
}
|
||||
mc->counter = 0;
|
||||
mc->max_measure = atoi(max_mes);
|
||||
mc->payload_size = atoi(plsize);
|
||||
mc->max_measure = max_mes;
|
||||
mc->payload_size = plsize;
|
||||
mc->payload = malloc(mc->payload_size);
|
||||
if (mc->payload == NULL) {
|
||||
perror("malloc failed");
|
||||
|
@ -90,7 +90,7 @@ int on_timer(struct evt_core_ctx* ctx, struct evt_core_fdinfo* fdinfo) {
|
|||
if (ticks != 1) {
|
||||
fprintf(stderr, "Has ticked %lu times, expected 1 time. This is a bug\n", ticks);
|
||||
}
|
||||
mc->counter += ticks;
|
||||
mc->counter++;
|
||||
|
||||
memset(mc->payload, 0, mc->payload_size);
|
||||
struct packet_header* head = (struct packet_header*)mc->payload;
|
||||
|
@ -114,14 +114,7 @@ void free_timer_conf(void* v) {
|
|||
free(mc);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
printf("~ measlat ~\n");
|
||||
if (argc < 6){
|
||||
fprintf(stderr, "%s host port interval count payload-size\n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
struct evt_core_ctx evts = {0};
|
||||
void register_categories(struct evt_core_ctx* evts) {
|
||||
struct evt_core_cat udp_read = {
|
||||
.app_ctx = NULL,
|
||||
.free_app_ctx = NULL,
|
||||
|
@ -141,12 +134,15 @@ int main(int argc, char** argv) {
|
|||
.socklist = NULL
|
||||
};
|
||||
|
||||
evt_core_init(&evts);
|
||||
evt_core_add_cat (&evts, &udp_read);
|
||||
evt_core_add_cat(&evts, &timer);
|
||||
evt_core_init(evts);
|
||||
evt_core_add_cat (evts, &udp_read);
|
||||
evt_core_add_cat(evts, &timer);
|
||||
printf("--- Categories registered\n");
|
||||
|
||||
int udp_sock = create_udp_client (argv[1], argv[2]);
|
||||
}
|
||||
|
||||
int register_udp_socket(struct evt_core_ctx* evts, char* host, char* port, int count, int size) {
|
||||
int udp_sock = create_udp_client (host, port);
|
||||
char url[1024];
|
||||
struct evt_core_cat cat = {0};
|
||||
struct evt_core_fdinfo fdinfo = {0};
|
||||
|
@ -155,20 +151,27 @@ int main(int argc, char** argv) {
|
|||
|
||||
fdinfo.fd = udp_sock;
|
||||
fdinfo.cat->name = "udp-read";
|
||||
fdinfo.other = create_measure_conf (-1, argv[4], argv[5]);
|
||||
sprintf(fdinfo.url, "udp:read:%s:%s", argv[1], argv[2]);
|
||||
evt_core_add_fd (&evts, &fdinfo);
|
||||
fdinfo.other = create_measure_conf (-1, count, size);
|
||||
sprintf(fdinfo.url, "udp:read:%s:%s", host, port);
|
||||
evt_core_add_fd (evts, &fdinfo);
|
||||
printf("--- UDP socket registered\n");
|
||||
return fdinfo.fd;
|
||||
}
|
||||
|
||||
void register_timer(struct evt_core_ctx* evts, int udp, int interval, int count, int size) {
|
||||
struct timespec now;
|
||||
struct itimerspec timer_config;
|
||||
char url[1024];
|
||||
struct evt_core_cat cat = {0};
|
||||
struct evt_core_fdinfo fdinfo = {0};
|
||||
fdinfo.cat = &cat;
|
||||
fdinfo.url = url;
|
||||
|
||||
if (clock_gettime(CLOCK_REALTIME, &now) == -1) {
|
||||
perror("clock_gettime");
|
||||
return 1;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
uint64_t micro_sec = atoi(argv[3]);
|
||||
uint64_t micro_sec = interval;
|
||||
timer_config.it_value.tv_sec = now.tv_sec + 1;
|
||||
timer_config.it_value.tv_nsec = now.tv_nsec;
|
||||
timer_config.it_interval.tv_sec = micro_sec / 1000;
|
||||
|
@ -177,20 +180,67 @@ int main(int argc, char** argv) {
|
|||
fdinfo.fd = timerfd_create(CLOCK_REALTIME, 0);
|
||||
if (fdinfo.fd == -1) {
|
||||
perror("Unable to timerfd_create");
|
||||
return 1;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (timerfd_settime (fdinfo.fd, TFD_TIMER_ABSTIME, &timer_config, NULL) == -1) {
|
||||
perror("Unable to timerfd_time");
|
||||
return 1;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
fdinfo.cat->name = "timer";
|
||||
fdinfo.other = create_measure_conf(udp_sock, argv[4], argv[5]);
|
||||
fdinfo.other = create_measure_conf(udp, count, size);
|
||||
fdinfo.free_other = free_timer_conf;
|
||||
sprintf(fdinfo.url, "timer:%s:%s", argv[3], argv[4]);
|
||||
evt_core_add_fd (&evts, &fdinfo);
|
||||
sprintf(fdinfo.url, "timer:%d:%d", interval, count);
|
||||
evt_core_add_fd (evts, &fdinfo);
|
||||
printf("--- Timer registered\n");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
printf("~ measlat ~\n");
|
||||
|
||||
int opt, udp_fd, count = 0, size = 0, interval = 0;
|
||||
char *host = NULL, *port = NULL;
|
||||
struct evt_core_ctx evts = {0};
|
||||
|
||||
// 1. Parse parameters
|
||||
while ((opt = getopt(argc, argv, "h:p:c:s:i:")) != -1) {
|
||||
switch(opt) {
|
||||
case 'h':
|
||||
host = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
port = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
count = atoi(optarg);
|
||||
break;
|
||||
case 's':
|
||||
size = atoi(optarg);
|
||||
break;
|
||||
case 'i':
|
||||
interval = atoi(optarg);
|
||||
break;
|
||||
default:
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Check and fix parameters
|
||||
size_t header_size = sizeof(struct packet_header);
|
||||
if (interval <= 0) interval = 1000;
|
||||
if (count <= 0) count = 1;
|
||||
if (size < header_size) size = header_size;
|
||||
if (host == NULL || port == NULL) goto usage;
|
||||
|
||||
// 3. Bind events
|
||||
register_categories(&evts);
|
||||
udp_fd = register_udp_socket(&evts, host, port, count, size);
|
||||
register_timer(&evts, udp_fd, interval, count, size);
|
||||
|
||||
// 4. Run main loop
|
||||
evt_core_loop(&evts);
|
||||
|
||||
return 0;
|
||||
usage:
|
||||
fprintf(stderr, "Usage: %s -h <host> -p <port> [-c <count>] [-i <ms>] [-s <bytes>]\n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue