Repository : ssh://git@open-mesh.org/doc
On branches: backup-redmine/2017-07-13,master
commit aa51775c657d7b9856c3ca0a8dccef4c23aa3d0e Author: Simon Wunderlich sw@simonwunderlich.de Date: Sun Oct 18 15:53:24 2009 +0000
doc: open-mesh/Emulation
aa51775c657d7b9856c3ca0a8dccef4c23aa3d0e open-mesh/Emulation.textile | 160 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+)
diff --git a/open-mesh/Emulation.textile b/open-mesh/Emulation.textile new file mode 100644 index 00000000..1bcfb8e1 --- /dev/null +++ b/open-mesh/Emulation.textile @@ -0,0 +1,160 @@ += Emulation Setup = + +As a lot of people discussed about simulating mesh network protocols, i'd like to share my qemu setup which i used to gather some data for batman-adv. The idea is to use [http://www.qemu.org/ QEMU] or [http://user-mode-linux.sourceforge.net/ UML] (instead of frameworks like they exist for [http://www.isi.edu/nsnam/ns/ NS-2]) to run an unmodified linux system with the unmodified source code. Besides BATMAN, you could evaluate any routing protocol. + +== Architecture == + +My system consists of the following components: + + * OpenWRT, kamikaze trunk version for x86 with minimal modifications (see below) + * one (unmodified) QEMU instance per host + * one (modified, see below) vde_switch per instance. You need multiple instances to allow interconnection with wirefilter + * one (unmodified) wirefilter per link between host. + +=== OpenWRT === + +OpenWRT has been used for this test. Some packages (tcpdump, netcat, batman-adv-kernelland...) were added and kernel commandline parameters were modified to make sure that qemu boots up properly: +{{{ +noapic acpi=off +}}} + +Furthermore, to allow automatic network device setup on boot i'm using the following script which is located in /etc/rc.local ( ./files/etc/rc.local in OpenWRT build directory): + +{{{ +#!/bin/sh + +# kill default openwrt network config + +NUM=$(ifconfig eth0| grep HWaddr | sed 's/:01[\n\ ]*$//' | sed 's/.*://'| sed 's/[\n\ ].*//') +ifconfig eth1 inet 192.168.${NUM}.2 up +ifconfig br-lan down +brctl delbr br-lan + +# set up log server + +cat << EOF > /tmp/logserver.sh +#!/bin/sh +while [ 1 ]; do + nc -l -p 2050 < /proc/net/batman-adv/log +done +EOF +chmod 755 /tmp/logserver.sh +/tmp/logserver.sh& + +# setup batman +ifconfig eth0 up +echo "" > /proc/net/batman-adv/interfaces +echo eth0 > /proc/net/batman-adv/interfaces +echo 15 > /proc/net/batman-adv/log_level +ifconfig bat0 inet 192.168.0.${NUM} up +}}} + +The script above is far from perfect, it takes some minutes after the rc.local file is finally started. Suggestions welcome. + +A sample openwrt image can be found here: + + * TODO + +=== vde_switch === + +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, i've modified the vde_switch 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 as the incoming port. + +In this concept, the host port can have colour 1 while the interconnection ports have to colour 0. 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 the interconnection ports, thus only allowing "one hop" connections and avoiding switch loops and shared broadcast domains. The concept is illustrated below: + + * TODO + +You can find the patch to add these colour patches here: + + * TODO + +=== wirefilter === + +wirefilter is a tool where you can simulate various link defects and limits: + + * packet loss + * burst loss + * delay + * duplicates + * bandwidth + * noise (damage to packets) + * mtu + * ... + +However as the links are only set up bidirectional, interferences can unfortunately not be simulated with this system. + +== Scripts == + +The following script is used to start up all the qemus. It is a good idea to start the script inside a screen to have the QEMU instances in screen windows (which can be switch with ctrl+a n, ctrl+a p). Make sure that you have the correct sudo priveleges or alternatively run this script as root. + +The script does: + * kill old instances + * start up vde_switch instances for each host + * start up QEMU hosts (one Ethernet tap device is created per instance to allow logging etc) + * install the links between the hosts. The topology graphic can be found here: TODO + +{{{ +#!/bin/sh +QEMU=$(which qemu) +VDESWITCH=/home/dotslash/src/vde2-2.2.3/src/vde_switch/vde_switch +IMAGE=/home/dotslash/src/openwrt2/kamikaze/bin/openwrt-x86-jffs2-128k.image + +# you can set this if you are running as root and don't need sudo: +# SUDO= +SUDO=sudo + +${SUDO} killall -q qemu +killall -q wirefilter +killall -q vde_switch + +for i in $(seq 1 9); +do + ${VDESWITCH} \ + -d --hub --sock num${i}.ctl -f colourful.rc +done + +for i in $(seq 1 9); +do + + cp ${IMAGE} num${i}.image + screen ${SUDO} ${QEMU} \ + -no-acpi -m 32M \ + -net vde,sock=num${i}.ctl,port=1 -net nic,macaddr=fe:fe:00:00:$(printf %2502x $i):01 \ + -net nic -net tap,ifname=tapwrt${i} \ + -nographic num${i}.image + sleep 3 + ${SUDO} /sbin/ifconfig tapwrt${i} inet 192.168.${i}.1 up +done + +wirefilter --daemon -v num1.ctl:num2.ctl +wirefilter --daemon -v num2.ctl:num3.ctl +wirefilter --daemon -v num3.ctl:num4.ctl +wirefilter --daemon -v num4.ctl:num5.ctl +wirefilter --daemon -v num5.ctl:num6.ctl +wirefilter --daemon -v num6.ctl:num7.ctl +wirefilter --daemon -v num7.ctl:num8.ctl +wirefilter --daemon -v num8.ctl:num9.ctl + +wirefilter --daemon -v num1.ctl:num3.ctl -l 60 +wirefilter --daemon -v num3.ctl:num5.ctl -l 60 +wirefilter --daemon -v num5.ctl:num7.ctl -l 60 +wirefilter --daemon -v num7.ctl:num9.ctl -l 60 +wirefilter --daemon -v num2.ctl:num4.ctl -l 60 +wirefilter --daemon -v num4.ctl:num6.ctl -l 60 +wirefilter --daemon -v num6.ctl:num8.ctl -l 60 +}}} + +To collect the batman logs from the individual hosts, you might want to use this script after all nodes have completed booting and started batman: + +{{{ +#!/bin/sh +for i in $(seq 1 9) +do + nc 192.168.${i}.2 2050 > num$i.log & +done +}}} \ No newline at end of file