-
Notifications
You must be signed in to change notification settings - Fork 4
Home
The purpose of this network emulator is to test evaluate and debug mesh network protocols how the B.A.T.M.A.N. ADV protocol. This network emulator is a front end for virtualbox openwrt machines connected trough a vde-switch and wirefilter emulating a wireless link. The front end is writed in python with pygtk gui. The python program monitor the openwrt machines with snmp protocol, showing in the main screen transmited packets for each interface, and originators interfaces for batmam-adv protocol. The vde-switches have tap interfaces connected with the host machine, this permit monitor the packet traffic with the Wire-shark program, the eth0 interface of the openwrt machines are connected to the host via the vboxnet interface of the host, in this way is possible to access to the openwrt console for management purpose. The mesh is integrate with nodes and wireless connection. Each node diagram is show in the folowing figure.
The architecture is basically compound of two elements Nodos and Links (Wirefilter) as shown in the figure 1.
Figure 1
The nodos are shown in figure 2 this are more complex and have the folowing elements:
- OpenWrt, kamikaze trunk version for x86 with minimal modifications (see below)
- VirtualBox (unmodified) the version must suport vde-switch.
- Vde_switch must run two instance for nodo to support 2.4 GHz and 5.0 GHz networks. The vde-switch have a patch colorfull see below.
Figure 2
##OpenWrt A standard OpenWrt can be downloaded and configured for X86. Once that virtual machine is runining some packages must be download (ip, snmpd, tcpdump, netcat, kmod-batman-adv, batctl).
The file /etc/config/network must be set in the following form:
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config interface 'lan'
option ifname 'eth0'
option proto 'dhcp'
config interface 'mesh0'
option ifname 'eth1'
option proto 'batadv'
option mesh 'bat0'
option mtu '1538'
config interface 'mesh1'
option ifname 'eth2'
option proto 'batadv'
option mesh 'bat0'
option mtu '1538'
config globals 'globals'
option ula_prefix 'fdd1:e2dc:f954::/48'
For an automatic configuration of the network interfaces devices setup on boot must be use the following script and save it as './files/etc/rc.local' in your local OpenWrt build directory):
#!/bin/sh
# pass ip config trough ethernet mac address
RED=$(ifconfig eth1 | sed '1,1!d' | sed 's/.*HWaddr //'| sed 's/.\{11\}://'| sed 's/.\{5\}$//')
NUM=$(ifconfig eth1 | sed '1,1!d' | sed 's/.*HWaddr //'| sed 's/.*://'| sed 's/[\n\ ].*//')
#delete bridge
ifconfig br-lan down
brctl delbr br-lan
#delete eth0
ip link delete eth0
ip addr add 192.168.100.$NUM/24 dev eth0
ip link set dev eth1 mtu 1532 up
ip link set dev eth2 mtu 1532 up
batctl -m bat0 interface add eth1
batctl -m bat0 interface add eth2
ip addr add 192.168.$RED.$NUM/24 dev bat0
ip link set dev bat0 address 90:$NUM:$NUM:$NUM:$NUM:$NUM
ip link set dev bat0 up
batctl -m bat0 originators
In virtualBox is difficult to pas the IP address for the interfaces this is accomplished setting the mac address in VirtualBox and int the "rc.local" script read the mac address and set the ip in the interfaces.
####SNMPD
When the snmpd is installed in the openwrt machine is nedded to setup the MIB for batman-adv. To add custom records to the batman-adv MIB a series of shell script was conducted running and returning to stdout what it takes SNMP. To request originators table the next script was made: Script name batctl_o.sh (for originator list)
#!/bin/sh
BAT=$(batctl o | sed -n 's/^\(..:..:..:..:..:..\).*/\1/p')
echo $BAT
Script name batctl_n.sh (for next hope list)
#!/bin/sh
BAT=$(batctl o | sed -n 's/^\(..:..:..:..:..:..\).\{19\}* \(..:..:..:..:..:..\).*/\1 \2/p')
)
echo $BAT
Script name batctl_tg.sh (for the global translation table)
#!/bin/sh
BAT=$(batctl tg | sed -n 's/.*\(..:..:..:..:..:..\).* \(..:..:..:..:..:..\).*/\1 \2/p')
echo $BAT
Then add entries in the configuration file SNMPD /etc/snmp/snmpd.conf using the command uci in a terminal.
uci add snmpd exec
uci set snmpd.@exec[-1].name=.1.3.6.1.4.1.32.1.1
uci set snmpd.@exec[-1].prog=batctlo
uci set snmpd.@exec[-1].args=/batctl_o.sh
uci commit snmpd
uci add snmpd exec
uci set snmpd.@exec[-1].name=.1.3.6.1.4.1.32.1.2
uci set snmpd.@exec[-1].prog=batctln
uci set snmpd.@exec[-1].args=/batctl_n.sh
uci commit snmpd
uci add snmpd exec
uci set snmpd.@exec[-1].name=.1.3.6.1.4.1.32.1.3
uci set snmpd.@exec[-1].prog=batctltg
uci set snmpd.@exec[-1].args=/batctl_tg.sh
uci commit snmpd
/etc/init.d/snmpd restart
To the files /etc/snmp/snmp.conf append the following lines.
.......
exec .1.3.6.1.4.1.32.1.1 batctl_o /batctl_o.sh
exec .1.3.6.1.4.1.32.1.2 batctl_n /batctl_n.sh
exec .1.3.6.1.4.1.32.1.5 batctl_tg batctl_tg.sh
From the host the snmp can be tested with the followings commands.
$ snmpget -v 1 -c public 192.168.100.11 iso.3.6.1.4.1.32.1.1.101.1
iso.3.6.1.4.1.32.1.1.101.1 = STRING: "80:03:00:00:07:41 80:03:00:00:07:31 80:02:00:00:07:31 80:02:00:00:07:21 80:03:00:00:07:21"
batctl o nexhop
$ snmpget -v 1 -c public 192.168.100.11 iso.3.6.1.4.1.32.1.2.101.1
iso.3.6.1.4.1.32.1.2.101.1 = STRING: "80:02:00:00:07:21 80:02:00:00:07:21 80:03:00:00:07:21 80:02:00:00:07:21 80:03:00:00:07:21"
In the Git Hub repository there are a fully configurated virtual machine. Download openwrt.ova in VirtualBox go to File menu -> Import Appliance
####Ip assignations in openwrt.
For assign the ip address to the VM first is assigned the MAC address to the VM. Each VM have three interfaces nic1, nic2 and nic3 this interfaces in the openwrt appear as eth0, eth1 and eth2.
- nic1 (eth0) mac 80:01:00:00:07 + nodenumber(nn).
- nic2 (eth1) mac 80:02:00:00:07 + nodenumber(nn). the number 2 for 2.4GHz)
- nic3 (eth2) mac 80:05:00:00:07 + nodenumber(nn). the number 5 for 5.0GHz)
For configure the VM with this mac address the following commands are used:
VBoxManage modifyvm openwrtnn --nic1 generic --nicgenericdrv1 VDE --nicproperty1 network=/tmp/c24GHznn[2] --macaddress1 8001000007nn
VBoxManage modifyvm openwrtnn --nic2 generic --nicgenericdrv2 VDE --nicproperty2 network=/tmp/c24GHznn[2] --macaddress2 8001000007nn
VBoxManage modifyvm openwrtnn --nic3 generic --nicgenericdrv3 VDE --nicproperty3 network=/tmp/c24GHznn[2] --macaddress3 8001000007nn
Where:
- nn Node number
The script in the openwrt in /etc/rc.local read the mac address of the interface eth1 and configure the ip of the interfaces:
- eth0 192.168.100.nn
- bat0 192.168.7.nn
and the mac address of bat0 = 90:nn:nn:nn:nn:nn
Whit this convention of IP and MAC address is easy to follow the packets trough the nodes.
With the eth0 interface is possible to access to the nodes via ssh to the ip address 192.168.100.nn. The host have the vboxnet0 interface with the ip address 192.168.100.1.
Each vde-switch have a tap interface through the wireshark can sniff the packets that transverse the vde-switch.
##VirtualBox
The VirtualBox version must by 4.3 or higher. To verify VDE-Switch support in the network windows select in Attached to: "Generic Driver" in the Name: box verify that exist VDE. The configuration of the virtual machines openwrt is made trough console with the VBoxManage command.
##vde_switch The main advantage of vde_switch over uml_switch is that any clients can be attached to this virtual switch: VirtualBox, UML, tap interfaces, virtual interconnections, and not just UML instances.
If the vde_switches were just connected with wirefilter "patch cables" without modification, we would end up creating a broadcast domain and switch loops which we don't want: The goal is to allow the packets to travel only from one host to it's neighbor, not farther.
To accomplish this, the vde_switch needs to be modified to have "coloured" ports. The idea is:
- each port has a "colour" (an integer number)
- packets are only passed from ports to others with DIFFERENT colours.
- packets are dropped on outgoing ports if it has the SAME colour (same number) as the incoming port.
In this concept, the host port can have colour 1 the TAP port colour 2, while the interconnection ports have colour 0. In this way, packets can only travel from the host to (all of) the interconnection ports, or from one interconnection port to the host port. However packets can not travel between the interconnection ports, thus only allowing "one hop" connections and avoiding switch loops and shared broadcast domains. The concept is illustrated in figure 2. The patch against vde2-2.3.2 (current latest stable version) to add this colour patch can be find here: vde2-2.3.2_colour.patch
The vde-switch parched can be download from here. Attention this version can be old!
##wirefilter
The wirefilter program is a tool where its posiblen simulate various link defects and limits:
- packet loss
- burst loss
- delay
- duplicates
- bandwidth
- Interface speed
- Chanel capacity
- noise (damage to packets)
- mtu
However as the links are only set up bidirectional, interferences can unfortunately not be simulated with this system.
For advanced testing it might be necessary to apply the aforementioned link defects to some packets only whereas other packets are able to traverse the emulated environment unharmed. Once you applied the 'ethertype' patch you can specify an ethertype which wirefilter will simply forward. To apply a packet loss of 50% to all packets except batman-adv packets, run:
wirefilter --ether 0x4305 -l 50
This patch also allows to filter batman-adv packet types. To apply a packet loss of 50% to all packets except batman-adv ICMP packets, run:
wirefilter --ether 0x4305:02 -l 50
You can specify up to 10 packet types (separated by colon). The patch against vde2-2.3.1 (current latest stable version) can be found here:
vde2-2.3.1-wirefilter-ethertype.patch