</HEAD>
<BODY>
<H1>Olsr_Switch network simulation</H1>
-<P><I>$Id: README-Olsr-Switch.html,v 1.1 2005/06/03 17:25:12 kattemat Exp $</I>
+<P><I>$Id: README-Olsr-Switch.html,v 1.2 2005/06/04 21:07:08 kattemat Exp $</I>
</P>
<H2>Summary</H2>
<P>This document gives a brief introduction to the <A HREF="http://www.olsr.org/">olsr.org</A>
></PRE><P>
<BR><BR>
</P>
-<P>To start olsrd in host-emulation mode do:
+<P>olsrd_switch has a buildt-in command for starting and
+stopping local olsrd instances and we will learn more about
+this later. But olsrd can also be ran in host-emulation mode
+from the command line. To start olsrd in host-emulation mode do:
</P>
<PRE STYLE="margin-bottom: 0.2in">./olsrd -hemu <B>IP-ADDRESS</B></PRE><P>
Here <I>IP-ADDRESS</I> will be the IP address that the process will
To delete all links do:
link * * 100
Wildcards can also be used in combination with 'bi'.
-To list all manipulated links use 'list links'.</PRE><H3>
-others</H3>
+To list all manipulated links use 'list links'.</PRE>
+<H3>olsrd</H3>
+<P>The <I>olsrd</I> command is used for manipulating links. Here is
+the help page for this command:
+</P>
+<PRE>
+> help olsrd
+Usage: <B>olsrd [start|stop|show|setb|seta] [IP|path|args]</B>
+Description:
+<I>This command is used for managing local olsrd instances from within olsr_switch.</I>
+<I>The command can be configured in runtime using the setb and seta sub-commands.</I>
+To show the current olsrd command-configuration do:
+ olsrd show
+To set the olsrd binary path do:
+ olsrd setb /full/path/to/olsrd
+To start a olsrd instance with a IP address of 10.0.0.1, do:
+ olsrd start 10.0.0.1
+To stop that same instance do:
+ olsrd stop 10.0.0.1
+</PRE>
+<H3>others</H3>
<P>Two other commands are available:
</P>
<UL>
Source IP addr Dest IP addr LQ ILQ ETX
</PRE><P>
-We have our own virtual network! :-) At out switch prompt the command
+We now have our own virtual network! Notice that you can
+start olsrd instances from olsr_switch using the <i>olsrd</i>
+command. The equvivalent of the above command line statement
+would be:
+<PRE>
+olsrd start 10.0.0.x
+</PRE>
+<P>
+Given that the olsrd command is configured properly
+(see olsrd show, setb and seta).
+</P>
+<P>
+At our switch prompt the command
<I>list</I> yields the following output:
</P>
<PRE>All connected clients:
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: commands.h,v 1.6 2005/06/03 17:26:46 kattemat Exp $
+ * $Id: commands.h,v 1.7 2005/06/04 21:07:33 kattemat Exp $
*/
"This command is used for manipulating olsr links. The link quality is a number between 0-100 representing the chance in percentage for a packet to be forwarded on the link.\nTo make the link between 10.0.0.1 and 10.0.0.2 have 50% packet loss do:\nlink 10.0.0.1 10.0.0.2 50\nNote that this will only effect the unidirectional link 10.0.0.1 -> 10.0.0.2.\nTo make the changes affect traffic in both directions do:\nlink bi 10.0.0.1 10.0.0.2 50\nTo completely block a link do:\nlink 10.0.0.1 10.0.0.2 0\nTo make all traffic pass(delete the entry) do:\nlink 10.0.0.1 10.0.0.2 100\nNote that \"bi\" can be used in all these examples.\nWildcard source and/or destinations are also supported.\nTo block all traffic from a node do:\nlink 10.0.0.1 * 0\nTo set 50% packet loss on all links to 10.0.0.2 do:\nlink * 10.0.0.2 50\nTo delete all links do:\nlink * * 100\nWildcards can also be used in combination with 'bi'.\nTo list all manipulated links use 'list links'.\n",
ohs_cmd_link
},
+ { "olsrd", "olsrd [start|stop|show|setb|seta] [IP|path|args]",
+ "Start or stop local olsrd processes. Also used to set the olsrd binary path and arguments",
+ "This command is used for managing local olsrd instances from within olsr_switch.\nThe command can be configured in runtime using the setb and seta sub-commands.\nTo show the current olsrd command-configuration do:\nolsrd show\nTo set the olsrd binary path do:\nolsrd setb /full/path/to/olsrd\nTo start a olsrd instance with a IP address of 10.0.0.1, do:\nolsrd start 10.0.0.1\nTo stop that same instance do:\nolsrd stop 10.0.0.1\n",
+ ohs_cmd_olsrd
+ },
{ NULL, NULL,
NULL,
NULL,
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: main.c,v 1.15 2005/06/03 16:36:20 kattemat Exp $
+ * $Id: main.c,v 1.16 2005/06/04 21:07:33 kattemat Exp $
*/
/* olsrd host-switch daemon */
#include "ohs_cmd.h"
#include <sys/types.h>
#include <sys/socket.h>
+#include <sys/wait.h>
#include <errno.h>
#include <signal.h>
#include <netinet/in.h>
static void
ohs_listen_loop(void);
-static int
-ohs_delete_connection(struct ohs_connection *);
-
-
-
-
char *
olsr_ip_to_string(union olsr_ip_addr *addr)
{
return 1;
}
-static int
+int
ohs_delete_connection(struct ohs_connection *oc)
{
}
}
-
int
main(int argc, char *argv[])
{
#else
signal(SIGINT, ohs_close);
signal(SIGTERM, ohs_close);
+
+ /* Avoid zombie children */
+ signal(SIGCHLD, SIG_IGN);
#endif
printf("olsrd host-switch daemon version %s starting\n", OHS_VERSION);
srand((unsigned int)time(NULL));
+ ohs_set_olsrd_path(OHS_DEFAULT_OLSRD_PATH);
ohs_init_connect_sockets();
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: ohs_cmd.c,v 1.14 2005/06/02 19:06:24 kattemat Exp $
+ * $Id: ohs_cmd.c,v 1.15 2005/06/04 21:07:33 kattemat Exp $
*/
#include "olsr_host_switch.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
#define ARG_BUF_SIZE 500
#define TOK_BUF_SIZE 500
static char tok_buf[TOK_BUF_SIZE];
+#define MAX_OLSRD_ARGS 10
+static char olsrd_path[FILENAME_MAX];
+
static void
get_arg_buf(FILE *handle, char *buf, size_t size)
{
return i + j;
}
+int
+ohs_set_olsrd_path(char *path)
+{
+ strncpy(olsrd_path, path, FILENAME_MAX);
+ return 0;
+}
+
+int
+ohs_cmd_olsrd(FILE *handle, char *args)
+{
+ char *olsrd_args[MAX_OLSRD_ARGS];
+ struct in_addr iaddr;
+
+ args += get_next_token(args, tok_buf, TOK_BUF_SIZE);
+
+ if(!strlen(tok_buf))
+ goto print_usage;
+
+ /* Start olsrd instance */
+ if(!strncmp(tok_buf, "start", strlen("start")))
+ {
+ int argc = 0, i = 0;
+
+ args += get_next_token(args, tok_buf, TOK_BUF_SIZE);
+
+ if(!strlen(tok_buf))
+ goto print_usage;
+
+ if(!inet_aton(tok_buf, &iaddr))
+ {
+ printf("Invalid IP %s\n", tok_buf);
+ goto print_usage;
+ }
+
+ olsrd_args[argc++] = olsrd_path;
+
+ if(1) /* config file is set */
+ {
+ olsrd_args[argc++] = "-f";
+ olsrd_args[argc++] = "/etc/olsrd-emu.conf";
+ }
+ olsrd_args[argc++] = "-hemu";
+ olsrd_args[argc++] = tok_buf;
+
+ olsrd_args[argc++] = "-d";
+ olsrd_args[argc++] = "0";
+ olsrd_args[argc++] = "-nofork";
+ olsrd_args[argc] = NULL;
+
+ printf("Executing: %s", olsrd_path);
+ for(i = 0; i < argc; i++)
+ printf(" %s", olsrd_args[i]);
+ printf("\n");
+
+ if(fork())
+ return 1;
+
+ if(execve(olsrd_path, olsrd_args, NULL) < 0)
+ {
+ printf("Error executing olsrd: %s\n", strerror(errno));
+ exit(1);
+ }
+ }
+ /* Stop olsrd instance */
+ else if(!strncmp(tok_buf, "stop", strlen("stop")))
+ {
+ struct ohs_connection *oc;
+
+ args += get_next_token(args, tok_buf, TOK_BUF_SIZE);
+
+ if(!strlen(tok_buf))
+ goto print_usage;
+
+ if(!inet_aton(tok_buf, &iaddr))
+ {
+ printf("Invalid IP %s\n", tok_buf);
+ goto print_usage;
+ }
+
+ oc = get_client_by_addr((union olsr_ip_addr *)&iaddr.s_addr);
+
+ if(!oc)
+ {
+ printf("No such client: %s\n", tok_buf);
+ return -1;
+ }
+ ohs_delete_connection(oc);
+
+ return 1;
+ }
+ /* Set olsrd binary path */
+ else if(!strncmp(tok_buf, "setb", strlen("setb")))
+ {
+ struct stat sbuf;
+
+ args += get_next_token(args, tok_buf, TOK_BUF_SIZE);
+
+ if(!strlen(tok_buf))
+ goto print_usage;
+
+ if(stat(tok_buf, &sbuf) < 0)
+ {
+ printf("Error setting binary \"%s\": %s\n",
+ tok_buf, strerror(errno));
+ return -1;
+ }
+
+ if((sbuf.st_mode & S_IFDIR) || !(sbuf.st_mode & S_IXUSR))
+ {
+ printf("Error setting binary \"%s\": Not a regular execuatble file!\n",
+ tok_buf);
+ return -1;
+ }
+
+ printf("New olsrd binary path:\"%s\"\n", tok_buf);
+ ohs_set_olsrd_path(tok_buf);
+
+ return 1;
+
+ }
+ /* Set arguments */
+ else if(!strncmp(tok_buf, "seta", strlen("seta")))
+ {
+
+ }
+ /* Show settings */
+ else if(!strncmp(tok_buf, "show", strlen("show")))
+ {
+ printf("olsrd command settings:\n\tBinary path: %s\n\tArguments : \n",
+ olsrd_path);
+ return 1;
+ }
+
+ print_usage:
+ printf("Usage: olsrd [start|stop|show|setb|seta] [IP|path|args]\n");
+ return 0;
+}
+
int
ohs_cmd_link(FILE *handle, char *args)
{
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: ohs_cmd.h,v 1.3 2005/05/31 05:30:40 kattemat Exp $
+ * $Id: ohs_cmd.h,v 1.4 2005/06/04 21:07:33 kattemat Exp $
*/
int (*cmd_cb)(FILE *, char *);
};
+int
+ohs_set_olsrd_path(char *);
+
int
ohs_parse_command(FILE *);
+int
+ohs_cmd_olsrd(FILE *, char *);
+
int
ohs_cmd_list(FILE *, char *);
* to the project. For more information see the website or contact
* the copyright holders.
*
- * $Id: olsr_host_switch.h,v 1.7 2005/05/31 18:18:00 kattemat Exp $
+ * $Id: olsr_host_switch.h,v 1.8 2005/06/04 21:07:33 kattemat Exp $
*/
#ifndef _OLSR_HOST_SWITCH
#define OHS_VERSION "0.1"
+#define OHS_DEFAULT_OLSRD_PATH "./olsrd"
+
#define OHS_OUT_OF_MEMORY(s) \
{ printf("ohsd: out of memory \"%s\"!\n", s); ohs_close(0);}
struct ohs_connection *
get_client_by_addr(union olsr_ip_addr *);
+int
+ohs_delete_connection(struct ohs_connection *);
+
#endif