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 links = ( 35 (0, 1, 10), 36 (0, 2, 20), 37 (0, 3, 0), 38 (1, 2, 30), 39 (1, 3, 10), 40 (2, 3, 20) 41 ); 42}; 43__EOM 44 45tmux new -s $session -d 46 47rm /tmp/netns.pid.* 2>/dev/null 48i=0 49for addr in ${addrs[@]}; do 50 phy=`addr2phy $addr` 51 dev=`ls /sys/class/ieee80211/$phy/device/net` 52 phys[$i]=$phy 53 devs[$i]=$dev 54 55 ip=${subnet}.$((10 + i)) 56 57 # put this phy in own netns and tmux window, and start a mesh node 58 win=$session:$((i+1)).0 59 tmux new-window -t $session -n $ip 60 61 # start netns 62 pidfile=/tmp/netns.pid.$i 63 tmux send-keys -t $win 'lxc-unshare -s NETWORK /bin/bash' C-m 64 tmux send-keys -t $win 'echo $$ > '$pidfile C-m 65 66 # wait for netns to exist 67 while [[ ! -e $pidfile ]]; do 68 echo "Waiting for netns $i -- $pidfile" 69 sleep 0.5 70 done 71 72 tmux send-keys -t $session:0.0 'iw phy '$phy' set netns `cat '$pidfile'`' C-m 73 74 # wait for phy to exist in netns 75 while [[ -e /sys/class/ieee80211/$phy ]]; do 76 echo "Waiting for $phy to move to netns..." 77 sleep 0.5 78 done 79 80 # start mesh node 81 tmux send-keys -t $win '. func' C-m 82 tmux send-keys -t $win 'meshup-iw '$dev' diamond 2412 '$ip C-m 83 84 i=$((i+1)) 85done 86winct=$i 87 88# start wmediumd 89win=$session:$((winct+1)).0 90winct=$((winct+1)) 91tmux new-window -a -t $session -n wmediumd 92tmux send-keys -t $win '../wmediumd/wmediumd -c diamond.cfg -x signal_table_ieee80211ax' C-m 93 94# start iperf server on 10.10.10.13 95tmux send-keys -t $session:4 'iperf -s' C-m 96 97# enable monitor 98tmux send-keys -t $session:0 'ip link set hwsim0 up' C-m 99 100tmux select-window -t $session:1 101tmux send-keys -t $session:1 'ping -c 5 10.10.10.13' C-m 102tmux send-keys -t $session:1 'iperf -c 10.10.10.13 -i 5 -t 120' 103 104tmux attach 105