Wbm2009v2/config-Olsr

From Hackerspace Brussels
Jump to: navigation, search

Parent: Wbm2009v2

Contents

[edit] Config

  • 4 foneras
    • Channel: 3
    • ESSID: olsr1
    • BSSID: 02:02:CA:FE:CA:FE


  • packages to install:
    • olsrd-ninux
    • olsrd-ninux-mod-arprefresh
    • olsrd-ninux-mod-dot-draw
    • olsrd-ninux-mod-httpinfo
    • olsrd-ninux-mod-mdns
    • olsrd-ninux-mod-nameservice
    • olsrd-ninux-mod-txtinfo
    • libpthread
    • librt
  • for logging:
    • snmpd-static_5.4.2.1-2_atheros.ipk

The package with specific patches is here: http://svn.ninux.org/svn/ninuxdeveloping/packages/olsrd-ninux/

Binary here: http://192.168.42.42/olsr/

We run olsrd-0.5.6-r6 with mDNS plugin patch and with nosegfault patch from today

    • olsrd-ninux-mod-arprefresh_0.5.6-r6-1_mips.ipk
    • olsrd-ninux-mod-dot-draw_0.5.6-r6-1_mips.ipk 17-Oct-2009 12:50 4.1K
    • olsrd-ninux-mod-httpinfo_0.5.6-r6-1_mips.ipk 17-Oct-2009 12:50 21K
    • olsrd-ninux-mod-mdns_0.5.6-r6-1_mips.ipk 17-Oct-2009 12:50 5.7K
    • olsrd-ninux-mod-nameservice_0.5.6-r6-1_mips.ipk 17-Oct-2009 12:50 14K
    • olsrd-ninux-mod-txtinfo_0.5.6-r6-1_mips.ipk 17-Oct-2009 12:50 5.3K
    • olsrd-ninux_0.5.6-r6-1_mips.ipk

IP version 4 Plugins: arprefresh, httpinfo, txtinfo

[edit] Config Snippets:

[edit] Configure the daemon

IP="192.168.1.2"

[ -f /etc/config/olsrd ] && rm /etc/config/olsrd

touch /etc/config/olsrd

uci add olsrd olsrd

uci set olsrd.@olsrd[0].IpVersion=4
uci set olsrd.@olsrd[0].DebugLevel=9

uci add olsrd LoadPlugin
uci set olsrd.@LoadPlugin[0]=LoadPlugin
uci set olsrd.@LoadPlugin[0].library=olsrd_arprefresh.so.0.1

uci add olsrd LoadPlugin
uci set olsrd.@LoadPlugin[1]=LoadPlugin
uci set olsrd.@LoadPlugin[1].library=olsrd_dot_draw.so.0.3
uci set olsrd.@LoadPlugin[1].accept="$IP"

uci add olsrd LoadPlugin
uci set olsrd.@LoadPlugin[2]=LoadPlugin
uci set olsrd.@LoadPlugin[2].library=olsrd_httpinfo.so.0.1
uci set olsrd.@LoadPlugin[2].port=1978
uci set olsrd.@LoadPlugin[2].Net="0.0.0.0 0.0.0.0"

uci add olsrd LoadPlugin
uci set olsrd.@LoadPlugin[3]=LoadPlugin
uci set olsrd.@LoadPlugin[3].library=olsrd_mdns.so.1.0.0
uci set olsrd.@LoadPlugin[3].NonOlsrIf=eth0

uci add olsrd LoadPlugin
uci set olsrd.@LoadPlugin[4]=LoadPlugin
uci set olsrd.@LoadPlugin[4].library=olsrd_nameservice.so.0.3

uci add olsrd LoadPlugin
uci set olsrd.@LoadPlugin[5]=LoadPlugin
uci set olsrd.@LoadPlugin[5].library=olsrd_txtinfo.so.0.1
uci set olsrd.@LoadPlugin[5].accept="$IP"

uci add olsrd Interface
uci set olsrd.@Interface[0]=Interface
uci set olsrd.@Interface[0].interface=wlan

adding hna4 -- only do this on one node...

uci add olsrd Hna4
uci set olsrd.@Hna4[-1].netaddr=192.168.42.0
uci set olsrd.@Hna4[-1].netmask=255.255.255.0
uci commit olsrd

[edit] Configure the wireless

uci set network.wlan.proto=static
uci set wireless.wifi0.channel=3
uci set wireless.@wifi-iface[0].ssid=olsr1
uci set wireless.@wifi-iface[0].bssid=02:02:ca:fe:ca:fe

[edit] Enable the daemon

[ -f /etc/init.d/olsrd ] && {
  /etc/init.d/olsrd enable
  /etc/init.d/olsrd start
}

[edit] Disable the daemon

