Repository : ssh://git@open-mesh.org/doc
On branches: backup-redmine/2019-11-07,master
commit 2a5b39bda04b37dc9d328e0f519039ab9dc5c602 Author: Sven Eckelmann sven@narfation.org Date: Sun Oct 27 13:09:14 2019 +0000
doc: open-mesh/OpenWrt_in_QEMU
2a5b39bda04b37dc9d328e0f519039ab9dc5c602 open-mesh/OpenWrt_in_QEMU.textile | 116 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+)
diff --git a/open-mesh/OpenWrt_in_QEMU.textile b/open-mesh/OpenWrt_in_QEMU.textile new file mode 100644 index 0000000..637ce82 --- /dev/null +++ b/open-mesh/OpenWrt_in_QEMU.textile @@ -0,0 +1,116 @@ +h1. OpenWrt in QEMU + +The [[open-mesh:Emulation_Environment#Architecture]] + +h2. Start of the simple environment + +The two node environment must be started inside a screen session. The hub (bridge with 5 tap devices) has to be started first to have a simple network. A more complex network setup can be on the page [[vde switch interconnect]] and [[bridge interconnect]] + +<pre> +cat > hub.sh << "EOF" +#! /bin/sh + +USER="$(whoami)" +BRIDGE=br-qemu +NUM_SESSIONS=3 + +sudo ip link add "${BRIDGE}" type bridge +for i in $(seq 1 "${NUM_SESSIONS}")`; do + sudo ip tuntap add dev tap$i mode tap user "$USER" + sudo ip link set tap$i up + sudo ip link set tap$i master "${BRIDGE}" +done + +sudo ip link set "${BRIDGE}" up +sudo ip addr replace 192.168.251.1/24 dev "${BRIDGE}" +EOF + +chmod +x hub.sh +</pre> + +The @SHARED_PATH@ in run.sh has to be changed to a valid path which is used to share the precompiled batman-adv.ko and other tools + +<pre> +cat > run.sh << "EOF" +#! /bin/bash + +BOOTARGS=() + +if [ -z "${STY}" ]; then + echo "must be started inside a screen session" >&2 + exit 1 +fi + +SHARED_PATH="$(pwd)" +NUM_SESSIONS=3 + +## OpenWrt in QEMU +BASE_IMG=openwrt-x86-64-combined-ext4.img + +## Kernel hacking Debian image +#BASE_IMG=debian.img +#BOOTARGS+=("-kernel" "linux-next/arch/x86/boot/bzImage") +#BOOTARGS+=("-append" "root=/dev/vda rw console=ttyS0 nokaslr") + +for i in $(seq 1 "${NUM_SESSIONS}"); do + if [ ! -e "/sys/class/net/tap${i}" ]; then + echo "hub script must be started first to create tap$i interface" >&2 + exit 1 + fi +done + +for i in $(seq 1 "${NUM_SESSIONS}"); do + normalized_id="$(echo "$i"|awk '{ printf "%02d\n",$1 }')" + twodigit_id="$(echo $i|awk '{ printf "%02X", $1 }')" + + qemu-img create -b "${BASE_IMG}" -f qcow2 root.cow$i + screen qemu-system-x86_64 -enable-kvm -name "instance${i}" \ + "${BOOTARGS[@]}" \ + -display none -no-user-config -nodefaults \ + -m 512 -device virtio-balloon \ + -cpu host -smp 2 -machine q35,accel=kvm,usb=off,dump-guest-core=off \ + -drive file=root.cow$i,if=virtio,cache=unsafe \ + -nic tap,ifname=tap$i,script=no,model=virtio-net-pci,mac=02:ba:de:af:fe:"${twodigit_id}" \ + -nic user,model=virtio-net-pci,mac=06:ba:de:af:fe:"${twodigit_id}" \ + -virtfs local,path="${SHARED_PATH}",security_model=none,mount_tag=host \ + -gdb tcp:127.0.0.1:$((23000+$i)) \ + -device virtio-rng-pci \ + -serial mon:stdio + sleep 1 +done +EOF + +chmod +x run.sh +</pre> + +The test-init.sh script can be used to automatically initialize the test setup during boot: + +<pre> +cat > test-init.sh << "EOF" +#! /bin/sh + +set -e + +## Simple batman-adv setup + +rmmod batman-adv || true +modprobe batman-adv +batctl routing_algo BATMAN_IV +batctl if add dummy0 +batctl it 5000 +batctl if add eth0 +ip link set up dev eth0 +ip link set up dev bat0 +EOF + +chmod +x test-init.sh +</pre> + + +Everything can then be started up inside a screen session + +<pre> +screen +./hub.sh +./run.sh +</pre> \ No newline at end of file