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",
+