OLSRTopologiePerl

Aus Freifunk Leipzig
Wechseln zu: Navigation, Suche

Inhaltsverzeichnis

Freifunk-Einstellungen white-russian

Um eine Topologie zu bekommen, muss zunächst dem Linksys beigebogen werden, dass er die dafür notwendigen dot-draw-daten auf port 2004 zur verfügung stellen soll.

zuerst:

 ipkg update
 ipkg install olsrd-libs
 rm /usr/lib/olsrd_bmf.so.1.5

dann:

cd /etc/init.d/
edit S53olsrd 
oder mit WinSCP Datei editieren /etc/init.d/S53olsrd

und bei Zeile 97 ein neues Plugin reinkopieren:

LoadPlugin         "olsrd_dot_draw.so.0.3"
{
       PlParam     "accept" "192.168.1.2"
       }

Die Adressse hinter "accept" müsst Ihr natürlich mit der Adresse des PC ersetzen, der die Topologie dann erstellen soll.

Dann olsr oder Geraet neustarten:

 /etc/init.d/S53olsrd restart

Zur Kontrolle könnt Ihr Euch die OLSR-Statusseite auf dem Linksys ansehen und bei Plugins nach dem dot-draw-Plugin suchen.

Testen auf Beispiel-PC:

telnet 104.61.114.1 2004

Die Adressse hinter "telnet" müsst Ihr natürlich mit der Adresse des WRT ersetzen, der die Topologie Daten senden soll.

After a while you should get some text output.

Jetzt könnt ihr von diesem PC (192.168.1.5) mit den betreffenden Perlscripten auf die Topologie-Daten zugreifen (werden im DOT-Format gesendet)


Freifunk-Einstellungen backfire

opkg update
opkg install olsrd-mod-dot-draw

Dann das Plugin über die Weboberfläche aktivieren Einträge für /etc/config/olsr leider noch unklar Firewall auf Port 2004 tcp öffnen könnte auch notwendig sein, mal sehen...

Linux-Installation

wo ist der Link hin?

Windows-Installation

Install graphviz-2.8.exe

Graphviz is open source graph visualization software.
It has several main graph layout programs. See the gallery for some sample layouts.
It also has web and interactive graphical interfaces, and auxiliary tools, libraries, and language bindings.

First install the following packages on your workstation:

http://www.graphviz.org/Download..php

Auf Windows-PC kontrollieren, ob die Path Variable jetzt ..\Graphviz\bin enthält!

Perl Script

Perl muss installiert sein! Then download the script from

http://meshcube.org/nylon/utils/olsr-topology-view.pl
DOS-Box: perl olsr-topology-view.pl --server 104.61.114.1

das Perl Script empfängt die DOT-Daten vom WRT (--server 104.61.114.1) vom Port 2004

speichert die Daten in /tmp/topology.dot

erzeugt Grafik in /tmp/topology.png

Angepasste Versionauch unter:

http://www.netwald.net/ff/Freifunk.zip

DOS-Box: perl Freifunk.pl --server 104.61.114.1

das Perl Script empfängt die DOT-Daten vom WRT (--server 104.61.114.1) vom Port 2004

speichert die Daten in c:/www/mrtg/DOT

erzeugt Grafik in c:/www/olsr3d

Die Daten (DOT + PNG-Grafik) gemessen von 114.1 aus, liegen auch im FF unter:

ftp://104.61.114.1/mrtg (alle DOT seit 28.04.06 und PNG der letzten 50 Stunden)

options:

       --server SERVER    connect to OLSR node (default: localhost)
       --port PORT        connect to port (default: 2004)
       --bgcolor          background color (default: black)
       --fontname         font name (default: Courier)
       --fontsize         font size (default: 12)
       --style            drawing style 1, 2 or 3 (default:1)
       --size X,Y         image size in inches for graphviz (default: 8,8)
       --[no]fullscreen   display fullscreen (default: off)
       --[no]rootwin      display in root window (default: off)
       --[no]graph        genereate graphics (default: on)
       --[no]show         display the graphics (default: on)
       --[no]once         run only 1 time, then exit (default: run forever)
       --[no]linewith     change line width according to metric (default: off)
       --[no]linecolor    change line color according to metric (default: off)
       --[no]resolv       resolv hostnames (default: off)
       --[no]keep         keep the .dot files with timestamp in /tmp (default: off)

Beispielbild

Node114-Topo

Beispielscript fuer cronjob

z.b. in /usr/local/bin


#!/usr/bin/perl

# a hack to display OLSR topology information
#
# copyleft 2004 Bruno Randolf <br1@subnet.at>
# licensed under the GPL

