[PATCH v3] nodewatcher: only add direct batman originators

Tim Niemeyer tim.niemeyer at mastersword.de
Sa Okt 10 16:46:39 CEST 2015


This is a normal scenario:
--- %< ---
originator last-seen (quality) nexthop [interface]: .. possible nexthops ..
A    0.270s   (134) A [    w2mesh]: C ( 79) A (134)
B    0.170s   (245) B [    w2mesh]: B (245)
C    1.850s   (152) C [    w2mesh]: A ( 83) C (152)
--- >% ---
Nodewatcher will send only the originator, last-seen, quality, nexthop
and the interface. Nothing about the possible nexthops. Because Netmon
can't show every Originator (to bad performance), we need some filtering,
to only see direct neighbors. At the moment Netmon stores only
originator == nexthop entries. And there is no other way to filter,
because Netmon has only this information.

But this may fail. The problem occurs, if A has a better connection
(e.g. via eth0) with leads to an quality of 255:
--- %< ---
A    0.270s   (255) A [    eth0]: C ( 79) A (255)
B    0.170s   (245) B [    w2mesh]: B (245)
C    1.850s   (204) A [    eth0]: A (204) C (152)
--- >% ---
In this example, Netmon wouldn't show the connection to C.

This patch doesn't use the originator == nexthop filter. Instead a
filter like "originator is anywhere in the possible nexthops" is used.
With this, we can disable the filtering in Netmon and show at least that
there is directly connection. With the "batctl o" command it is not
possible to show the correct interface for this direct connection.

Signed-off-by: Tim Niemeyer <tim.niemeyer at mastersword.de>
---

Changes in v3:
- Add comments to AWK
- Add better commit log
- Increment the script version

 bsp/default/root_file_system/etc/nodewatcher.sh | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/bsp/default/root_file_system/etc/nodewatcher.sh b/bsp/default/root_file_system/etc/nodewatcher.sh
index 1c85cc0..3516a7f 100755
--- a/bsp/default/root_file_system/etc/nodewatcher.sh
+++ b/bsp/default/root_file_system/etc/nodewatcher.sh
@@ -2,7 +2,7 @@
 # Netmon Nodewatcher (C) 2010-2012 Freifunk Oldenburg
 # License; GPL v3
 
-SCRIPT_VERSION="31"
+SCRIPT_VERSION="32"
 
 test -f /tmp/started || exit
 
@@ -168,17 +168,22 @@ crawl() {
             BATMAN_ADV_INTERFACES=$BATMAN_ADV_INTERFACES"<$iface><name>$iface</name><status>$status</status></$iface>"
         done
 
+        # Build a list of direct neighbors
         batman_adv_originators=$(awk \
-            'BEGIN { FS=" "; i=0 }
-            /O/ { next }
-            /B/ { next }
-            {   sub("\\(", "", $0)
+            'BEGIN { FS=" "; i=0 } # set the delimiter to " "
+            /O/ { next } # ignore lines with O (will remove second line)
+            /B/ { next } # ignore line with B (will remove first line)
+            {   sub("\\(", "", $0) # remove parentheses
                 sub("\\)", "", $0)
                 sub("\\[", "", $0)
                 sub("\\]:", "", $0)
                 sub("  ", " ", $0)
-                printf "<originator_"i"><originator>"$1"</originator><link_quality>"$3"</link_quality><nexthop>"$4"</nexthop><last_seen>"$2"</last_seen><outgoing_interface>"$5"</outgoing_interface></originator_"i">"
-                i++
+                o=$1".*"$1 # build a regex to find lines that contains the $1 (=originator) twice
+                if ($0 ~ o) # filter for this regex (will remove entries without direct neighbor)
+                {
+                    printf "<originator_"i"><originator>"$1"</originator><link_quality>"$3"</link_quality><nexthop>"$4"</nexthop><last_seen>"$2"</last_seen><outgoing_interface>"$5"</outgoing_interface></originator_"i">"
+                    i++
+                }
             }' /sys/kernel/debug/batman_adv/bat0/originators)
         
 		batman_adv_gateway_mode=$(batctl gw)
-- 
2.1.4




Mehr Informationen über die Mailingliste franken-dev