Re: [B.A.T.M.A.N.] batman advanced in openwrt

Jacob Marble
2009-06-15T19:40:13Z

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

On Fri, Jun 12, 2009 at 10:59 AM, Marek Lindner<lindner_marek@yahoo.de> wrote:
>> Also, it's tedious to deal with /proc/net/batman-adv/*  It's cool in
>> hacky sort of way, but tedious.  Is there any way that this could be
>> manipulated with a script?  brctl is a nice interface, how about
>> bactl?  "bactl show originators"  "bactl show interfaces"  "bactl set
>> log_level 15"  "bactl help"  Of course, leave the /proc interface for
>> hard-core types. ;)
>
> The idea sounds interesting. We could integrate these feature into the
> battools in order to not create another tool. What do you think ?

Here is batctl. I have only tested it in OpenWrt 8.09.1 and the latest SVN.

Jake

[-- Attachment #2: batctl --]
[-- Type: application/octet-stream, Size: 3551 bytes --]

#!/bin/sh
#
# batctl - batman-adv control tool; wrapper for /proc/net/batman-adv interface
#
# written by Jacob Marble (jacobmarble@gmail.com)
# jun-2009

PREFIX="/proc/net/batman-adv/"
INTERFACES="interfaces"
ORIGINATORS="originators"
LOG_LEVEL="log_level"
ORIG_INTERVAL="orig_interval"
TRANSTABLE_GLOBAL="transtable_global"
TRANSTABLE_LOCAL="transtable_local"
AGGREGATE_OGM="aggregate_ogm"
VIS="vis"
VIS_FORMAT="vis_format"
LOG="log"

batctl_test_file() {
if [ ! -r $1 ] ; then
echo "$1 does not exist or is not readable."
exit 1
fi
return 0
}

batctl_interfaces() {
batctl_test_file $PREFIX$INTERFACES
if [ -n "$1" ] ; then
if [ "$1" = "none" ] ; then
echo "" > $PREFIX$INTERFACES
else
echo "$1" > $PREFIX$INTERFACES
fi
fi
echo "Interfaces attached to bat0: `cat $PREFIX$INTERFACES`"
}

batctl_originators() {
batctl_test_file $PREFIX$ORIGINATORS
cat $PREFIX$ORIGINATORS
}

batctl_log_level() {
batctl_test_file $PREFIX$LOG_LEVEL
[ -n "$1" ] && echo "$1" > $PREFIX$LOG_LEVEL
echo -e "Currently logging:\n`cat $PREFIX$LOG_LEVEL`"
}

batctl_orig_interval() {
batctl_test_file $PREFIX$ORIG_INTERVAL
[ -n "$1" ] && echo "$1" > $PREFIX$ORIG_INTERVAL
echo "Originator Interval: `cat $PREFIX$ORIG_INTERVAL`"
}

batctl_transtable_global() {
batctl_test_file $PREFIX$TRANSTABLE_GLOBAL
cat $PREFIX$TRANSTABLE_GLOBAL
}

batctl_transtable_local() {
batctl_test_file $PREFIX$TRANSTABLE_LOCAL
cat $PREFIX$TRANSTABLE_LOCAL
}

batctl_aggregate_ogm() {
batctl_test_file $PREFIX$AGGREGATE_OGM
echo "Aggregate OGM value: `cat $PREFIX$AGGREGATE_OGM`"
}

batctl_vis() {
batctl_test_file $PREFIX$VIS
[ -n "$1" ] && echo "$1" > $PREFIX$VIS
echo -e "Visualization server says:\n`cat $PREFIX$VIS`"
}

batctl_vis_format() {
batctl_test_file $PREFIX$VIS_FORMAT
[ -n "$1" ] && echo "$1" > $PREFIX$VIS_FORMAT
echo -e "Visualization server format:\n`cat $PREFIX$VIS_FORMAT`"
}

batctl_log() {
batctl_test_file $PREFIX$LOG
cat $PREFIX$LOG
}

if [ $# -ne 0 ] ; then
[ "$1" = "all" -o "$1" = "$INTERFACES" ] && batctl_$INTERFACES $2
[ "$1" = "all" ] && echo -e ""
[ "$1" = "all" -o "$1" = "$ORIGINATORS" ] && batctl_$ORIGINATORS
[ "$1" = "all" ] && echo -e ""
[ "$1" = "all" -o "$1" = "$LOG_LEVEL" ] && batctl_$LOG_LEVEL $2
[ "$1" = "all" ] && echo -e ""
[ "$1" = "all" -o "$1" = "$ORIG_INTERVAL" ] && batctl_$ORIG_INTERVAL $2
[ "$1" = "all" ] && echo -e ""
[ "$1" = "all" -o "$1" = "$TRANSTABLE_GLOBAL" ] && batctl_$TRANSTABLE_GLOBAL
[ "$1" = "all" ] && echo -e ""
[ "$1" = "all" -o "$1" = "$TRANSTABLE_LOCAL" ] && batctl_$TRANSTABLE_LOCAL
[ "$1" = "all" ] && echo -e ""
[ "$1" = "all" -o "$1" = "$AGGREGATE_OGM" ] && batctl_$AGGREGATE_OGM
[ "$1" = "all" ] && echo -e ""
[ "$1" = "all" -o "$1" = "$VIS" ] && batctl_$VIS $2
[ "$1" = "all" ] && echo -e ""
[ "$1" = "all" -o "$1" = "$VIS_FORMAT" ] && batctl_$VIS_FORMAT $2
[ "$1" = "$LOG" ] && batctl_$LOG
else
echo "batctl is batman-advanced-control, candy for the /proc interface"
echo "Usage: $0 command [value]"
echo "commands:"
echo " $INTERFACES [athX|ethX|none|whatever]"
echo " $ORIGINATORS"
echo " $LOG_LEVEL [0-15]"
echo " $ORIG_INTERVAL [integer > 0]"
echo " $TRANSTABLE_GLOBAL"
echo " $TRANSTABLE_LOCAL"
echo " $AGGREGATE_OGM"
echo " $VIS [client|server]"
echo " $VIS_FORMAT [dot_draw|json]"
echo " $LOG"
echo " all"
echo "examples:"
echo " $0 $INTERFACES ath0 # add ath0 to the bat0 interface"
echo " $0 $INTERFACES none # clear all interfaces and disable batman-advanced"
echo " $0 all # show everything except the log"
exit 0
fi