summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/ouroboros/common.h20
-rw-r--r--include/ouroboros/ipcp.h2
-rw-r--r--include/ouroboros/irm.h2
-rw-r--r--include/ouroboros/sockets.h2
-rw-r--r--src/irmd/main.c15
-rw-r--r--src/lib/du_buff.c5
-rw-r--r--src/lib/irm.c12
-rw-r--r--src/lib/sockets.c4
-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.c68
-rw-r--r--src/tools/irm/irm_create_ipcp.c74
-rw-r--r--src/tools/irm/irm_destroy_ipcp.c65
-rw-r--r--src/tools/irm/irm_enroll_ipcp.c71
-rw-r--r--src/tools/irm/irm_ops.h28
-rw-r--r--src/tools/irm/irm_register_ipcp.c84
-rw-r--r--src/tools/irm/irm_unregister_ipcp.c84
-rw-r--r--src/tools/irm/irm_utils.c58
-rw-r--r--src/tools/irm/irm_utils.h27
-rw-r--r--src/tools/irm/main.c73
20 files changed, 685 insertions, 102 deletions
diff --git a/include/ouroboros/common.h b/include/ouroboros/common.h
index 36f6171c..00d1f482 100644
--- a/include/ouroboros/common.h
+++ b/include/ouroboros/common.h
@@ -32,7 +32,7 @@ typedef uint32_t port_id_t;
typedef struct {
uint8_t * data;
- size_t size;
+ size_t size;
} buffer_t;
typedef struct {
@@ -42,33 +42,37 @@ typedef struct {
int aei_id;
} rina_name_t;
-/* FIXME: To be extended to have all QoS params */
+/* FIXME: may need revision */
struct qos_spec {
+ char * qos_name;
+ char * dif_name;
+
uint32_t delay;
uint32_t jitter;
};
-struct dt_const {
+/* FIXME: What should be configurable in the DIF? */
+struct dif_config {
+ /* general data */
+ struct qos_spec * qosspecs;
+
+ /* TODO: efficient policies */
+
/* dt field sizes in octets */
uint8_t addr_size;
uint8_t cep_id_size;
uint8_t pdu_length_size;
uint8_t qos_id_size;
uint8_t seqno_size;
- /* uint8_t ctrl_sqnum_sz; is this in the spec?? */
/* constants for dup */
uint8_t ttl_size;
uint8_t chk_size;
-};
-/* FIXME: What should be configurable in the DIF? */
-struct dif_info {
/* values, octets */
uint32_t min_pdu_size;
uint32_t max_pdu_size;
- struct dt_const dtc;
};
#endif /* OUROBOROS_COMMON_H */
diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h
index 91223bec..7b53d827 100644
--- a/include/ouroboros/ipcp.h
+++ b/include/ouroboros/ipcp.h
@@ -35,7 +35,7 @@ int ipcp_unreg(int instance,
char ** difs);
int ipcp_bootstrap(int instance,
- struct dif_info info);
+ struct dif_conf conf);
int ipcp_enroll(int instance,
char * dif_name,
rina_name_t member);
diff --git a/include/ouroboros/irm.h b/include/ouroboros/irm.h
index 819675d1..459b0e9f 100644
--- a/include/ouroboros/irm.h
+++ b/include/ouroboros/irm.h
@@ -30,7 +30,7 @@ int irm_create_ipcp(rina_name_t name,
int irm_destroy_ipcp(rina_name_t name);
int irm_bootstrap_ipcp(rina_name_t name,
- struct dif_info info);
+ struct dif_config conf);
int irm_enroll_ipcp(rina_name_t name,
char * dif_name);
diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h
index 88e9564b..e2409c2b 100644
--- a/include/ouroboros/sockets.h
+++ b/include/ouroboros/sockets.h
@@ -39,7 +39,7 @@ struct irm_msg {
enum irm_msg_code code;
rina_name_t * name;
char * ipcp_type;
- struct dif_info * info;
+ struct dif_config * conf;
char * dif_name;
char ** difs;
size_t difs_size;
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 73533ef0..262b737c 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -50,7 +50,7 @@ static void destroy_ipcp(rina_name_t * name)
}
static void bootstrap_ipcp(rina_name_t * name,
- struct dif_info * info)
+ struct dif_config * conf)
{
LOG_MISSING;
}
@@ -78,18 +78,12 @@ static void unreg_ipcp(rina_name_t * name,
int main()
{
int sockfd;
- uint8_t * buf;
+ uint8_t buf[IRM_MSG_BUF_SIZE];
sockfd = server_socket_open(IRM_SOCK_PATH);
if (sockfd < 0)
return -1;
- buf = malloc(sizeof(*buf) * IRM_MSG_BUF_SIZE);
- if (buf == NULL) {
- LOG_ERR("Cannot allocate memory");
- return -ENOMEM;
- }
-
while (true) {
int cli_sockfd;
struct irm_msg * msg;
@@ -120,7 +114,7 @@ int main()
break;
case IRM_BOOTSTRAP_IPCP:
bootstrap_ipcp(msg->name,
- msg->info);
+ msg->conf);
break;
case IRM_ENROLL_IPCP:
enroll_ipcp(msg->name,
@@ -140,12 +134,11 @@ int main()
LOG_ERR("Don't know that message code");
break;
}
+ free(msg);
}
close(cli_sockfd);
}
- free(buf);
-
return 0;
}
diff --git a/src/lib/du_buff.c b/src/lib/du_buff.c
index bfb33339..08e3d23e 100644
--- a/src/lib/du_buff.c
+++ b/src/lib/du_buff.c
@@ -85,6 +85,9 @@ struct buffer * buffer_create (size_t size, size_t headspace, size_t len)
bool head_block = true;
head = malloc(sizeof *head);
+ if (head == NULL)
+ return NULL;
+
head->size=0;
head->data=NULL;
@@ -111,6 +114,7 @@ struct buffer * buffer_create (size_t size, size_t headspace, size_t len)
buf = malloc(sizeof *buf);
if (buf == NULL) {
LOG_WARN("Could not allocate struct.");
+ free(head);
return NULL;
}
@@ -119,6 +123,7 @@ struct buffer * buffer_create (size_t size, size_t headspace, size_t len)
if (buf->data == NULL) {
LOG_WARN("Could not allocate memory block.");
buffer_destroy_list(head);
+ free(head);
return NULL;
}
} else {
diff --git a/src/lib/irm.c b/src/lib/irm.c
index 97000029..519b4eb8 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -26,6 +26,7 @@
#include <ouroboros/common.h>
#include <ouroboros/logs.h>
#include <ouroboros/sockets.h>
+#include <stdlib.h>
static int send_irm_msg(struct irm_msg * msg)
{
@@ -47,8 +48,11 @@ static int send_irm_msg(struct irm_msg * msg)
return -1;
}
- close(sockfd);
- return 0;
+ free(buf->data);
+ free(buf);
+
+ close(sockfd);
+ return 0;
}
int irm_create_ipcp(rina_name_t name,
@@ -87,13 +91,13 @@ int irm_destroy_ipcp(rina_name_t name)
}
int irm_bootstrap_ipcp(rina_name_t name,
- struct dif_info info)
+ struct dif_config conf)
{
struct irm_msg msg;
msg.code = IRM_BOOTSTRAP_IPCP;
msg.name = &name;
- msg.info = &info;
+ msg.conf = &conf;
if (send_irm_msg(&msg)) {
LOG_ERR("Failed to send message to daemon");
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index c0331063..eebd223b 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -48,7 +48,7 @@ int client_socket_open(char * file_name)
if (connect(sockfd,
(struct sockaddr *) &serv_addr,
sizeof(serv_addr))) {
- LOG_ERR("Failed to connect to server");
+ LOG_ERR("Failed to connect to daemon");
return -1;
}
@@ -223,7 +223,7 @@ buffer_t * serialize_irm_msg(struct irm_msg * msg)
case IRM_DESTROY_IPCP:
break;
case IRM_BOOTSTRAP_IPCP:
- /* FIXME: Fields missing, need to define dif_info properly */
+ /* FIXME: Fields missing, need to define dif_conf properly */
break;
case IRM_ENROLL_IPCP:
if (msg->dif_name == NULL) {
diff --git a/src/tools/irm/CMakeLists.txt b/src/tools/irm/CMakeLists.txt
index 8e191d7e..f356d068 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..0325c810
--- /dev/null
+++ b/src/tools/irm/irm.c
@@ -0,0 +1,84 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * A tool to instruct the IRM daemon
+ *
+ * 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");
+}
+
+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..e17ed5ef
--- /dev/null
+++ b/src/tools/irm/irm_bootstrap_ipcp.c
@@ -0,0 +1,68 @@
+/*
+ * 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 <ouroboros/irm.h>
+#include <ouroboros/common.h>
+
+#include "irm_ops.h"
+#include "irm_utils.h"
+
+static void usage()
+{
+ /* FIXME: Add dif_config stuff */
+ printf("Usage: irm bootstrap_ipcp\n"
+ " ap <application process name>\n"
+ " [api <application process instance>]\n"
+ " [ae <application entity name]\n"
+ " [aei <application entity instance>]\n");
+}
+
+
+int do_bootstrap_ipcp(int argc, char ** argv)
+{
+ rina_name_t name;
+ struct dif_config conf;
+
+ name.ap_name = NULL;
+ name.api_id = 0;
+ name.ae_name = "";
+ name.aei_id = 0;
+
+ while (argc > 0) {
+ if (!parse_name(argv, &name)) {
+ printf("\"%s\" is unknown, try \"irm "
+ "enroll_ipcp\".\n", *argv);
+ return -1;
+ }
+
+ argc -= 2;
+ argv += 2;
+ }
+
+ if (name.ap_name == NULL) {
+ usage();
+ return -1;
+ }
+
+ return irm_bootstrap_ipcp(name, conf);
+}
diff --git a/src/tools/irm/irm_create_ipcp.c b/src/tools/irm/irm_create_ipcp.c
new file mode 100644
index 00000000..5c847988
--- /dev/null
+++ b/src/tools/irm/irm_create_ipcp.c
@@ -0,0 +1,74 @@
+/*
+ * 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 <ouroboros/common.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)
+{
+ rina_name_t name;
+ char * ipcp_type = NULL;
+
+ name.ap_name = NULL;
+ name.api_id = 0;
+ name.ae_name = "";
+ name.aei_id = 0;
+
+ while (argc > 0) {
+ if (!parse_name(argv, &name)) {
+ 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 || name.ap_name == NULL) {
+ usage();
+ return -1;
+ }
+
+ 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..467d1b50
--- /dev/null
+++ b/src/tools/irm/irm_destroy_ipcp.c
@@ -0,0 +1,65 @@
+/*
+ * 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 <ouroboros/irm.h>
+#include <ouroboros/common.h>
+
+#include "irm_ops.h"
+#include "irm_utils.h"
+
+static void usage()
+{
+ printf("Usage: irm destroy_ipcp\n"
+ " ap <application process name>\n"
+ " [api <application process instance>]\n"
+ " [ae <application entity name]\n"
+ " [aei <application entity instance>]\n");
+}
+
+int do_destroy_ipcp(int argc, char ** argv)
+{
+ rina_name_t name;
+
+ name.ap_name = NULL;
+ name.api_id = 0;
+ name.ae_name = "";
+ name.aei_id = 0;
+
+ while (argc > 0) {
+ if (!parse_name(argv, &name)) {
+ printf("\"%s\" is unknown, try \"irm "
+ "destroy_ipcp\".\n", *argv);
+ return -1;
+ }
+
+ argc -= 2;
+ argv += 2;
+ }
+
+ if (name.ap_name == NULL) {
+ usage();
+ return -1;
+ }
+
+ return irm_destroy_ipcp(name);
+}
diff --git a/src/tools/irm/irm_enroll_ipcp.c b/src/tools/irm/irm_enroll_ipcp.c
new file mode 100644
index 00000000..94f28f82
--- /dev/null
+++ b/src/tools/irm/irm_enroll_ipcp.c
@@ -0,0 +1,71 @@
+/*
+ * 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 <ouroboros/irm.h>
+#include <ouroboros/common.h>
+
+#include "irm_ops.h"
+#include "irm_utils.h"
+
+static void usage()
+{
+ printf("Usage: irm enroll_ipcp\n"
+ " ap <application process name>\n"
+ " [api <application process instance>]\n"
+ " [ae <application entity name]\n"
+ " [aei <application entity instance>]\n"
+ " dif <dif to enroll in>\n");
+}
+
+int do_enroll_ipcp(int argc, char ** argv)
+{
+ rina_name_t name;
+ char * dif_name = NULL;
+
+ name.ap_name = NULL;
+ name.api_id = 0;
+ name.ae_name = "";
+ name.aei_id = 0;
+
+ while (argc > 0) {
+ if (!parse_name(argv, &name)) {
+ if (matches(*argv, "dif") == 0) {
+ dif_name = *(argv + 1);
+ } else {
+ printf("\"%s\" is unknown, try \"irm "
+ "enroll_ipcp\".\n", *argv);
+ return -1;
+ }
+ }
+
+ argc -= 2;
+ argv += 2;
+ }
+
+ if (dif_name == NULL || name.ap_name == NULL) {
+ usage();
+ return -1;
+ }
+
+ return irm_enroll_ipcp(name, dif_name);
+}
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..c69ad350
--- /dev/null
+++ b/src/tools/irm/irm_register_ipcp.c
@@ -0,0 +1,84 @@
+/*
+ * 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"
+ " [ae <application entity name]\n"
+ " [aei <application entity 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)
+{
+ rina_name_t name;
+ char * difs[MAX_DIFS];
+ size_t difs_size = 0;
+
+ name.ap_name = NULL;
+ name.api_id = 0;
+ name.ae_name = "";
+ name.aei_id = 0;
+
+ while (argc > 0) {
+ if (!parse_name(argv, &name)) {
+ 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 || name.ap_name == NULL) {
+ usage();
+ return -1;
+ }
+
+ return irm_reg_ipcp(name, difs, difs_size);
+}
diff --git a/src/tools/irm/irm_unregister_ipcp.c b/src/tools/irm/irm_unregister_ipcp.c
new file mode 100644
index 00000000..a2dffc6c
--- /dev/null
+++ b/src/tools/irm/irm_unregister_ipcp.c
@@ -0,0 +1,84 @@
+/*
+ * 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 <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 unregister_ipcp\n"
+ " ap <application process name>\n"
+ " [api <application process instance>]\n"
+ " [ae <application entity name]\n"
+ " [aei <application entity instance>]\n"
+ " dif <dif name to unregister from>\n"
+ " [dif <dif name to unregister from>]\n"
+ " [... (maximum %d difs)]\n", MAX_DIFS);
+}
+
+
+int do_unregister_ipcp(int argc, char ** argv)
+{
+ rina_name_t name;
+ char * difs[MAX_DIFS];
+ size_t difs_size = 0;
+
+ name.ap_name = NULL;
+ name.api_id = 0;
+ name.ae_name = "";
+ name.aei_id = 0;
+
+ while (argc > 0) {
+ if (!parse_name(argv, &name)) {
+ 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 "
+ "unregister_ipcp\".\n", *argv);
+ return -1;
+ }
+ }
+
+ argc -= 2;
+ argv += 2;
+ }
+
+ if (difs_size == 0 || name.ap_name == NULL) {
+ usage();
+ return -1;
+ }
+
+ return irm_unreg_ipcp(name, difs, difs_size);
+}
diff --git a/src/tools/irm/irm_utils.c b/src/tools/irm/irm_utils.c
new file mode 100644
index 00000000..021227fd
--- /dev/null
+++ b/src/tools/irm/irm_utils.c
@@ -0,0 +1,58 @@
+/*
+ * 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>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <ouroboros/common.h>
+
+#include "irm_utils.h"
+
+int matches(const char * cmd, const char * pattern)
+{
+ int len = strlen(cmd);
+
+ if (len > strlen(pattern))
+ return -1;
+
+ return memcmp(pattern, cmd, len);
+}
+
+
+bool parse_name(char ** argv,
+ rina_name_t * name)
+{
+ bool found = true;
+
+ if (matches(*argv, "ap") == 0)
+ name->ap_name = *(argv + 1);
+ else if (matches(*argv, "api") == 0)
+ name->api_id = atoi(*(argv + 1));
+ else if (matches(*argv, "ae") == 0)
+ name->ae_name = *(argv + 1);
+ else if (matches(*argv, "aei") == 0)
+ name->aei_id = atoi(*(argv + 1));
+ else
+ found = false;
+
+ return found;
+}
diff --git a/src/tools/irm/irm_utils.h b/src/tools/irm/irm_utils.h
new file mode 100644
index 00000000..9332b108
--- /dev/null
+++ b/src/tools/irm/irm_utils.h
@@ -0,0 +1,27 @@
+/*
+ * 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 <stdbool.h>
+
+int matches(const char * cmd, const char * pattern);
+
+bool parse_name(char ** argv, rina_name_t * name);
diff --git a/src/tools/irm/main.c b/src/tools/irm/main.c
deleted file mode 100644
index ac09e1e7..00000000
--- a/src/tools/irm/main.c
+++ /dev/null
@@ -1,73 +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.
- */
-
-#define OUROBOROS_PREFIX "irm"
-
-#include <ouroboros/logs.h>
-#include <ouroboros/common.h>
-#include <ouroboros/irm.h>
-
-int main () {
- 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)) {
- LOG_ERR("Failed to create IPCP");
- return -1;
- }
-
- if (irm_destroy_ipcp(name)) {
- LOG_ERR("Failed to destroy IPCP");
- return -1;
- }
-
- if (irm_bootstrap_ipcp(name, info)) {
- LOG_ERR("Failed to bootstrap IPCP");
- return -1;
- }
-
- if (irm_enroll_ipcp(name, dif_name)) {
- LOG_ERR("Failed to enroll IPCP");
- return -1;
- }
-
- if (irm_reg_ipcp(name, &dif_name, difs_size)) {
- LOG_ERR("Failed to register IPCP");
- return -1;
- }
-
- if (irm_unreg_ipcp(name, &dif_name, difs_size)) {
- LOG_ERR("Failed to unregister IPCP");
- return -1;
- }
-
-
- return 0;
-}