1#!/bin/bash 2# 4 mesh nodes in a diamond topology 3# paths must go through one of two intermediate nodes. 4 5num_nodes=4 6session=wmediumd 7subnet=10.10.10 8macfmt='02:00:00:00:%02x:00' 9 10. func 11 12if [[ $UID -ne 0 ]]; then 13 echo "Sorry, run me as root." 14 exit 1 15fi 16 17modprobe -r mac80211_hwsim 18modprobe mac80211_hwsim radios=$num_nodes 19 20for i in `seq 0 $((num_nodes-1))`; do 21 addrs[$i]=`printf $macfmt $i` 22done 23 24cat <<__EOM > diamond.cfg 25ifaces : 26{ 27 ids = [ 28 "02:00:00:00:00:00", 29 "02:00:00:00:01:00", 30 "02:00:00:00:02:00", 31 "02:00:00:00:03:00" 32 ]; 33}; 34 35model: 36{ 37 type = "prob"; 38 39 default_prob = 1.0; 40 links = ( 41 (0, 2, 0.000000), 42 (2, 3, 0.000000) 43 ); 44}; 45__EOM 46 47tmux new -s $session -d 48 49rm /tmp/netns.pid.* 2>/dev/null 50i=0 51for addr in ${addrs[@]}; do 52 phy=`addr2phy $addr` 53 dev=`ls /sys/class/ieee80211/$phy/device/net` 54 phys[$i]=$phy 55 devs[$i]=$dev 56 57 ip=${subnet}.$((10 + i)) 58 59 # put this phy in own netns and tmux window, and start a mesh node 60 win=$session:$((i+1)).0 61 tmux new-window -t $session -n $ip 62 63 # start netns 64 pidfile=/tmp/netns.pid.$i 65 tmux send-keys -t $win 'lxc-unshare -s NETWORK /bin/bash' C-m 66 tmux send-keys -t $win 'echo $$ > '$pidfile C-m 67 68 # wait for netns to exist 69 while [[ ! -e $pidfile ]]; do 70 echo "Waiting for netns $i -- $pidfile" 71 sleep 0.5 72 done 73 74 tmux send-keys -t $session:0.0 'iw phy '$phy' set netns `cat '$pidfile'`' C-m 75 76 # wait for phy to exist in netns 77 while [[ -e /sys/class/ieee80211/$phy ]]; do 78 echo "Waiting for $phy to move to netns..." 79 sleep 0.5 80 done 81 82 # start mesh node 83 tmux send-keys -t $win '. func' C-m 84 tmux send-keys -t $win 'meshup-iw '$dev' diamond 2412 '$ip C-m 85 86 i=$((i+1)) 87done 88winct=$i 89 90# start wmediumd 91win=$session:$((winct+1)).0 92winct=$((winct+1)) 93tmux new-window -a -t $session -n wmediumd 94tmux send-keys -t $win '../wmediumd/wmediumd -c diamond.cfg' C-m 95 96# start iperf server on 10.10.10.13 97tmux send-keys -t $session:4 'iperf -s' C-m 98 99# enable monitor 100tmux send-keys -t $session:0 'ip link set hwsim0 up' C-m 101 102tmux select-window -t $session:1 103tmux send-keys -t $session:1 'ping -c 5 10.10.10.13' C-m 104tmux send-keys -t $session:1 'iperf -c 10.10.10.13 -i 5 -t 120' 105 106tmux attach 107