1#!/bin/bash 2# run multiple mesh nodes in a linear topology 3# each node is in the same coverage area, so 4# total throughput is divided by n. 5 6num_nodes=${1:-4} 7daemon=${2:-iw} 8 9session=wmediumd 10subnet=10.10.10 11macfmt='02:00:00:00:%02x:00' 12 13. func 14 15if [[ $UID -ne 0 ]]; then 16 echo "Sorry, run me as root." 17 exit 1 18fi 19 20modprobe -r mac80211_hwsim 21modprobe mac80211_hwsim radios=$num_nodes 22 23for i in `seq 0 $((num_nodes-1))`; do 24 addrs[$i]=`printf $macfmt $i` 25done 26 27echo "ifaces: { count = $num_nodes; ids = [" > linear.cfg 28for addr in "${addrs[@]}"; do 29 echo -n '"'$addr'"' >> linear.cfg 30 if [[ $addr != ${addrs[$((num_nodes-1))]} ]]; then 31 echo ", " >> linear.cfg 32 fi 33done 34echo "]; }" >> linear.cfg 35 36tmux new -s $session -d 37 38rm /tmp/netns.pid.* 2>/dev/null 39i=0 40for addr in ${addrs[@]}; do 41 phy=`addr2phy $addr` 42 dev=`ls /sys/class/ieee80211/$phy/device/net` 43 phys[$i]=$phy 44 devs[$i]=$dev 45 46 ip=${subnet}.$((10 + i)) 47 48 # put this phy in own netns and tmux window, and start a mesh node 49 win=$session:$((i+1)).0 50 tmux new-window -t $session -n $ip 51 52 # start netns 53 pidfile=/tmp/netns.pid.$i 54 tmux send-keys -t $win 'lxc-unshare -s NETWORK /bin/bash' C-m 55 tmux send-keys -t $win 'echo $$ > '$pidfile C-m 56 57 # wait for netns to exist 58 while [[ ! -e $pidfile ]]; do 59 echo "Waiting for netns $i -- $pidfile" 60 sleep 0.5 61 done 62 63 tmux send-keys -t $session:0.0 'iw phy '$phy' set netns `cat '$pidfile'`' C-m 64 65 # wait for phy to exist in netns 66 while [[ -e /sys/class/ieee80211/$phy ]]; do 67 echo "Waiting for $phy to move to netns..." 68 sleep 0.5 69 done 70 71 # start mesh node 72 tmux send-keys -t $win '. func' C-m 73 tmux send-keys -t $win 'meshup-'$daemon ' ' $dev' linear 2412 '$ip C-m 74 75 i=$((i+1)) 76done 77winct=$i 78 79# wait a few beacon periods for everyone to discover each other 80sleep 3 81 82# force a linear topology 83for i in `seq 0 $((${#addrs[@]} - 1))`; do 84 win=$session:$((i+1)).0 85 addr=${addrs[$i]} 86 dev=${devs[$i]} 87 88 for j in `seq 0 $((${#addrs[@]} - 1))`; do 89 oaddr=${addrs[$j]} 90 if [[ $j -lt $((i-1)) || $j -gt $((i+1)) ]]; then 91 tmux send-keys -t $win 'iw dev '$dev' station set '$oaddr' plink_action block' C-m 92 fi 93 done 94done 95 96# start wmediumd 97win=$session:$((winct+1)).0 98winct=$((winct+1)) 99tmux new-window -t $session -n wmediumd 100tmux send-keys -t $win '../wmediumd/wmediumd -c linear.cfg' C-m 101 102tmux attach 103