[B.A.T.M.A.N.] /proc vis rework

2009-11-30 Thread Andrew Lunn
Hi Folks

A while back i suggested we re-work the /proc/net/batman/vis format.
Attached are two patches to achieve this. One patch is for the kernel
model sources and the second extends batctl so that it can read from
the /proc file and output dot or json format as before. The patch
includes documentation for the new new batctl command in the man page.

I've tested the dot output using graphviz dot. However i don't have
any tools which use the json output. So that format is not tested.

Andrew
Index: batctl/vis.c
===
--- batctl/vis.c	(revision 0)
+++ batctl/vis.c	(revision 0)
@@ -0,0 +1,323 @@
+/* Copyright (C) 2009 B.A.T.M.A.N. contributors:
+ * Andrew Lunn 
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA
+ *
+ */
+
+#define _GNU_SOURCE
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "main.h"
+#include "vis.h"
+#include "functions.h"
+#include "bat-hosts.h"
+#include "proc.h"
+
+#define TQ_MAX_VALUE 255
+
+typedef void (*print_tq_t)(char * orig, char * from, const long tq);
+typedef void (*print_HNA_t)(char * orig, char * from);
+typedef void (*print_1st_t)(char * orig);
+typedef void (*print_2nd_t)(char * orig, char * from);
+typedef void (*print_header_t)(void);
+typedef void (*print_footer_t)(void);
+
+struct funcs 
+{
+  print_tq_t print_tq;
+  print_HNA_t print_HNA;
+  print_1st_t print_1st;
+  print_2nd_t print_2nd;
+  print_header_t print_header;
+  print_footer_t print_footer;
+};
+
+static bool with_HNA = true;
+static bool with_2nd = true;
+static bool with_names = true;
+
+static void 
+usage(void)
+{
+  printf("batctl vis dot {--no-HNA|-h} {--no-2nd|-2} {--numbers|-n}\n");
+  printf("or\n");
+  printf("batctl vis json {--no-HNA|-h} {--no-2nd|-2} {--numbers|-n}\n");
+}
+
+static void 
+dot_print_tq(char * orig, char * from, const long tq)
+{
+  int int_part = TQ_MAX_VALUE / tq;
+  int frac_part = (1000 * TQ_MAX_VALUE / tq) - (int_part * 1000);
+
+  printf("\t\"%s\" -> ",
+ get_name_by_macstr(orig, (with_names ? USE_BAT_HOSTS : 0)));
+  printf("\"%s\" [label=\"%d.%d\"]\n", 
+ get_name_by_macstr(from, (with_names ? USE_BAT_HOSTS : 0)),
+ int_part, frac_part);
+}
+
+static void 
+dot_print_HNA(char * orig, char * from)
+{
+printf("\t\"%s\" -> ",
+   get_name_by_macstr(orig, (with_names ? USE_BAT_HOSTS : 0)));
+printf("\"%s\" [label=\"HNA\"]\n", 
+   get_name_by_macstr(from, (with_names ? USE_BAT_HOSTS : 0)));
+}
+
+static void
+dot_print_1st(char * orig)
+{
+  printf("\tsubgraph \"cluster_%s\" {\n",
+ get_name_by_macstr(orig, (with_names ? USE_BAT_HOSTS : 0)));
+  printf("\t\t\"%s\" [peripheries=2]\n",
+ get_name_by_macstr(orig, (with_names ? USE_BAT_HOSTS : 0)));
+  printf("\t}\n");
+}
+
+static void
+dot_print_2nd(char * orig, char * from)
+{
+  printf("\tsubgraph \"cluster_%s\" {\n",
+ get_name_by_macstr(orig, (with_names ? USE_BAT_HOSTS : 0)));
+  printf("\t\t\"%s\" [peripheries=2]\n",
+ get_name_by_macstr(orig, (with_names ? USE_BAT_HOSTS : 0)));
+  printf("\t\t\"%s\"\n",
+ get_name_by_macstr(from, (with_names ? USE_BAT_HOSTS : 0)));
+  printf("\t}\n");
+}
+
+static void
+dot_print_header(void) 
+{
+  printf("digraph {\n");
+}
+
+static void
+dot_print_footer(void) 
+{
+  printf("}\n");
+}
+
+const struct funcs dot_funcs = 
+  { dot_print_tq,
+dot_print_HNA,
+dot_print_1st,
+dot_print_2nd,
+dot_print_header,
+dot_print_footer
+};
+
+static void 
+json_print_tq(char * orig, char * from, const long tq)
+{
+  int int_part = TQ_MAX_VALUE / tq;
+  int frac_part = (1000 * TQ_MAX_VALUE / tq) - (int_part * 1000);
+
+  printf("\t{ router : \"%s\", ",
+ get_name_by_macstr(orig, (with_names ? USE_BAT_HOSTS : 0)));
+  printf("neighbor : \"%s\", label : \"%d.%d\" }\n", 
+ get_name_by_macstr(from, (with_names ? USE_BAT_HOSTS : 0)),
+ int_part, frac_part);
+}
+
+static void 
+json_print_HNA(char * orig, char * from)
+{
+  printf("\t{ router : \"%s\", ",
+ get_name_by_macstr(orig, (with_names ? USE_BAT_HOSTS : 0)));
+  printf("gateway : \"%s\", label : \"HNA\" }\n", 
+ get_name_by_macstr(from, (with_names ? USE_BAT_HOSTS : 0)));
+}
+
+static void
+json_print_1st(char * orig)
+{
+  printf("\t{ primary : \"%s\" }\n",
+ 

Re: [B.A.T.M.A.N.] [PATCH] Removing the big batman lock

2009-11-30 Thread Andrew Lunn
On Sun, Nov 29, 2009 at 09:09:50PM +0100, Simon Wunderlich wrote:

> I did some testing, including loading, unloading, killing individual
> nodes etc, which seems to be clean so far. However there might be 
> more race conditions introduced by this large patch, and i'm therefore
> requesting a careful review before committing.

Hi Simon

I've not done a careful review yet, just a quick look.

Two idea for improvements:

In the purge code, add some debug code which looks at the refcount
value. If it is not between 1 and 5, prinkt() a warning what there is
probably a missing refcount operation. Since the purge code does not
run very often, it should not add much overhead, yet it is still a
useful debug tool.

The following bit of code happens quite a lot:

while (NULL != (orig_node = orig_hash_iterate(&hashit, orig_node))) {


There is also a comment about having to free hashit, if you don't
iterate to the end of the hash. How about refactoring this, more like
the linux list.h.

Make hashit a stack variable, with an init macro:

#define HASHIT(name) struct hash_it_t name = { .index = -1, .bucket = NULL, \
   .prev_bucket=NULL,   \
   .first_bucket=NULL }

and a macro for iterating over the hash

HASHIT(hashit);

orig_hash_for_each(orig_node, hashit) {

foo(orig_node);
}


Andrew


[B.A.T.M.A.N.] batman's new configuration interface

2009-11-30 Thread Marek Lindner

Hey folks,

I have given the new interface (designed in Brussels - specs are at the bottom 
of this page: http://www.open-mesh.net/wiki/2009-10-23-batman-goes-mainline) a 
little bit of thought. The main idea is to have batman list all available 
interfaces inside of /proc/sys/net/batman-adv/interfaces to let the user 
enable/disable/configure each interface individually via sysctl or batctl.

Back then we decided to create a "mesh" folder that should contain all 
relevant meshing data such as the originator table, translation tables, vis 
data, etc. We did not consider that the sysctl interface is not made for such 
data. It easily allows to set small variables but other (read-only) 
information should be placed elsewhere.

Now, we have to rethink the location. The creator of the new interface (Linus) 
suggested to create 2 folders inside of /proc: The first folder should be part 
of sysctl and contain all files that are writeable. The other should be 
/proc/net/batman-adv and contains all read-only information.
Alternatively, we could keep everything in one folder but outside of the 
sysctl interface.

Other ideas ? Opinions ?

Regards,
Marek