-
Notifications
You must be signed in to change notification settings - Fork 34
Local testing
sarumpaet edited this page Nov 3, 2018
·
1 revision
#!/bin/bash
# This sets up a local Docker container running OpenWrt along with
# emulated Wifi devices.
# To build the OpenWrt image necessary before:
# make TARGET=x86-generic PACKAGES_LIST_DEFAULT=default
#TODO use https://github.com/bcopeland/wmediumd to simulate Wifi delay and loss?
set -o nounset
set -o errexit
#set -o verbose
#set -o xtrace
set +o histexpand
# create Docker image from x64 OpenWrt image
ls -lhat firmwares/x86-generic/default/freifunk-berlin-*-x86-generic-generic-rootfs.tar.gz|head --l 1
docker import $(ls -t firmwares/x86-generic/default/freifunk-berlin-*-x86-generic-generic-rootfs.tar.gz|head --l 1) ffberlin_image
# set up mac80211_hwsim on host to emulate wifi device
# take note of existing PHYs, then load mac80211_hwsim, then look at PHYs again; new PHYs are emulated ones
if lsmod | grep -q mac80211_hwsim ; then echo "Removing mac80211_hwsim module"; sudo modprobe -r mac80211_hwsim ; fi
iw phy|grep "Wiphy"|cut -d ' ' -f2|sort > /tmp/ffb_docker_phys.list
if ! lsmod | grep -q mac80211_hwsim ; then echo "Loading mac80211_hwsim module"; sudo modprobe mac80211_hwsim ; fi
HWSIMPHYS=$(iw phy|grep "Wiphy"|cut -d ' ' -f2|sort|grep -v -f /tmp/ffb_docker_phys.list)
#TODO better network setup
#if ! docker network list|grep -q ffdockernet ; then docker network create --driver=bridge --subnet=192.168.42.0/16 ffdockernet ; fi
#docker run --network=ffdockernet --ip=192.168.42.1
# create Docker container from image
if docker ps -a | grep -q ffberlin ; then docker rm -f ffberlin ; fi
docker run --name ffberlin --cap-add NET_ADMIN -d ffberlin_image /sbin/init
sleep 2
# move simulated wifi interfaces into container
DOCKERNS=$(docker inspect -f '{{.State.Pid}}' ffberlin)
for PHY in $HWSIMPHYS; do
echo "Moving $PHY into OpenWrt container"
sudo iw phy $PHY set netns $DOCKERNS
done
docker exec ffberlin wifi config
# output some notes
CONTAINERIP=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ffberlin)
echo "open in browser: http://$CONTAINERIP/"
echo "to open shell: docker exec -it ffberlin /bin/sh"
echo "to tear down container: docker rm -f ffberlin"
# set container LAN IP to Docker IP
sleep 10
docker exec -it ffberlin ifconfig br-lan $CONTAINERIP