summaryrefslogtreecommitdiff
path: root/src/tools/irm
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-03-02 19:43:07 +0100
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-03-02 19:43:07 +0100
commitccbfc46ada3317b0f3655b751d473643d4dcab72 (patch)
tree4f418e7f612a5a717e3351c3c911617537012c51 /src/tools/irm
parent3bebab119c5a2c59121355c72b4e69b2817eea3a (diff)
downloadouroboros-ccbfc46ada3317b0f3655b751d473643d4dcab72.tar.gz
ouroboros-ccbfc46ada3317b0f3655b751d473643d4dcab72.zip
tools: irm: Parse arguments for irm and create_ipcp
This parses the arguments passed to irm at the top level, and also the arguments supplied when calling irm create_ipcp. It subsequently calls irm_create_ipcp with these arguments.
Diffstat (limited to 'src/tools/irm')
-rw-r--r--src/tools/irm/CMakeLists.txt9
-rw-r--r--src/tools/irm/irm.c84
-rw-r--r--src/tools/irm/irm_bootstrap_ipcp.c32
-rw-r--r--src/tools/irm/irm_create_ipcp.c83
-rw-r--r--src/tools/irm/irm_destroy_ipcp.c32
-rw-r--r--src/tools/irm/irm_enroll_ipcp.c32
-rw-r--r--src/tools/irm/irm_ops.h28
-rw-r--r--src/tools/irm/irm_register_ipcp.c32
-rw-r--r--src/tools/irm/irm_unregister_ipcp.c32
-rw-r--r--src/tools/irm/irm_utils.c33
-rw-r--r--src/tools/irm/irm_utils.h23
-rw-r--r--src/tools/irm/main.c79
12 files changed, 419 insertions, 80 deletions
diff --git a/src/tools/irm/CMakeLists.txt b/src/tools/irm/CMakeLists.txt
index 82c73e38..b0d2697b 100644
--- a/src/tools/irm/CMakeLists.txt
+++ b/src/tools/irm/CMakeLists.txt
@@ -6,7 +6,14 @@ include_directories(${CMAKE_BINARY_DIR}/include)
set(SOURCE_FILES
# Add source files here
- main.c
+ irm.c
+ irm_create_ipcp.c
+ irm_destroy_ipcp.c
+ irm_bootstrap_ipcp.c
+ irm_enroll_ipcp.c
+ irm_register_ipcp.c
+ irm_unregister_ipcp.c
+ irm_utils.c
)
add_executable (irm ${SOURCE_FILES})
diff --git a/src/tools/irm/irm.c b/src/tools/irm/irm.c
new file mode 100644
index 00000000..cca8def4
--- /dev/null
+++ b/src/tools/irm/irm.c
@@ -0,0 +1,84 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * A tool to instruct the IRM
+ *
+ * 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/common.h>
+#include <ouroboros/irm.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "irm_ops.h"
+#include "irm_utils.h"
+
+static void usage()
+{
+ printf("Usage: irm [OPERATION]\n\n"
+ "where OPERATION = {create_ipcp destroy_ipcp \n"
+ " bootstrap_ipcp enroll_ipcp\n"
+ " register_ipcp unregister_ipcp\n"
+ " help}\n");
+}
+
+static int do_help(int argc, char **argv)
+{
+ usage();
+ return 0;
+}
+
+static const struct cmd {
+ const char * cmd;
+ int (* func)(int argc, char ** argv);
+} cmds[] = {
+ { "create_ipcp", do_create_ipcp },
+ { "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 },
+ { "help", do_help },
+ { 0 }
+};
+
+static int do_cmd(const char * argv0,
+ int argc,
+ char ** argv)
+{
+ const struct cmd * c;
+
+ for (c = cmds; c->cmd; ++c) {
+ if (matches(argv0, c->cmd) == 0)
+ return -(c->func(argc-1, argv+1));
+ }
+
+ fprintf(stderr, "\"%s\" is unknown, try \"irm help\".\n", argv0);
+ return -1;
+}
+
+
+int main (int argc, char ** argv) {
+
+ if (argc < 2) {
+ usage();
+ return 0;
+ }
+
+ return do_cmd(argv[1], argc-1, argv+1);
+}
diff --git a/src/tools/irm/irm_bootstrap_ipcp.c b/src/tools/irm/irm_bootstrap_ipcp.c
new file mode 100644
index 00000000..ca0fba0e
--- /dev/null
+++ b/src/tools/irm/irm_bootstrap_ipcp.c
@@ -0,0 +1,32 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Bootstrap IPC Processes
+ *
+ * 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 "irm_ops.h"
+
+int do_bootstrap_ipcp(int argc, char ** argv)
+{
+ printf("Nothing here in %s\n", __FUNCTION__);
+
+ return -1;
+}
diff --git a/src/tools/irm/irm_create_ipcp.c b/src/tools/irm/irm_create_ipcp.c
new file mode 100644
index 00000000..5a8478e6
--- /dev/null
+++ b/src/tools/irm/irm_create_ipcp.c
@@ -0,0 +1,83 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Create IPC Processes
+ *
+ * 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 <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include "irm_ops.h"
+#include "irm_utils.h"
+
+static void usage()
+{
+ printf("Usage: irm create_ipcp\n"
+ " ap <application process name>\n"
+ " [api <application process instance>]\n"
+ " [ae <application entity name]\n"
+ " [aei <application entity instance>]\n"
+ " type <ipc process type>\n");
+}
+
+int do_create_ipcp(int argc, char ** argv)
+{
+ char * ap_name = NULL;
+ int api_id = 0;
+ char * ae_name = "";
+ int aei_id = 0;
+ rina_name_t name;
+ char * ipcp_type = NULL;
+
+ while (argc > 0) {
+ if (matches(*argv, "ap") == 0) {
+ ap_name = *(argv + 1);
+ } else if (matches(*argv, "api") == 0) {
+ api_id = atoi(*(argv + 1));
+ } else if (matches(*argv, "ae") == 0) {
+ ae_name = *(argv + 1);
+ } else if (matches(*argv, "aei") == 0) {
+ aei_id = atoi(*(argv + 1));
+ } else if (matches(*argv, "type") == 0) {
+ ipcp_type = *(argv + 1);
+ } else {
+ printf("\"%s\" is unknown, try \"irm "
+ "create_ipcp\".\n", *argv);
+ return -1;
+ }
+
+ argc -= 2;
+ argv += 2;;
+ }
+
+ if (ipcp_type == NULL || ap_name == NULL) {
+ usage();
+ return -1;
+ }
+
+ name.ap_name = ap_name;
+ name.api_id = api_id;
+ name.ae_name = ae_name;
+ name.aei_id = aei_id;
+
+ return irm_create_ipcp(name, ipcp_type);
+}
diff --git a/src/tools/irm/irm_destroy_ipcp.c b/src/tools/irm/irm_destroy_ipcp.c
new file mode 100644
index 00000000..69170b11
--- /dev/null
+++ b/src/tools/irm/irm_destroy_ipcp.c
@@ -0,0 +1,32 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Destroy IPC Processes
+ *
+ * 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 "irm_ops.h"
+
+int do_destroy_ipcp(int argc, char ** argv)
+{
+ printf("Nothing here in %s\n", __FUNCTION__);
+
+ return -1;
+}
diff --git a/src/tools/irm/irm_enroll_ipcp.c b/src/tools/irm/irm_enroll_ipcp.c
new file mode 100644
index 00000000..058feee2
--- /dev/null
+++ b/src/tools/irm/irm_enroll_ipcp.c
@@ -0,0 +1,32 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Enroll IPC Processes
+ *
+ * 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 "irm_ops.h"
+
+int do_enroll_ipcp(int argc, char ** argv)
+{
+ printf("Nothing here in %s\n", __FUNCTION__);
+
+ return -1;
+}
diff --git a/src/tools/irm/irm_ops.h b/src/tools/irm/irm_ops.h
new file mode 100644
index 00000000..ff63b6bf
--- /dev/null
+++ b/src/tools/irm/irm_ops.h
@@ -0,0 +1,28 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Functions of the IRM tool that are one level deep
+ *
+ * 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.
+ */
+
+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);
diff --git a/src/tools/irm/irm_register_ipcp.c b/src/tools/irm/irm_register_ipcp.c
new file mode 100644
index 00000000..f271afc4
--- /dev/null
+++ b/src/tools/irm/irm_register_ipcp.c
@@ -0,0 +1,32 @@
+/*
+ * 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 "irm_ops.h"
+
+int do_register_ipcp(int argc, char ** argv)
+{
+ printf("Nothing here in %s\n", __FUNCTION__);
+
+ return -1;
+}
diff --git a/src/tools/irm/irm_unregister_ipcp.c b/src/tools/irm/irm_unregister_ipcp.c
new file mode 100644
index 00000000..bda406c7
--- /dev/null
+++ b/src/tools/irm/irm_unregister_ipcp.c
@@ -0,0 +1,32 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Unregister 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 "irm_ops.h"
+
+int do_unregister_ipcp(int argc, char ** argv)
+{
+ printf("Nothing here in %s\n", __FUNCTION__);
+
+ return -1;
+}
diff --git a/src/tools/irm/irm_utils.c b/src/tools/irm/irm_utils.c
new file mode 100644
index 00000000..34bec18c
--- /dev/null
+++ b/src/tools/irm/irm_utils.c
@@ -0,0 +1,33 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Handy helper functions for the IRM tool
+ *
+ * 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 <string.h>
+
+int matches(const char * cmd, const char * pattern)
+{
+ int len = strlen(cmd);
+
+ if (len > strlen(pattern))
+ return -1;
+
+ return memcmp(pattern, cmd, len);
+}
diff --git a/src/tools/irm/irm_utils.h b/src/tools/irm/irm_utils.h
new file mode 100644
index 00000000..da2259c6
--- /dev/null
+++ b/src/tools/irm/irm_utils.h
@@ -0,0 +1,23 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * Handy helper functions for the IRM tool
+ *
+ * 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.
+ */
+
+int matches(const char * cmd, const char * pattern);
diff --git a/src/tools/irm/main.c b/src/tools/irm/main.c
deleted file mode 100644
index ea88e4a6..00000000
--- a/src/tools/irm/main.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Ouroboros - Copyright (C) 2016
- *
- * A tool to instruct the IRM
- *
- * 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/common.h>
-#include <ouroboros/irm.h>
-#include <stdio.h>
-
-int main (int argc, char ** argv) {
-
- char * operation;
-
- if (argc < 2) {
- printf("Usage: irm [OPERATION]\n\n"
- "where OPERATION = {create_ipcp destroy_ipcp \n"
- " bootstrap_ipcp enroll_ipcp\n"
- " register_ipcp unregister_ipcp}\n");
- return 0;
- }
-
- operation = argv[1];
- printf("Operation is %s\n", operation);
-
- char * ap_name = "test";
- char * ipcp_type = "normal-ipcp";
- rina_name_t name;
- name.ap_name = ap_name;
- name.api_id = 1;
- name.ae_name = "";
- name.aei_id = 0;
- struct dif_info info;
- char * dif_name = "wienerschnitzel";
- size_t difs_size = 1;
-
- if (irm_create_ipcp(name, ipcp_type)) {
- return -1;
- }
-
- if (irm_destroy_ipcp(name)) {
- return -1;
- }
-
- if (irm_bootstrap_ipcp(name, info)) {
- return -1;
- }
-
- if (irm_enroll_ipcp(name, dif_name)) {
- return -1;
- }
-
- if (irm_reg_ipcp(name, &dif_name, difs_size)) {
- return -1;
- }
-
- if (irm_unreg_ipcp(name, &dif_name, difs_size)) {
- return -1;
- }
-
-
- return 0;
-}