[ -f /etc/init.d/olsrd ] && {
  /etc/init.d/olsrd stop
  /etc/init.d/olsrd disable
}


[edit] Details

This will be the UCI config file

config 'olsrd'
	option 'IpVersion' '4'

config 'LoadPlugin'
	option 'library' 'olsrd_arprefresh.so.0.1'

config 'LoadPlugin'
	option 'library' 'olsrd_dot_draw.so.0.3'
	option 'accept' '192.168.1.2'

config 'LoadPlugin'
	option 'library' 'olsrd_httpinfo.so.0.1'
	option 'port' '1978'
	option 'Net' '0.0.0.0 0.0.0.0'

config 'LoadPlugin'
	option 'library' 'olsrd_mdns.so.1.0.0'
	option 'NonOlsrIf' 'eth0'

config 'LoadPlugin'
	option 'library' 'olsrd_nameservice.so.0.3'

config 'LoadPlugin'
	option 'library' 'olsrd_txtinfo.so.0.1'
	option 'accept' '192.168.1.2'

config 'Interface'
	option 'interface' 'wlan'

Based in the UCI file and the init.d script of the OLSR package the following olsrd config file will be generated

DebugLevel 0
IpVersion 4
AllowNoInt yes
Pollrate 0.025
TcRedundancy 2
MprCoverage 3
LinkQualityFishEye 1
LinkQualityWinSize 100
LinkQualityDijkstraLimit 0 9.0
LinkQualityLevel 2
UseHysteresis no
FIBMetric "flat"
ClearScreen yes
Willingness 3
LinkQualityAging 0.1
LinkQualityAlgorithm "etx_ff"

Hna4
{
                192.168.1.0 255.255.255.0
}

LoadPlugin "olsrd_arprefresh.so.0.1"
{
}

LoadPlugin "olsrd_httpinfo.so.0.1"
{                                 
        PlParam "Net" "0.0.0.0 0.0.0.0"
        PlParam "port" "1978"          
}                                      
                                       
LoadPlugin "olsrd_nameservice.so.0.3"  
{                                      
        PlParam "name" "testninux"   
}                                    
                                     
LoadPlugin "olsrd_txtinfo.so.0.1"    
{                                 
}                                 
                                 
Interface "ath0"                 
{                                
        Ip4Broadcast 255.255.255.255
        HelloInterval 2.0           
        HelloValidityTime 40.0      
        TcInterval 5.0              
        TcValidityTime 100.0        
        MidInterval 18.0            
        MidValidityTime 324.0 
        HnaInterval 18.0      
        HnaValidityTime 108.0
}            

[edit] Topology Logging

To log the topology, we need HNA enabled on one node (see above).

The following python script can be used:

#!/usr/bin/env python

#
# Copyright 2006 clauz at ninux dot org
# released under the GNU Public License
# 
# OLSR Topology Logger. Dumps dot files from the OLSR dot plugin (http://www.olsr.org).
# Usage: olsrtopologylogger.py [-t timeoutseconds] [-s sleepseconds] [{+,-}h]
#                 [-x n] hostname [port]
# 
#         -t timeoutseconds       set the read timeout to timeoutseconds (default 120).
#         -s sleepseconds         pause sleepseconds between reads (default 300).
#         +h                      use human-readable date and time for filenames.
#         -h                      use floating point seconds since the epoch for filenames (default).
#         -x n            read and dump to file n times (-1=infinite) (default -1)
#         hostname                the hostname
#         port                    the port (default 2004)
# 
# example: olsrtopologylogger.py -x 3 -s 3 localhost

import telnetlib
import time
import sys

params={
'PORT':2004, #tcp
'HOST':'127.0.0.1',
'TIMEOUT':120,
'SLEEP':300,
'HUMANREADABLE':False,
'TIMES':-1,
'EXT':'.dot'
}

def readfromdotplugin(host='127.0.0.1',port='2004',timeout=120, exitonerror=True):
	try:
		dotcon=telnetlib.Telnet(host,port)
	except:
		sys.stderr.write("Error. Can't connect to %s:%s.\n" % (host,port))
		if exitonerror:
			sys.exit(2)
		else:
			return ""
	dotoutput=""
	dotoutput=dotcon.read_until('}',timeout)
	dotoutput+='\n'
	dotcon.close()
	return dotoutput
#readfromdotplugin
	
def gettimestamp(humanreadable=False):
	if humanreadable:
		ts=time.asctime()
		ts=ts.replace(' ','_')
		ts=ts.replace(':','.')
	else:
		ts=time.time()	#seconds since the epoch
	return ts
#gettimestamp

