b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: "Linus Lüssing" <linus.luessing@web.de>
To: "B.A.T.M.A.N" <b.a.t.m.a.n@lists.open-mesh.net>
Subject: [B.A.T.M.A.N.] [patch] adding subgraph-feature to vis-output in dot-file-format
Date: Sun, 30 Aug 2009 03:36:48 +0200	[thread overview]
Message-ID: <20090830013647.GA26017@Linus-Debian> (raw)

[-- Attachment #1: Type: text/plain, Size: 6599 bytes --]

Pfeh... long night again, but here you go. With this patch,
batman-adv now supports the subgraphing-feature of the
dot-file-format. The vis-output can then be parsed with 
"fdp -Tsvg -Gcharset=utf8 /proc/net/batman-adv/vis > test.svg"
for example. 

Interfaces belonging to one BATMAN-node can be found
inside a box, the primary interface of a BATMAN-node is
double-circled. The output also got more detailed, in that
connections between nodes are being displayed with the exact
mac address of the used interface instead of replacing one end
with the primary interface's mac (see [0] for the problems I had
posted before).

Cheers, Linus

PS: Please check if I got that kmalloc stuff right.
PPS: I had to introduce a src-field in the vis-packet-struct,
therefore the compatibility version had to be increased as well.

[0] https://lists.open-mesh.net/pipermail/b.a.t.m.a.n/2009-August/002832.html

Index: vis.c
===================================================================
--- vis.c	(revision 1417)
+++ vis.c	(working copy)
@@ -333,6 +333,7 @@
 
 			/* fill one entry into buffer. */
 			entry = &entry_array[info->packet.entries];
+			memcpy(entry->src, orig_node->batman_if->net_dev->dev_addr, ETH_ALEN);
 			memcpy(entry->dest, orig_node->orig, ETH_ALEN);
 			entry->quality = orig_node->router->tq_avg;
 			info->packet.entries++;
@@ -351,6 +352,7 @@
 	while (NULL != (hashit = hash_iterate(hna_local_hash, hashit))) {
 		hna_local_entry = hashit->bucket->data;
 		entry = &entry_array[info->packet.entries];
+		memset(entry->src, 0, ETH_ALEN);
 		memcpy(entry->dest, hna_local_entry->addr, ETH_ALEN);
 		entry->quality = 0; /* 0 means HNA */
 		info->packet.entries++;
Index: vis.h
===================================================================
--- vis.h	(revision 1417)
+++ vis.h	(working copy)
@@ -33,6 +33,7 @@
 } __attribute__((packed));
 
 struct vis_info_entry {
+	uint8_t  src[ETH_ALEN];
 	uint8_t  dest[ETH_ALEN];
 	uint8_t  quality;	/* quality = 0 means HNA */
 } __attribute__((packed));
Index: packet.h
===================================================================
--- packet.h	(revision 1417)
+++ packet.h	(working copy)
@@ -26,7 +26,7 @@
 #define BAT_VIS       0x05
 
 /* this file is included by batctl which needs these defines */
-#define COMPAT_VERSION 7
+#define COMPAT_VERSION 8
 #define DIRECTLINK 0x40
 #define VIS_SERVER 0x20
 
Index: proc.c
===================================================================
--- proc.c	(revision 1417)
+++ proc.c	(working copy)
@@ -403,17 +403,47 @@
 	return single_open(file, proc_transt_global_read, NULL);
 }
 
