diff options
author | Sander Vrijders <[email protected]> | 2016-06-14 14:55:39 +0200 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2016-06-14 14:55:39 +0200 |
commit | 6271d09bdd17114c3095b7e819a7bcded14f26a5 (patch) | |
tree | a1c2a7bd200eb0343557524ddc80b0af6df4ec9e /src/tools/cbr | |
parent | ddfc7091d2698d36c1cfec49eaaad96b278bb37b (diff) | |
parent | 95124310f647913a678060fc10155a0ad9311dba (diff) | |
download | ouroboros-6271d09bdd17114c3095b7e819a7bcded14f26a5.tar.gz ouroboros-6271d09bdd17114c3095b7e819a7bcded14f26a5.zip |
Merged in dstaesse/ouroboros/be-api (pull request #122)
lib, irmd, tools, ipcpd: updates to dev API.
Diffstat (limited to 'src/tools/cbr')
-rw-r--r-- | src/tools/cbr/cbr.c | 40 | ||||
-rw-r--r-- | src/tools/cbr/cbr_client.c | 16 | ||||
-rw-r--r-- | src/tools/cbr/cbr_server.c | 30 |
3 files changed, 38 insertions, 48 deletions
diff --git a/src/tools/cbr/cbr.c b/src/tools/cbr/cbr.c index e36b1856..ab178ca3 100644 --- a/src/tools/cbr/cbr.c +++ b/src/tools/cbr/cbr.c @@ -30,9 +30,6 @@ #include <time.h> #include <stdbool.h> -#define SERVER_AP_NAME "cbr-server" -#define CLIENT_AP_NAME "cbr-client" - #define BUF_SIZE 1500 #include "cbr_client.c" @@ -49,6 +46,7 @@ static void usage(void) printf("Usage: cbr [OPTION]...\n" "Sends SDU's from client to server at a constant bit rate.\n\n" " -l, --listen Run in server mode\n" + " -n, --server_apn Specify the name of the server.\n" "\n" "Server options:\n" " -i, --interval Server report interval (s)\n" @@ -66,14 +64,20 @@ static void usage(void) int main(int argc, char ** argv) { - int duration = 60; /* One minute test */ - int size = 1000; /* 1000 byte SDU's */ - long rate = 1000000; /* 1 Mb/s */ - bool flood = false; - bool sleep = false; - char * rem; + int duration = 60; /* One minute test */ + int size = 1000; /* 1000 byte SDU's */ + long rate = 1000000; /* 1 Mb/s */ + bool flood = false; + bool sleep = false; + int ret = 0; + char * rem = NULL; + char * s_apn = NULL; bool server = false; + + /* FIXME: should be argv[0] */ + ap_init(argv[0]); + server_settings.interval = 1; /* One second reporting interval */ server_settings.timeout = 1; @@ -88,6 +92,10 @@ int main(int argc, char ** argv) strcmp(*argv, "--timeout") == 0) { server_settings.timeout = strtol(*(++argv), &rem, 10); --argc; + } else if (strcmp(*argv, "-n") == 0 || + strcmp(*argv, "--server_apn") == 0) { + s_apn = *(++argv); + --argc; } else if (strcmp(*argv, "-d") == 0 || strcmp(*argv, "--duration") == 0) { duration = strtol(*(++argv), &rem, 10); @@ -123,8 +131,18 @@ int main(int argc, char ** argv) } if (server) { - return server_main(); + ret = server_main(); + } else { + if (s_apn == NULL) { + printf("No server specified.\n"); + usage(); + return 0; + } + + ret = client_main(s_apn, duration, size, rate, flood, sleep); } - return client_main(duration, size, rate, flood, sleep); + ap_fini(); + + return ret; } diff --git a/src/tools/cbr/cbr_client.c b/src/tools/cbr/cbr_client.c index b0c04f39..1cc325b8 100644 --- a/src/tools/cbr/cbr_client.c +++ b/src/tools/cbr/cbr_client.c @@ -35,7 +35,12 @@ static void busy_wait_until(const struct timespec * deadline) clock_gettime(CLOCK_REALTIME, &now); } -int client_main(int duration, int size, long rate, bool flood, bool sleep) +int client_main(char * server, + int duration, + int size, + long rate, + bool flood, + bool sleep) { int fd = 0; int result = 0; @@ -49,15 +54,10 @@ int client_main(int duration, int size, long rate, bool flood, bool sleep) struct timespec intv = {(gap / BILLION), gap % BILLION}; int ms; - if (ap_init(CLIENT_AP_NAME)) { - printf("Failed to init AP.\n"); - return -1; - } - printf("Client started, duration %d, rate %lu b/s, size %d B.\n", duration, rate, size); - fd = flow_alloc(SERVER_AP_NAME, NULL, NULL); + fd = flow_alloc(server, NULL, NULL); if (fd < 0) { printf("Failed to allocate flow.\n"); ap_fini(); @@ -122,7 +122,5 @@ int client_main(int duration, int size, long rate, bool flood, bool sleep) flow_dealloc(fd); - ap_fini(); - return 0; } diff --git a/src/tools/cbr/cbr_server.c b/src/tools/cbr/cbr_server.c index eef1acc9..3a1d8d5c 100644 --- a/src/tools/cbr/cbr_server.c +++ b/src/tools/cbr/cbr_server.c @@ -30,7 +30,6 @@ #include <ouroboros/dev.h> #include <ouroboros/time_utils.h> -#define DIF_NAME "*" #define THREADS_SIZE 10 pthread_t listen_thread; @@ -43,19 +42,12 @@ pthread_cond_t fds_signal; void shutdown_server(int signo, siginfo_t * info, void * c) { - char * dif = DIF_NAME; int i; switch(signo) { case SIGINT: case SIGTERM: case SIGHUP: - if (ap_unreg(&dif, 1)) { - printf("Failed to unregister application.\n"); - ap_fini(); - exit(EXIT_FAILURE); - } - pthread_cancel(listen_thread); for (i = 0; i < THREADS_SIZE; i++) { @@ -157,36 +149,20 @@ void * worker(void * o) void * listener(void * o) { - char * dif = DIF_NAME; - int server_fd; - char * client_name = NULL; int client_fd = 0; int response = 0; - if (ap_init(SERVER_AP_NAME)) { - printf("Failed to init AP.\n"); - exit(EXIT_FAILURE); - } - - server_fd = ap_reg(&dif, 1); - if (server_fd < 0) { - printf("Failed to register application.\n"); - ap_fini(); - exit(EXIT_FAILURE); - } - printf("Server started, interval is %ld s, timeout is %ld s.\n", server_settings.interval, server_settings.timeout); while (true) { - client_fd = flow_accept(server_fd, - &client_name, NULL); + client_fd = flow_accept(NULL); if (client_fd < 0) { printf("Failed to accept flow.\n"); break; } - printf("New flow from %s.\n", client_name); + printf("New flow.\n"); pthread_mutex_lock(&fds_lock); @@ -259,7 +235,5 @@ int server_main() pthread_join(threads[i], NULL); } - ap_fini(); - return 0; } |