B.A.T.M.A.N. Advanced on OpenWrt How-To
Last changed: 03-Jul-2009 16:14
|
OpenWrt is a linux distro for embedded devices, and is particularly well-suited for Wi-Fi routers. Batman Advanced is a tool for creating a mesh network that is transparent to IP, DHCP, etc. I needed a How-To for setting this up, but I don't think one exists yet, so here we go.
I assume that
- you can install OpenWrt
- you are not afraid of the command line
- you know at least the basics about TCP/IP networks
- you have two or three embedded computers with wifi interfaces and the option to install OpenWrt
My test environment includes three Ubiquiti NanoStation2 units and a desktop computer to work from. The three NanoStations and desktop are on a 192.168.1.0/24 network; the mesh nodes are 192.168.1.101, 192.168.1.102 and 192.168.1.103. The mesh network is 192.168.2.0/24 with no external gateway; the mesh nodes are 192.168.2.101, 192.168.2.102 and 192.168.2.103. Where examples below show only .101, the other nodes (.102 and .103) are implied. I won't go into how to setup an Internet gateway and such.
I have also tested this How-To with a few Ubiquiti PicoStation2HP units.
For each mesh node:
- Install OpenWrt 8.09.1
- Log in via telnet, set the root password and set the wired IP address and gateway
jake@bernard:~$ telnet 192.168.1.1
Trying 192.168.1.1...
Connected to 192.168.1.1.
Escape character is ']'.
=== IMPORTANT ============================
Use 'passwd' to set your login password
this will disable telnet and enable SSH
------------------------------------------
BusyBox v1.11.2 (2009-05-28 20:21:24 UTC) built-in shell (ash)
Enter 'help' for a list of built-in commands.
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
KAMIKAZE (8.09.1, r16278) ----------------------------
* 10 oz Vodka Shake well with ice and strain
* 10 oz Triple sec mixture into 10 shot glasses.
* 10 oz lime juice Salute!
---------------------------------------------------
root@OpenWrt:/# passwd
Changing password for root
New password:
Retype password:
Password for root changed by root
root@OpenWrt:/# uci set network.lan.ipaddr=192.168.1.101
root@OpenWrt:/# uci set network.lan.gateway=192.168.1.254
root@OpenWrt:/# uci set network.lan.dns=192.168.1.254
root@OpenWrt:/# uci commit
root@OpenWrt:/# /etc/init.d/network restart
<ctrl+]>
telnet> <ctrl+d>Connection closed.
jake@bernard:~$
- Connect via SSH, get the available opkg packages and install battool and kmod-batman-advanced (do not install batman-adv)
jake@bernard:~$ ssh root@192.168.1.101
root@192.168.1.101's password:
BusyBox v1.11.2 (2009-05-28 20:21:24 UTC) built-in shell (ash)
Enter 'help' for a list of built-in commands.
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
KAMIKAZE (8.09.1, r16278) ----------------------------
* 10 oz Vodka Shake well with ice and strain
* 10 oz Triple sec mixture into 10 shot glasses.
* 10 oz lime juice Salute!
---------------------------------------------------
root@OpenWrt:~# opkg update && opkg install battool kmod-batman-advanced
Downloading http://downloads.openwrt.org/kamikaze/8.09.1/atheros/packages/Packages.gz
Connecting to downloads.openwrt.org (195.56.146.238:80)
Packages.gz 100% |*************************************************************************| 141k 00:00:00 ETA
Inflating http://downloads.openwrt.org/kamikaze/8.09.1/atheros/packages/Packages.gz
Updated list of available packages in /var/opkg-lists/snapshots
Installing battool (r1176-1) to root...
Downloading http://downloads.openwrt.org/kamikaze/8.09.1/atheros/packages/battool_r1176-1_mips.ipk
Connecting to downloads.openwrt.org (195.56.146.238:80)
battool_r1176-1_mips 100% |*************************************************************************| 10162 --:--:-- ETA
Installing kmod-batman-advanced (2.6.26.8+r1176-atheros-1) to root...
Downloading http://downloads.openwrt.org/kamikaze/8.09.1/atheros/packages/kmod-batman-advanced_2.6.26.8+r1176-atheros-1_mips.ipk
Connecting to downloads.openwrt.org (195.56.146.238:80)
kmod-batman-advanced 100% |*************************************************************************| 64121 00:00:00 ETA
Configuring battool
Configuring kmod-batman-advanced
root@OpenWrt:~#
- Make sure the batman_adv kernel module is loaded
root@OpenWrt:~# lsmod | grep bat
batman_adv 51360 0
root@OpenWrt:~#
- Create the wireless device that the mesh will use (ath0)
root@OpenWrt:~# uci delete wireless.wifi0.disabled
root@OpenWrt:~# uci delete wireless.@wifi-iface[0].network
root@OpenWrt:~# uci set wireless.wifi0.channel=1
root@OpenWrt:~# uci set wireless.@wifi-iface[0].mode=ahdemo
root@OpenWrt:~# uci set wireless.@wifi-iface[0].ssid=mesh
root@OpenWrt:~# uci set network.lan.mtu=1500
root@OpenWrt:~# uci set network.lan.ifname="eth0 bat0"
root@OpenWrt:~# uci set network.ath0=interface
root@OpenWrt:~# uci set network.ath0.ifname=ath0
root@OpenWrt:~# uci set network.ath0.proto=none
root@OpenWrt:~# uci set network.ath0.mtu=1524
root@OpenWrt:~# uci set network.bat0=interface
root@OpenWrt:~# uci set network.bat0.ifname=bat0
root@OpenWrt:~# uci set network.bat0.proto=none
root@OpenWrt:~# uci set network.bat0.mtu=1500
root@OpenWrt:~# uci commit
root@OpenWrt:~# /etc/init.d/network restart
Interface doesn't accept private ioctl...
wds (8BE0): Operation not supported
root@OpenWrt:~# I'm pretty sure that error is harmless. The "uci delete" command ensures that ath0 will not have an IP address. - Add the wireless interface to the batman-advanced interface
root@OpenWrt:~# echo ath0 > /proc/net/batman-adv/interfaces
root@OpenWrt:~#
- Now stop. Reboot this node and do all of the previous steps to at least one more node. Rebooting the node is the only way I can find to get the MTU to be set correctly. Running
/etc/init.d/network restart will leave one or two of your interfaces with incorrect MTU values. If you know how to resolve this problem without rebooting, please contact me.root@OpenWrt:~# reboot && exit
- At this point, batman-advanced should be able to see other batman-advanced nodes. To see what other nodes are visible to the current node
root@OpenWrt:~# cat /proc/net/batman-adv/originators
Originator (#/255) Nexthop [outgoingIF]: Potential nexthops ... [B.A.T.M.A.N. Adv 0.1 rv1176, MainIF/MAC: ath0/00:15:6d:a7:6a:14]
00:15:6d:a7:6a:9e ( 18) 00:15:6d:a7:6a:9e [ ath0]: 00:15:6d:a7:6a:9e ( 18) 00:15:6d:a7:6a:9c ( 3)
00:15:6d:a7:6a:9c ( 39) 00:15:6d:a7:6a:9c [ ath0]: 00:15:6d:a7:6a:9c ( 39) 00:15:6d:a7:6a:9e ( 1)
root@OpenWrt:~# The first line says MainIF/MAC and the interface and MAC address of this node. Each following line is a node that the current node can see. - Test the connection with battool
root@OpenWrt:~# battool ping 00:15:6d:a7:6a:9e
batping 0:15:6d:a7:6a:9e
19 bytes from 0:15:6d:a7:6a:9e icmp_seq=0 ttl=0 time=3.35 ms
19 bytes from 0:15:6d:a7:6a:9e icmp_seq=0 ttl=0 time=2.54 ms
19 bytes from 0:15:6d:a7:6a:9e icmp_seq=0 ttl=0 time=2.56 ms
C--- 0:15:6d:a7:6a:9e batping statistic ---
3 packets transmitted, 3 received, 0% packet loss
rtt min/avg/max/mdev = 2.536/2.815/3.347/0.811 ms
root@OpenWrt:~#
- And the mesh is running! You can treat bat0 like any other interface. For example
root@OpenWrt:~# uci set network.mesh=interface
root@OpenWrt:~# uci set network.mesh.ifname=bat0
root@OpenWrt:~# uci set network.mesh.proto=static
root@OpenWrt:~# uci set network.mesh.ipaddr=192.168.2.101
root@OpenWrt:~# uci set network.mesh.netmask=255.255.255.0
root@OpenWrt:~# uci commit
root@OpenWrt:~# /etc/init.d/network restart
Interface doesn't accept private ioctl...
wds (8BE0): Operation not supported
root@OpenWrt:~# ping 192.168.2.102
PING 192.168.2.102 (192.168.2.102): 56 data bytes
64 bytes from 192.168.2.102: seq=0 ttl=64 time=29.766 ms
C
--- 192.168.2.102 ping statistics ---
2 packets transmitted, 1 packets received, 50% packet loss
round-trip min/avg/max = 29.766/29.766/29.766 ms
root@OpenWrt:~# ping 192.168.2.103
PING 192.168.2.103 (192.168.2.103): 56 data bytes
64 bytes from 192.168.2.103: seq=0 ttl=64 time=23.502 ms
C
--- 192.168.2.103 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 23.502/23.502/23.502 ms
root@OpenWrt:~#
- To enable the interface automatically
root@OpenWrt:~# echo "echo ath0 > /proc/net/batman-adv/interfaces" > /etc/rc.d/S41batman_adv
root@OpenWrt:~# chmod +x /etc/rc.d/S41batman_adv
root@OpenWrt:~# Newer versions of batman-advanced have a nice uci interface for this. If you know of a more elegant way to automatically enable bat0 in r1176, please contact me. - It's a good idea to explore /proc/net/batman-adv/ and see what's there. log and log_level are important when you get on the mailing list. After a while, you might get tired of typing
[cat|echo] ... /proc/net/batman-adv/... That's when you should check out batctl.
If you aren't familiar with setting up bridges and access points then this is for you.
Having a bunch of mesh nodes is fun, but you probably want folks to be able to use the mesh with their WiFi devices. We'll create an access point interface and add it to the bridge. This gets tricky because OpenWrt adds the ad-hoc interface after the ap interface. i.e. ath0 becomes ath1, and ath0 becomes the access point.
- Add a second athX interface
The hard part here is compiling. After that, setup is just like the directions above. You will need a Linux box, and I'll show you how this is done in Ubuntu 9.04.
- Install the packages you will need to compile
sudo apt-get install build-essential subversion ncurses-dev zlib1g-dev gawk flex unzip
- Download the OpenWrt source code
$ wget http://downloads.openwrt.org/kamikaze/8.09.1/kamikaze_8.09.1_source.tar.bz2
$ tar -xf kamikaze_8.09.1_source.tar.bz2
- Get the packages feed, then install batman-advanced and battool
$ cd kamikaze_8.09.1
$ scripts/feeds update packages
$ scripts/feeds install battool
$ scripts/feeds install batman-advanced
|