diff options
Diffstat (limited to 'src/tools/ocbr')
| -rw-r--r-- | src/tools/ocbr/CMakeLists.txt | 5 | ||||
| -rw-r--r-- | src/tools/ocbr/ocbr.c | 34 | ||||
| -rw-r--r-- | src/tools/ocbr/ocbr_client.c | 11 | ||||
| -rw-r--r-- | src/tools/ocbr/ocbr_server.c | 39 |
4 files changed, 54 insertions, 35 deletions
diff --git a/src/tools/ocbr/CMakeLists.txt b/src/tools/ocbr/CMakeLists.txt index 5dac3e63..f7ba66cd 100644 --- a/src/tools/ocbr/CMakeLists.txt +++ b/src/tools/ocbr/CMakeLists.txt @@ -4,6 +4,11 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_SOURCE_DIR}/include) include_directories(${CMAKE_BINARY_DIR}/include) +get_filename_component(CURRENT_SOURCE_PARENT_DIR + ${CMAKE_CURRENT_SOURCE_DIR} DIRECTORY) + +include_directories(${CURRENT_SOURCE_PARENT_DIR}) + set(SOURCE_FILES # Add source files here ocbr.c diff --git a/src/tools/ocbr/ocbr.c b/src/tools/ocbr/ocbr.c index e2bd84af..775bcaac 100644 --- a/src/tools/ocbr/ocbr.c +++ b/src/tools/ocbr/ocbr.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2018 + * Ouroboros - Copyright (C) 2016 - 2024 * * CBR traffic generator * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -39,6 +39,8 @@ #define _POSIX_C_SOURCE 199506L #define __XSI_VISIBLE 500 +#include "time_utils.h" + #include <stdio.h> #include <string.h> #include <sys/time.h> @@ -60,7 +62,7 @@ struct s { static void usage(void) { printf("Usage: cbr [OPTION]...\n" - "Sends SDUs from client to server at a constant bit rate.\n\n" + "Sends packets from client to server at a constant bit rate.\n\n" " -l, --listen Run in server mode\n" "\n" "Server options:\n" @@ -70,10 +72,11 @@ static void usage(void) "Client options:\n" " -n, --server_apn Specify the name of the server.\n" " -d, --duration Duration for sending (s)\n" - " -f, --flood Send SDUs as fast as possible\n" - " -s, --size SDU size (B, max %ld B)\n" + " -f, --flood Send packets as fast as possible\n" + " -s, --size packet size (B, max %ld B)\n" " -r, --rate Rate (b/s)\n" - " --sleep Sleep in between sending SDUs\n" + " --sleep Sleep in between sending packets\n" + " --spin Spin CPU between sending packets\n" "\n\n" " --help Display this help text and exit\n", BUF_SIZE); @@ -82,10 +85,10 @@ static void usage(void) int main(int argc, char ** argv) { int duration = 60; /* One minute test */ - int size = 1000; /* 1000 byte SDUs */ + int size = 1000; /* 1000 byte packets */ long rate = 1000000; /* 1 Mb/s */ bool flood = false; - bool sleep = false; + bool sleep = true; int ret = 0; char * rem = NULL; char * s_apn = NULL; @@ -136,6 +139,8 @@ int main(int argc, char ** argv) flood = true; } else if (strcmp(*argv, "--sleep") == 0) { sleep = true; + } else if (strcmp(*argv, "--spin") == 0) { + sleep = false; } else { usage(); return 0; @@ -150,17 +155,22 @@ int main(int argc, char ** argv) if (s_apn == NULL) { printf("No server specified.\n"); usage(); - return 0; + return 1; } if (size > BUF_SIZE) { printf("Maximum size: %ld.\n", BUF_SIZE); - return 0; + return 1; } if (size < 0) { printf("Size overflow.\n"); - return 0; + return 1; + } + + if (rate <= 0) { + printf("Invalid rate.\n"); + return 1; } ret = client_main(s_apn, duration, size, rate, flood, sleep); diff --git a/src/tools/ocbr/ocbr_client.c b/src/tools/ocbr/ocbr_client.c index 026ab001..ba7b41f4 100644 --- a/src/tools/ocbr/ocbr_client.c +++ b/src/tools/ocbr/ocbr_client.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2018 + * Ouroboros - Copyright (C) 2016 - 2024 * * A simple CBR generator * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -37,7 +37,6 @@ */ #include <ouroboros/dev.h> -#include <ouroboros/time_utils.h> #include <signal.h> @@ -136,7 +135,7 @@ int client_main(char * server, } else { /* flood */ while (!stop) { clock_gettime(CLOCK_REALTIME, &end); - if (flow_write(fd, buf, (size_t) size) < 0) { + if (flow_write(fd, buf, size) < 0) { stop = true; continue; } @@ -155,7 +154,7 @@ int client_main(char * server, ms = ts_diff_ms(&start, &end); printf("sent statistics: " - "%9ld SDUs, %12ld bytes in %9d ms, %4.4f Mb/s\n", + "%9ld packets, %12ld bytes in %9d ms, %4.4f Mb/s\n", seqnr, seqnr * size, ms, (seqnr / (ms * 1000.0)) * size * 8.0); flow_dealloc(fd); diff --git a/src/tools/ocbr/ocbr_server.c b/src/tools/ocbr/ocbr_server.c index 4f080eff..a4bbadd4 100644 --- a/src/tools/ocbr/ocbr_server.c +++ b/src/tools/ocbr/ocbr_server.c @@ -1,10 +1,10 @@ /* - * Ouroboros - Copyright (C) 2016 - 2018 + * Ouroboros - Copyright (C) 2016 - 2024 * * A simple CBR generator * - * Dimitri Staessens <dimitri.staessens@ugent.be> - * Sander Vrijders <sander.vrijders@ugent.be> + * Dimitri Staessens <dimitri@ouroboros.rocks> + * Sander Vrijders <sander@ouroboros.rocks> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -37,7 +37,6 @@ */ #include <ouroboros/dev.h> -#include <ouroboros/time_utils.h> #include <ouroboros/fccntl.h> #include <stdbool.h> @@ -84,14 +83,15 @@ static void handle_flow(int fd) struct timespec now; struct timespec alive; struct timespec intv = {server_settings.interval, 0}; + struct timespec tic = {0, 100 * MILLION}; struct timespec iv_start; struct timespec iv_end; bool stop = false; - long sdus = 0; - long sdus_intv = 0; + long packets = 0; + long packets_intv = 0; long bytes_read = 0; long bytes_read_intv = 0; @@ -100,7 +100,8 @@ static void handle_flow(int fd) alive = iv_start; ts_add(&iv_start, &intv, &iv_end); - fccntl(fd, FLOWSFLAGS, FLOWFRNOBLOCK | FLOWFRDWR | FLOWFRNOPART); + fccntl(fd, FLOWSFLAGS, FLOWFRDWR | FLOWFRNOPART); + fccntl(fd, FLOWSRCVTIMEO, &tic); while (!stop) { clock_gettime(CLOCK_REALTIME, &now); @@ -109,7 +110,7 @@ static void handle_flow(int fd) if (count > 0) { clock_gettime(CLOCK_REALTIME, &alive); - sdus++; + packets++; bytes_read += count; } @@ -121,17 +122,18 @@ static void handle_flow(int fd) if (stop || ts_diff_ms(&now, &iv_end) < 0) { long us = ts_diff_us(&iv_start, &now); - printf("Flow %4d: %9ld SDUs (%12ld bytes) in %9ld ms" - " => %9.4f p/s, %9.4f Mb/s\n", + printf("Flow %4d: %9ld packets (%12ld bytes) in %9ld ms" + " => %9.4f pps, %9.4f Mbps\n", fd, - sdus - sdus_intv, + packets - packets_intv, bytes_read - bytes_read_intv, us / 1000, - ((sdus - sdus_intv) / (double) us) * MILLION, + ((packets - packets_intv) / (double) us) + * MILLION, 8 * ((bytes_read - bytes_read_intv) / (double)(us))); iv_start = iv_end; - sdus_intv = sdus; + packets_intv = packets; bytes_read_intv = bytes_read; ts_add(&iv_start, &intv, &iv_end); } @@ -140,6 +142,11 @@ static void handle_flow(int fd) flow_dealloc(fd); } +static void __cleanup_mutex_unlock(void * mutex) +{ + pthread_mutex_unlock((pthread_mutex_t *) mutex); +} + static void * worker(void * o) { int cli_fd; @@ -148,8 +155,7 @@ static void * worker(void * o) while (true) { pthread_mutex_lock(&fds_lock); - pthread_cleanup_push((void(*)(void *)) pthread_mutex_unlock, - (void *) &fds_lock); + pthread_cleanup_push(__cleanup_mutex_unlock, &fds_lock); while (fds[fds_index] == -1) pthread_cond_wait(&fds_signal, &fds_lock); @@ -182,8 +188,7 @@ static void * listener(void * o) while (true) { pthread_mutex_lock(&fds_lock); - pthread_cleanup_push((void(*)(void *)) pthread_mutex_unlock, - (void *) &fds_lock); + pthread_cleanup_push(__cleanup_mutex_unlock, &fds_lock); while (fds_count == THREADS_SIZE) { printf("Can't accept any more flows, waiting.\n"); |