use IO::Socket;
use Getopt::Long;

$TOPPATH = "/var/www/topo";
$NAME = "topology";
$FILENAME = "$TOPPATH/$NAME.dot";
$EXT = "png";
$SERVER = "192.168.1.1";
$PORT = "2004";
$FULLSCREEN = 0;
$HELP = 0;
$KEEP = 0;
$BGCOLOR = "white";
$STYLE = 1;
$SIZE = "35,20";
$ROOTWIN = 0;
$ONCE = 0;
$GRAPH = 1;
$SHOW = 1;
$FONTNAME = "Courier";
$FONTSIZE = 48;
$LINEWIDTH = 1;
$LINECOLOR = 0;
$RESOLV = 0;

GetOptions ("server=s" => \$SERVER,
	    "port=s" => \$PORT,
	    "fullscreen!" => \$FULLSCREEN,
	    "help!" => \$HELP,
	    "keep!" => \$KEEP,
	    "bgcolor=s" => \$BGCOLOR,
	    "fontname=s" => \$FONTNAME,
	    "fontsize=s" => \$FONTSIZE,
	    "style=i" => \$STYLE,
	    "size=s" => \$SIZE,
	    "rootwin!" => \$ROOTWIN,
	    "once!" => \$ONCE,
	    "graph!" => \$GRAPH,
	    "show!" => \$SHOW,
	    "linewidth!" => \$LINEWIDTH,
	    "linecolor!" => \$LINECOLOR,
	    "resolv" => \$RESOLV,
	     );

if ($HELP) {
	print << "EOF";
usage: $0 [ --server SERVER ] [--port PORT] [--fullscreen] [--keep]

a hack to display OLSR topology information

options:
        --server SERVER    connect to OLSR node (default: localhost)
        --port PORT        connect to port (default: 2004)
        --bgcolor          background color (default: black)
        --fontname         font name (default: Courier)
        --fontsize         font size (default: 12)
        --style            drawing style 1, 2 or 3 (default:1)
        --size X,Y         image size in inches for graphviz (default: 8,8)
        --[no]fullscreen   display fullscreen (default: off)
        --[no]rootwin      display in root window (default: off)
        --[no]graph        genereate graphics (default: on)
        --[no]show         display the graphics (default: on)
        --[no]once         run only 1 time, then exit (default: run forever)
        --[no]linewith     change line width according to metric (default: off)
        --[no]linecolor    change line color according to metric (default: off)
        --[no]resolv       resolv hostnames (default: off)
        --[no]keep         keep the .dot files with timestamp in /tmp (default: off)

requires the "graphviz" and "imagemagick" packages installed
and the "olsrd_dot_draw" plugin configured on the olsr node

EOF
	exit;
}


`touch $TOPPATH/$NAME.$EXT`;

$remote = IO::Socket::INET->new(
                        Proto    => "tcp",
                        PeerAddr => $SERVER,
                        PeerPort => $PORT,
                    )
                  or die "cannot connect to port $PORT at $SERVER!\nis the olsrd_dot_draw plugin loaded and configured to allow connections from this host?\n";

$f;
$start = 1;

$FULLOPT = "-backdrop -background black" if $FULLSCREEN;

if ($STYLE == 1) {
	$DOT_CMD = "neato -Tpng -Gsize=${SIZE} -Gbgcolor=${BGCOLOR} -Gsplines=true -Nstyle=filled -Nfontname=${FONTNAME} -Nfontsize=${FONTSIZE} -Efontname=${FONTNAME} -Efontsize=${FONTSIZE} -Ncolor=black -Nfillcolor=#ffcb05 -Ecolor=#dc0067 -Elen=6 -Earrowsize=2 -Efontcolor=white $FILENAME -o $TOPPATH/$NAME.new";
}
elsif ($STYLE == 2) {
	$BGCOLOR = "grey";
	$DOT_CMD = "dot -Tpng -Gsize=${SIZE} -Elen=2 -Ncolor=grey -Nstyle=filled -Nfillcolor=white -Nfontname=${FONTNAME} -Nfontsize=${FONTSIZE} -Efontname=${FONTNAME} -Efontsize=${FONTSIZE} -Nfontcolor=red -Nwidth=1 -Gbgcolor=$BGCOLOR $FILENAME -o $TOPPATH/$NAME.new";
}
elsif ($STYLE == 3) {
#	$BGCOLOR = "\#000000";
	$DOT_CMD = "neato -Tpng -Gsize=10,9 -Gbgcolor=${BGCOLOR} -Gsplines=true -Nstyle=filled -Nfontname=${FONTNAME} -Nfontsize=${FONTSIZE} -Efontname=${FONTNAME} -Efontsize=${FONTSIZE} -Nheight=1.3 -Nwidth=1.3 -Gsplines=true -Ncolor=orange -Nfillcolor=orange -Ecolor=black -Elen=4 -Earrowsize=3 $FILENAME -o $TOPPATH/$NAME.new";
}


