diff options
author | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-06-14 14:56:55 +0200 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@intec.ugent.be> | 2016-06-14 14:56:55 +0200 |
commit | 337ab9fe73b86306b72b9eaae3b7be759f7bbd36 (patch) | |
tree | d7b237631ef17df911ec4aef766aba085a63bd30 /src/tools | |
parent | 6019a5b1ee574c8cea485ce5ba68ff77a24b4786 (diff) | |
parent | 6271d09bdd17114c3095b7e819a7bcded14f26a5 (diff) | |
download | ouroboros-337ab9fe73b86306b72b9eaae3b7be759f7bbd36.tar.gz ouroboros-337ab9fe73b86306b72b9eaae3b7be759f7bbd36.zip |
Merge remote-tracking branch 'upstream/be' into be-llc
Diffstat (limited to 'src/tools')
-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 | ||||
-rw-r--r-- | src/tools/echo/echo.c | 19 | ||||
-rw-r--r-- | src/tools/echo/echo_client.c | 11 | ||||
-rw-r--r-- | src/tools/echo/echo_server.c | 32 | ||||
-rw-r--r-- | src/tools/irm/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/tools/irm/irm.c | 5 | ||||
-rw-r--r-- | src/tools/irm/irm_ops.h | 4 | ||||
-rw-r--r-- | src/tools/irm/irm_register.c | 123 | ||||
-rw-r--r-- | src/tools/irm/irm_register_ipcp.c | 79 | ||||
-rw-r--r-- | src/tools/irm/irm_unregister.c (renamed from src/tools/irm/irm_unregister_ipcp.c) | 64 |
12 files changed, 236 insertions, 191 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; } diff --git a/src/tools/echo/echo.c b/src/tools/echo/echo.c index 849c0ca8..4484dc71 100644 --- a/src/tools/echo/echo.c +++ b/src/tools/echo/echo.c @@ -23,7 +23,6 @@ #include <stdio.h> #include <string.h> -#define SERVER_AP_NAME "echo-server" #define BUF_SIZE 256 #include "echo_client.c" @@ -37,14 +36,22 @@ static void usage() " --help Display this help text and exit\n"); } -int main(int argc, char ** argv) { +int main(int argc, char ** argv) +{ + int ret = -1; + if (ap_init(argv[0])) { + printf("Failed to init AP.\n"); + return -1; + } argc--; argv++; while (argc > 0) { if (strcmp(*argv, "-l") == 0 || strcmp(*argv, "--listen") == 0) { - return server_main(); + ret = server_main(); + ap_fini(); + return ret; } else { usage(); return 0; @@ -53,5 +60,9 @@ int main(int argc, char ** argv) { argv++; } - return client_main(); + ret = client_main(); + + ap_fini(); + + return ret; } diff --git a/src/tools/echo/echo_client.c b/src/tools/echo/echo_client.c index 5c613817..499e36ee 100644 --- a/src/tools/echo/echo_client.c +++ b/src/tools/echo/echo_client.c @@ -20,8 +20,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define CLIENT_AP_NAME "echo-client" - #include <ouroboros/dev.h> #include <stdlib.h> @@ -33,12 +31,7 @@ int client_main() char * message = "Client says hi!"; ssize_t count = 0; - if (ap_init(CLIENT_AP_NAME)) { - printf("Failed to init AP.\n"); - return -1; - } - - fd = flow_alloc(SERVER_AP_NAME, NULL, NULL); + fd = flow_alloc("echo", NULL, NULL); if (fd < 0) { printf("Failed to allocate flow.\n"); ap_fini(); @@ -72,7 +65,5 @@ int client_main() flow_dealloc(fd); - ap_fini(); - return 0; } diff --git a/src/tools/echo/echo_server.c b/src/tools/echo/echo_server.c index b72da319..c5e9f807 100644 --- a/src/tools/echo/echo_server.c +++ b/src/tools/echo/echo_server.c @@ -27,28 +27,15 @@ #include <ouroboros/dev.h> -#define DIF_NAME "*" - void shutdown_server(int signo) { - char * dif = DIF_NAME; - - if (ap_unreg(&dif, 1)) { - printf("Failed to unregister application.\n"); - ap_fini(); - exit(EXIT_FAILURE); - } - ap_fini(); exit(EXIT_SUCCESS); } int server_main() { - int server_fd = 0; int client_fd = 0; - char * dif = DIF_NAME; - char * client_name = NULL; char buf[BUF_SIZE]; ssize_t count = 0; @@ -60,27 +47,14 @@ int server_main() return -1; } - if (ap_init(SERVER_AP_NAME)) { - printf("Failed to init AP.\n"); - return -1; - } - - server_fd = ap_reg(&dif, 1); - if (server_fd < 0) { - printf("Failed to register application.\n"); - ap_fini(); - return -1; - } - 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"); if (flow_alloc_resp(client_fd, 0)) { printf("Failed to give an allocate response.\n"); @@ -106,7 +80,5 @@ int server_main() flow_dealloc(client_fd); } - ap_fini(); - return 0; } diff --git a/src/tools/irm/CMakeLists.txt b/src/tools/irm/CMakeLists.txt index f356d068..eb385908 100644 --- a/src/tools/irm/CMakeLists.txt +++ b/src/tools/irm/CMakeLists.txt @@ -11,8 +11,8 @@ set(SOURCE_FILES irm_destroy_ipcp.c irm_bootstrap_ipcp.c irm_enroll_ipcp.c - irm_register_ipcp.c - irm_unregister_ipcp.c + irm_register.c + irm_unregister.c irm_utils.c ) diff --git a/src/tools/irm/irm.c b/src/tools/irm/irm.c index d05e083e..a1dc5ade 100644 --- a/src/tools/irm/irm.c +++ b/src/tools/irm/irm.c @@ -34,6 +34,7 @@ static void usage() printf("Usage: irm [OPERATION]\n\n" "where OPERATION = {create_ipcp destroy_ipcp \n" " bootstrap_ipcp enroll_ipcp\n" + " register unregister\n" " register_ipcp unregister_ipcp\n"); } @@ -51,8 +52,8 @@ static const struct cmd { { "destroy_ipcp", do_destroy_ipcp }, { "bootstrap_ipcp", do_bootstrap_ipcp }, { "enroll_ipcp", do_enroll_ipcp }, - { "register_ipcp", do_register_ipcp }, - { "unregister_ipcp", do_unregister_ipcp }, + { "register", do_register }, + { "unregister", do_unregister }, { "help", do_help }, { 0 } }; diff --git a/src/tools/irm/irm_ops.h b/src/tools/irm/irm_ops.h index ff63b6bf..ea51cbeb 100644 --- a/src/tools/irm/irm_ops.h +++ b/src/tools/irm/irm_ops.h @@ -24,5 +24,5 @@ int do_create_ipcp(int argc, char ** argv); int do_destroy_ipcp(int argc, char ** argv); int do_bootstrap_ipcp(int argc, char ** argv); int do_enroll_ipcp(int argc, char ** argv); -int do_register_ipcp(int argc, char ** argv); -int do_unregister_ipcp(int argc, char ** argv); +int do_register(int argc, char ** argv); +int do_unregister(int argc, char ** argv); diff --git a/src/tools/irm/irm_register.c b/src/tools/irm/irm_register.c new file mode 100644 index 00000000..67c81025 --- /dev/null +++ b/src/tools/irm/irm_register.c @@ -0,0 +1,123 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * Register AP's in DIFs + * + * Dimitri Staessens <dimitri.staessens@intec.ugent.be> + * Sander Vrijders <sander.vrijders@intec.ugent.be> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <ouroboros/config.h> +#include <stdio.h> +#include <ouroboros/irm.h> +#include <ouroboros/common.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <sys/types.h> +#include <signal.h> + +#include "irm_ops.h" +#include "irm_utils.h" + +#define MAX_DIFS 128 + +static void usage() +{ + printf("Usage: irm register\n" + " n <name>\n" + " apn <application process name>\n" + " [api <application instance id>]\n" + " [auto] (instantiate apn if not running)\n" + " [dif <dif name to register with>]\n" + " [... (maximum %d difs)]\n" + " [-- <application arguments>]\n" + , MAX_DIFS); +} + + +int do_register(int argc, char ** argv) +{ + char * name = NULL; + char ** args = NULL; + char * difs[MAX_DIFS]; + size_t difs_len = 0; + bool api_opt = false; + bool args_opt = false; + bool autoexec = false; + int i = argc; + + instance_name_t api = {NULL, 0}; + + while (i > 0) { + if (matches(*argv, "name") == 0) { + name = *(argv + 1); + } else if (matches(*argv, "apn") == 0) { + api.name = *(argv + 1); + } else if (matches(*argv, "api") == 0) { + api.id = atoi(*(argv + 1)); + api_opt = true; + } else if (strcmp(*argv, "auto") == 0) { + autoexec = true; + ++i; + --argv; + } else if (strcmp(*argv, "--") == 0) { + ++argv; + --i; + args_opt = true; + break; + } else if (matches(*argv, "dif") == 0) { + difs[difs_len++] = *(argv + 1); + if (difs_len > MAX_DIFS) { + printf("Too many difs specified\n"); + return -1; + } + } else { + printf("\"%s\" is unknown, try \"irm " + "register\".\n", *argv); + return -1; + } + + i -= 2; + argv += 2; + } + + if (name == NULL || api.name == NULL) { + usage(); + return -1; + } + + if (api_opt && kill(api.id, 0) < 0) { + printf("No application running with that pid."); + return -1; + } + + if (api_opt && autoexec) { + printf("Instance is given, auto disabled.\n"); + autoexec = false; + } + + args = argv; + + if (args_opt && api_opt) { + printf("Instance is given, args ignored.\n"); + args = NULL; + i = 0; + } + + return irm_reg(name, &api, i, args, autoexec, difs, difs_len); +} diff --git a/src/tools/irm/irm_register_ipcp.c b/src/tools/irm/irm_register_ipcp.c deleted file mode 100644 index f0c1ccff..00000000 --- a/src/tools/irm/irm_register_ipcp.c +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Ouroboros - Copyright (C) 2016 - * - * Register IPC Processes in an N-1 DIF - * - * Sander Vrijders <sander.vrijders@intec.ugent.be> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include <stdio.h> -#include <ouroboros/irm.h> -#include <ouroboros/common.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> - -#include "irm_ops.h" -#include "irm_utils.h" - -#define MAX_DIFS 128 - -static void usage() -{ - printf("Usage: irm register_ipcp\n" - " ap <application process name>\n" - " [api <application process instance>]\n" - " dif <dif name to register with>\n" - " [dif <dif name to register with>]\n" - " [... (maximum %d difs)]\n", MAX_DIFS); -} - - -int do_register_ipcp(int argc, char ** argv) -{ - char * difs[MAX_DIFS]; - size_t difs_size = 0; - instance_name_t api = {NULL, 0}; - - while (argc > 0) { - if (matches(*argv, "ap") == 0) { - api.name = *(argv + 1); - } else if (matches(*argv, "api") == 0) { - api.id = atoi(*(argv + 1)); - } else if (matches(*argv, "dif") == 0) { - difs[difs_size++] = *(argv + 1); - if (difs_size > MAX_DIFS) { - printf("Too many difs specified\n"); - return -1; - } - } else { - printf("\"%s\" is unknown, try \"irm " - "register_ipcp\".\n", *argv); - return -1; - } - - argc -= 2; - argv += 2; - } - - if (difs_size == 0 || api.name == NULL) { - usage(); - return -1; - } - - return irm_reg_ipcp(&api, difs, difs_size); -} diff --git a/src/tools/irm/irm_unregister_ipcp.c b/src/tools/irm/irm_unregister.c index 3fd6f148..d778e285 100644 --- a/src/tools/irm/irm_unregister_ipcp.c +++ b/src/tools/irm/irm_unregister.c @@ -3,7 +3,8 @@ * * Unregister IPC Processes in an N-1 DIF * - * Sander Vrijders <sander.vrijders@intec.ugent.be> + * Dimitri Staessens <dimitri.staessens@intec.ugent.be> + * Sander Vrijders <sander.vrijders@intec.ugent.be> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,12 +21,15 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include <ouroboros/config.h> #include <stdio.h> #include <ouroboros/irm.h> #include <ouroboros/common.h> #include <stdlib.h> #include <string.h> #include <errno.h> +#include <sys/types.h> +#include <signal.h> #include "irm_ops.h" #include "irm_utils.h" @@ -34,36 +38,50 @@ static void usage() { - printf("Usage: irm unregister_ipcp\n" - " ap <application process name>\n" + printf("Usage: irm unregister\n" + " [name <name>]\n" + " [apn <application process name>]\n" " [api <application process instance>]\n" " dif <dif name to unregister from>\n" " [dif <dif name to unregister from>]\n" - " [... (maximum %d difs)]\n", MAX_DIFS); + " [... (maximum %d difs)]\n" + " [hard] (unregisters everything using that name)\n" + , MAX_DIFS); } - -int do_unregister_ipcp(int argc, char ** argv) +int do_unregister(int argc, char ** argv) { instance_name_t api = {NULL, 0}; char * difs[MAX_DIFS]; - size_t difs_size = 0; - + size_t difs_len = 0; + char * name = NULL; + bool hard_opt = false; + bool ap_id = false; + instance_name_t * ptr_api = NULL; while (argc > 0) { - if (matches(*argv, "ap") == 0) { + if (matches(*argv, "name") == 0) { + name = *(argv + 1); + } else if (matches(*argv, "ap") == 0) { api.name = *(argv + 1); + ptr_api = &api; } else if (matches(*argv, "api") == 0) { api.id = atoi(*(argv + 1)); + ap_id = true; + } else if (strcmp(*argv, "hard") == 0) { + hard_opt = true; + /* this has no value */ + ++argc; + --argv; } else if (matches(*argv, "dif") == 0) { - difs[difs_size++] = *(argv + 1); - if (difs_size > MAX_DIFS) { + difs[difs_len++] = *(argv + 1); + if (difs_len > MAX_DIFS) { printf("Too many difs specified\n"); return -1; } } else { printf("\"%s\" is unknown, try \"irm " - "unregister_ipcp\".\n", *argv); + "unregister\".\n", *argv); return -1; } @@ -71,10 +89,28 @@ int do_unregister_ipcp(int argc, char ** argv) argv += 2; } - if (difs_size == 0 || api.name == NULL) { + if (difs_len == 0) { + usage(); + return -1; + } + + if (name == NULL && api.name == NULL) { + printf("apn or name must be set.\n"); + usage(); + return -1; + } + + if (ap_id && api.name == NULL) { + printf("api requires apn.\n"); + usage(); + return -1; + } + + if (hard_opt && api.name != NULL) { + printf("apn and/or api must not be set when using hard.\n"); usage(); return -1; } - return irm_unreg_ipcp(&api, difs, difs_size); + return irm_unreg(name, ptr_api, difs, difs_len, hard_opt); } |