+static void proc_vis_insert_interface(const uint8_t *interface, 
+				      struct vis_if_list **if_entry, 
+				      bool primary)
+{
+	// Did we get an empty list? (then insert imediately)
+	if(*if_entry == NULL) {
+		*if_entry = kmalloc(sizeof(struct vis_if_list), GFP_KERNEL);
+		(*if_entry)->primary = primary;
+		(*if_entry)->next = NULL;
+		memcpy((*if_entry)->addr, interface, ETH_ALEN);
+	} else {
+		// Do we already have this interface in our list?
+		while(memcmp((*if_entry)->addr, interface, ETH_ALEN)) {
+			// Or did we reach the end (then append the interface)
+			if((*if_entry)->next == NULL) {
+				(*if_entry)->next = kmalloc(sizeof(struct vis_if_list), GFP_KERNEL);
+				memcpy((*if_entry)->next->addr, interface, ETH_ALEN);
+				(*if_entry)->next->primary = primary;
+				(*if_entry)->next->next = NULL;
+				break;
+			}
+			*if_entry = (*if_entry)->next;
+		}
+	}
+}
+
 static void proc_vis_read_entry(struct seq_file *seq,
 				struct vis_info_entry *entry,
-				char *from,
+				struct vis_if_list **if_entry,
+				uint8_t *vis_orig,
 				uint8_t current_format,
 				uint8_t first_line)
 {
+	char from[40];
 	char to[40];
 	int int_part, frac_part;
 
 	addr_to_string(to, entry->dest);
 	if (entry->quality == 0) {
+		proc_vis_insert_interface(vis_orig, if_entry, true);
+		addr_to_string(from, vis_orig);
 		if (current_format == DOT_DRAW) {
 			seq_printf(seq, "\t\"%s\" -> \"%s\" [label=\"HNA\"]\n",
 				   from, to);
@@ -425,6 +455,9 @@
 	} else {
 		/* kernel has no printf-support for %f? it'd be better to return
 		 * this in float. */
+		proc_vis_insert_interface(entry->src, if_entry,
+		    (memcmp(entry->src, vis_orig, ETH_ALEN)) ? false : true);
+		addr_to_string(from, entry->src);
 		int_part = TQ_MAX_VALUE / entry->quality;
 		frac_part = 1000 * TQ_MAX_VALUE / entry->quality - int_part * 1000;
 		if (current_format == DOT_DRAW) {
@@ -444,9 +477,11 @@
 	struct hash_it_t *hashit = NULL;
 	struct vis_info *info;
 	struct vis_info_entry *entries;
-	char from[40];
+	struct vis_if_list *if_entries = NULL;
 	int i;
 	uint8_t current_format, first_line = 1;
+	char tmp_addr_str[ETH_STR_LEN];
+	struct vis_if_list *tmp_if_next;
 
 	current_format = vis_format;
 
@@ -468,14 +503,32 @@
 		info = hashit->bucket->data;
 		entries = (struct vis_info_entry *)
 			((char *)info + sizeof(struct vis_info));
-		addr_to_string(from, info->packet.vis_orig);
 
 		for (i = 0; i < info->packet.entries; i++) {
-			proc_vis_read_entry(seq, &entries[i], from,
+			proc_vis_read_entry(seq, &entries[i], &if_entries,
+					    info->packet.vis_orig,
 					    current_format, first_line);
 			if (first_line)
 				first_line = 0;
 		}
+
+		// Generate subgraphs from the collected items
+		if (current_format == DOT_DRAW) {
+			addr_to_string(tmp_addr_str, info->packet.vis_orig);
+			seq_printf(seq, "\tsubgraph \"cluster_%s\" \{\n", tmp_addr_str);
+			while (if_entries != NULL) {
+				addr_to_string(tmp_addr_str, if_entries->addr);
+				if (if_entries->primary)
+					seq_printf(seq, "\t\t\"%s\" [peripheries=2]\n", tmp_addr_str);
+				else
+					seq_printf(seq, "\t\t\"%s\"\n", tmp_addr_str);
+				// ... and empty the list while doing this
+				tmp_if_next = if_entries->next;
+				kfree(if_entries);
+				if_entries = tmp_if_next;
+			}
+			seq_printf(seq, "\t}\n");
+		}
 	}
 	spin_unlock(&vis_hash_lock);
 
Index: proc.h
===================================================================
--- proc.h	(revision 1417)
+++ proc.h	(working copy)
@@ -35,3 +35,12 @@
 
 void cleanup_procfs(void);
 int setup_procfs(void);
+
+// While scanning for vis-entries of a particular vis-originator
+// this list collects its interfaces to create a subgraph/cluster 
+// out of them later
+struct vis_if_list {
+	uint8_t addr[ETH_ALEN];
+	bool primary;
+	struct vis_if_list *next;
+};

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 835 bytes --]

             reply	other threads:[~2009-08-30  1:36 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-08-30  1:36 Linus Lüssing [this message]
2009-08-30  1:59 ` [B.A.T.M.A.N.] [patch] adding subgraph-feature to vis-output in dot-file-format Linus Lüssing
2009-08-30  7:37 ` Andrew Lunn
2009-08-30 20:23   ` Simon Wunderlich
2009-08-31  5:26     ` [B.A.T.M.A.N.] development flow Marek Lindner
2009-08-31  5:50       ` Andrew Lunn
2009-09-01 18:47         ` Marek Lindner
2009-09-02  6:18           ` Andrew Lunn
2009-09-03  6:06             ` Marek Lindner
2009-09-08 16:01               ` Andrew Lunn
2009-09-08 17:54                 ` [B.A.T.M.A.N.] mailing list migration (was: development flow) Marek Lindner
2009-09-18 21:14                   ` Jacob Marble
2009-09-18 21:19                     ` Jacob Marble
2009-09-19  7:59                       ` Andrew Lunn
2009-09-28  3:29                         ` Jacob Marble
2009-09-28  3:31                           ` Jacob Marble
2009-09-28  5:03                           ` Andrew Lunn
2009-09-28  6:12                             ` Jacob Marble
2009-09-29  5:06                               ` Jacob Marble
2009-09-29  5:25                                 ` Andrew Lunn
2009-09-29  9:19                                   ` Marek Lindner
2009-09-29 15:56                                     ` Jacob Marble
2009-09-29 16:14                                       ` Sven Eckelmann
2009-09-30  5:39                                         ` Jacob Marble
2009-09-30 19:27                                           ` Marek Lindner
2009-09-29 15:38                                   ` Jacob Marble
2009-08-30 19:55 ` [B.A.T.M.A.N.] [patch] adding subgraph-feature to vis-output in dot-file-format Simon Wunderlich
2009-08-30 20:15   ` Andrew Lunn
2009-08-30 21:47   ` Linus Lüssing
2009-08-31  5:28     ` Andrew Lunn
2009-09-01 20:47   ` Linus Lüssing
2009-09-04 18:58     ` Linus Lüssing

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090830013647.GA26017@Linus-Debian \
    --to=linus.luessing@web.de \
    --cc=b.a.t.m.a.n@lists.open-mesh.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).