3 # a hack to display OLSR topology information
5 # copyleft 2004 Bruno Randolf <br1@subnet.at>
6 # licensed under the GPL
13 $FILENAME = "$TOPPATH/$NAME.dot";
15 $SERVER = "localhost";
27 $FONTNAME = "Courier";
33 GetOptions ("server=s" => \$SERVER,
35 "fullscreen!" => \$FULLSCREEN,
38 "bgcolor=s" => \$BGCOLOR,
39 "fontname=s" => \$FONTNAME,
40 "fontsize=s" => \$FONTSIZE,
43 "rootwin!" => \$ROOTWIN,
47 "linewidth!" => \$LINEWIDTH,
48 "linecolor!" => \$LINECOLOR,
54 usage: $0 [ --server SERVER ] [--port PORT] [--fullscreen] [--keep]
56 a hack to display OLSR topology information
59 --server SERVER connect to OLSR node (default: localhost)
60 --port PORT connect to port (default: 2004)
61 --bgcolor background color (default: black)
62 --fontname font name (default: Courier)
63 --fontsize font size (default: 12)
64 --style drawing style 1, 2 or 3 (default:1)
65 --size X,Y image size in inches for graphviz (default: 8,8)
66 --[no]fullscreen display fullscreen (default: off)
67 --[no]rootwin display in root window (default: off)
68 --[no]graph genereate graphics (default: on)
69 --[no]show display the graphics (default: on)
70 --[no]once run only 1 time, then exit (default: run forever)
71 --[no]linewith change line width according to metric (default: off)
72 --[no]linecolor change line color according to metric (default: off)
73 --[no]resolv resolv hostnames (default: off)
74 --[no]keep keep the .dot files with timestamp in /tmp (default: off)
76 requires the "graphviz" and "imagemagick" packages installed
77 and the "olsrd_dot_draw" plugin configured on the olsr node
84 `touch $TOPPATH/$NAME.$EXT`;
86 $remote = IO::Socket::INET->new(
91 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";
96 $FULLOPT = "-backdrop -background black" if $FULLSCREEN;
99 $DOT_CMD = "neato -Tpng -Gsize=${SIZE} -Gbgcolor=${BGCOLOR} -Gsplines=true -Nstyle=filled -Nfontname=${FONTNAME} -Nfontsize=${FONTSIZE} -Efontname=${FONTNAME} -Efontsize=${FONTSIZE} -Ncolor=white -Nfillcolor=white -Ecolor=grey -Elen=4 -Earrowsize=2 -Efontcolor=white $FILENAME -o $TOPPATH/$NAME.new";
101 elsif ($STYLE == 2) {
103 $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";
105 elsif ($STYLE == 3) {
106 $BGCOLOR = "\#ff6600";
107 $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=darkslategrey -Nfillcolor=darkslategrey -Ecolor=black -Elen=4 -Earrowsize=3 $FILENAME -o $TOPPATH/$NAME.new";
115 $line = resolv( $line );
117 if ($LINEWIDTH || $LINECOLOR) {
118 $line = draw_thicker_metric_lines( $line );
123 if ( $line =~ /}/i ) {
125 open DOTFILE, ">$FILENAME";
132 `mv $TOPPATH/$NAME.new $TOPPATH/$NAME.$EXT`;
135 `cp $TOPPATH/$NAME.dot $TOPPATH/$NAME-\$(date +'%Y-%m-%d-%H-%M-%S').dot`;
139 system "display -window root -backdrop $TOPPATH/$NAME.$EXT &";
142 system "display $FULLOPT -update 5 $TOPPATH/$NAME.$EXT &";
150 print "connection closed\n";
155 if ( $l =~ /\"(.*)\" -> "([^[]*)"(.*)/) {
161 my $iaddrf = inet_aton($from);
162 my $fromn = gethostbyaddr($iaddrf, AF_INET);
163 my $iaddrt = inet_aton($to);
164 my $ton = gethostbyaddr($iaddrt, AF_INET);
165 $fromn = $from if ! $fromn;
166 $ton = $to if ! $ton;
167 $l = "\"$fromn\" -> \"$ton\"$rest\n";
173 sub draw_thicker_metric_lines {
175 # a hack to draws thicker lines for better metrics (the better the thicker).
176 # colorize the metric lines.
179 if ($l =~ /.*label="[0-9].*/){ # recognizion pattern
180 @n=split (/"/,$l); # split the string to get the metric value
182 if ( $n[5]>2 ) { # colorize metrics greater than 2 gray
185 else { # colorize metrics less than 2 black
188 $setcol = "color=\"#$c\",";
191 if ($n[5]>0 && $n[5]<10) { # thicker lines if 10 > metric > 0
195 else { # at least draw a thin line
199 $setwidth = "style=\"setlinewidth($lt)\", arrowsize=$at";
201 $l =~ s/\]/, $setcol $setwidth]/g; # replace pattern