def processoptions(argvlist,params):
	if len(argvlist)<2:
		instructions= "OLSR Topology Logger. Dumps dot files from the OLSR dot plugin (http://www.olsr.org).\n"
		instructions+="Usage: %s [-t timeoutseconds] [-s sleepseconds] [{+,-}h] \n" % (argvlist[0])
		instructions+="\t\t[-x n] hostname [port]\n\n"
		instructions+="\t-t timeoutseconds\tset the read timeout to timeoutseconds (default %d).\n" % (params['TIMEOUT'],)
		instructions+="\t-s sleepseconds  \tpause sleepseconds between reads (default %d).\n" % (params['SLEEP'],)
		instructions+="\t+h               \tuse human-readable date and time for filenames"
		if params['HUMANREADABLE']:
			instructions+=" (default).\n"
		else:
			instructions+=".\n"
		instructions+="\t-h               \tuse floating point seconds since the epoch for filenames"
		if not params['HUMANREADABLE']:
			instructions+=" (default).\n"
		else:
			instructions+=".\n"
		instructions+="\t-x n           \tread and dump to file n times (-1=infinite) (default %s)\n" % (params['TIMES'],)
		instructions+="\thostname         \tthe hostname\n"
		instructions+="\tport             \tthe port (default %s)\n" % (params['PORT'],)
# 		print instructions
		sys.stderr.write(instructions)
		sys.exit(1)
	else:
		i=1
		while i<len(argvlist):
			arg=argvlist[i]
			if arg=='+h':
				params['HUMANREADABLE']=True
			elif arg=='-h':
				params['HUMANREADABLE']=False
			elif arg=='-t':
				try:
					timeoutseconds=argvlist[i+1]
					params['TIMEOUT']=int(timeoutseconds)
					i+=1
				except:
					pass
			elif arg=='-s':
				try:
					sleepseconds=argvlist[i+1]
					params['SLEEP']=int(sleepseconds)
					i+=1
				except:
					pass
 			elif arg=='-x':
				try:
					n=argvlist[i+1]
					params['TIMES']=int(n)
					i+=1
				except:
					pass
			else:
				params['HOST']=arg
				try:
					port=argvlist[i+1]
					params['PORT']=int(port)
					i+=1
				except:
					pass
			i+=1
#processoptions		


if __name__=="__main__":
	
	processoptions(sys.argv,params)
	
	try:
		firstiteration=True
		iterations=params['TIMES']	
		while iterations==-1 or iterations>0:
			print "reading..."
			dotoutput=readfromdotplugin(params['HOST'],params['PORT'],params['TIMEOUT'],firstiteration)
			firstiteration=False
			timestamp=gettimestamp(params['HUMANREADABLE'])
			
			filename='%s' % (timestamp,)
			filename+=params['EXT']
			
			try:
				try:
					dotfile=file(filename,'r')
					dotfile.close()
					erstr="Warning! File %s already exists! Skipping...",(filename,)
# 					sys.stderr.write(erstr)
					print erstr
				except IOError:
					dotfile=file(filename,'w')
					dotfile.write(dotoutput)
					dotfile.close()
					print "%s: %s created." % (time.asctime(),filename)
			except:
				sys.stderr.write("I/O Error!!")
				sys.exit(2)
			
		
			print "sleeping %d seconds..." % (params['SLEEP'],)
			time.sleep(params['SLEEP'])
			
			if iterations>0: 
				iterations-=1
		#while
	except KeyboardInterrupt:
		pass

And to convert dot files to pngs, this one (requires the graphviz package):

#!/bin/bash
# convert all dot files in the current directory to png files

IMAGEFORMAT="png"
STYLE="-Gbgcolor=orange -Nstyle=filled -Nfillcolor=white -Nfontname=monospace -Nfontsize=10 -Efontname=monospace -Efontsize=9 -Earrowhead=normal"
DOT=/usr/bin/dot

for file in *.dot; do
		name=`basename $file .dot`
		$DOT $STYLE -T$IMAGEFORMAT ${name}.dot -o ${name}.png
done

Output example: Sampletopology.png


[edit] scratchpad

list of nodes / for

00:18:84:11:01:00,wbm-004,172.16.32.4,10.20.30.4
00:12:cf:7f:fc:32,wbm-134,172.16.32.134,10.20.30.134
00:12:cf:7f:fd:e0,wbm-138,172.16.32.138,10.20.30.138
00:12:cf:7f:fb:c0,wbm-137,172.16.32.137,10.20.30.137
00:12:cf:7f:fe:4c,wbm-135,172.16.32.135,10.20.30.135
00:18:84:1c:eb:28,wbm-120,172.16.32.120,10.20.30.120
00:18:84:12:f0:14,wbm-117,172.16.32.117,10.20.30.117
00:18:84:10:44:e8,wbm-109,172.16.32.109,10.20.30.109
00:18:84:11:73:f8,wbm-101,172.16.32.101,10.20.30.101
00:18:84:11:60:04,wbm-115,172.16.32.115,10.20.30.115