while ( <$remote> ) 
{
	$line = $_;
	if ($RESOLV) {
		$line = resolv( $line );
	}
	if ($LINEWIDTH || $LINECOLOR) {
		$line = draw_thicker_metric_lines( $line );
	}
	$f = $f . $line;

	# end of one graph
	if ( $line =~ /}/i ) { 
		#print "* ";
		open DOTFILE, ">$FILENAME";
		print DOTFILE $f;
		close DOTFILE;
		$f = "";
`grep -v "0.0.0.0" $FILENAME > $TOPPATH/$NAME.1`;
`grep -v "104.61.239.1" $TOPPATH/$NAME.1 > $TOPPATH/$NAME.2`;
`grep -v "HNA" $TOPPATH/$NAME.2 > $TOPPATH/$NAME.3`;
`grep -v "255.255" $TOPPATH/$NAME.3 > $TOPPATH/$NAME.4`;
`grep -v "104.61.0.1" $TOPPATH/$NAME.4 > $TOPPATH/$NAME.5`;
`grep -v "104.61.0.2" $TOPPATH/$NAME.5 > $TOPPATH/$NAME.6`;
`cp $TOPPATH/$NAME.6 $FILENAME`;


		if ($GRAPH) {
			`$DOT_CMD`;
			`mv $TOPPATH/$NAME.new $TOPPATH/$NAME.$EXT`;
	$TEXTY = `date`;
	$ROUTES = `grep 104 $TOPPATH/$NAME.$EXT \| wc -l`;
	`convert -resize 600x600 -geometry 600x600 -font helvetica -fill black -pointsize 11 -draw 'text 10,20 "$TEXTY"' -draw 'text 10,8 "Freifunk Leipzig Netztopologie"' -draw 'text 10,32 "$ROUTES"' $TOPPATH/$NAME.$EXT $TOPPATH/leipzig-topo.png`;
	`scp $TOPPATH/leipzig-topo.png freifunkfeeds\@feeds.leipzig.freifunk.net:httpdocs/`;

		}
		if ($KEEP) {
			`cp $TOPPATH/$NAME.dot $TOPPATH/$NAME-\$(date +'%Y-%m-%d-%H-%M-%S').dot`;
		}
		exit if $ONCE;
		exit;
	}
}

print "connection closed\n";


sub resolv {
	my $l = shift;
	if ( $l =~ /\"(.*)\" -> "([^[]*)"(.*)/) {
		my $from = $1;
		my $to = $2;
		my $rest = $3;
		$from =~ s/\"//g;
		$to =~ s/\"//g;
		my $iaddrf = inet_aton($from);
		my $fromn  = gethostbyaddr($iaddrf, AF_INET);
		my $iaddrt = inet_aton($to);
		my $ton  = gethostbyaddr($iaddrt, AF_INET);
		$fromn = $from if ! $fromn;
		$ton = $to if ! $ton;
		$l = "\"$fromn\" -> \"$ton\"$rest\n";
	}
	return $l;
}


sub draw_thicker_metric_lines { 
	# sla 04.04.2005
	# a hack to draws thicker lines for better metrics (the better the thicker).
	# colorize the metric lines.
	#
	my $l = shift;
	if ($l =~ /.*label="[0-9].*/){     # recognizion pattern
		@n=split (/"/,$l);         # split the string to get the metric value
		if ($LINECOLOR) {
			if ( $n[5]>2 ) {        # colorize metrics greater than 2 gray            
				$c="888888";
			}
			else {                     # colorize metrics less than 2 black
				$c="000000";            
			}
			$setcol = "color=\"#$c\",";
		}
		if ($LINEWIDTH) {
			if ($n[5]>0 && $n[5]<10) {  # thicker lines if 10 > metric > 0
				$lt=6/$n[5];
				$at=$lt/2;
			}
			else {                     # at least draw a thin line
				$lt=1;
				$at=$lt;
			}
			$setwidth = "style=\"setlinewidth($lt)\", arrowsize=$at";
		}
		$l =~ s/\]/, $setcol $setwidth]/g; # replace pattern
	}
	return $l;
}

__END__