1#!/bin/bash 2# 3 mesh nodes in a linear topology 3# 4 additional mesh nodes exists to prevent transmission 4# When enable_interference=true, ping always fails. 5# (This test is not perfect because of random values) 6 7num_nodes=7 8session=wmediumd 9subnet=10.10.10 10macfmt='02:00:00:00:%02x:00' 11 12. func 13 14if [[ $UID -ne 0 ]]; then 15 echo "Sorry, run me as root." 16 exit 1 17fi 18 19modprobe -r mac80211_hwsim 20modprobe mac80211_hwsim radios=$num_nodes 21iw reg set US 22 23for i in `seq 0 $((num_nodes-1))`; do 24 addrs[$i]=`printf $macfmt $i` 25done 26 27cat <<__EOM > diamond.cfg 28ifaces : 29{ 30 ids = [ 31 "02:00:00:00:00:00", 32 "02:00:00:00:01:00", 33 "02:00:00:00:02:00", 34 "02:00:00:00:03:00", 35 "02:00:00:00:04:00", 36 "02:00:00:00:05:00", 37 "02:00:00:00:06:00" 38 ]; 39 enable_interference = true; 40}; 41 42model : 43{ 44 band = 2; 45 type = "path_loss"; 46 positions = ( 47 (-69.0, 0.0), 48 ( 0.0, 0.0), 49 ( 69.0, 0.0), 50 (130.0, -2.0), 51 (130.0, -1.0), 52 (130.0, 2.0), 53 (130.0, 1.0) 54 ); 55 tx_powers = (15.0, 15.0, 15.0, 11.0, 11.0, 11.0, 11.0); 56 57 model_name = "log_distance"; 58 path_loss_exp = 3.5; 59 xg = 0.0; 60}; 61__EOM 62 63tmux new -s $session -d 64 65rm /tmp/netns.pid.* 2>/dev/null 66i=0 67for addr in ${addrs[@]}; do 68 phy=`addr2phy $addr` 69 dev=`ls /sys/class/ieee80211/$phy/device/net` 70 phys[$i]=$phy 71 devs[$i]=$dev 72 73 ip=${subnet}.$((10 + i)) 74 75 # put this phy in own netns and tmux window, and start a mesh node 76 win=$session:$((i+1)).0 77 tmux new-window -t $session -n $ip 78 79 # start netns 80 pidfile=/tmp/netns.pid.$i 81 tmux send-keys -t $win 'lxc-unshare -s NETWORK /bin/bash' C-m 82 tmux send-keys -t $win 'echo $$ > '$pidfile C-m 83 84 # wait for netns to exist 85 while [[ ! -e $pidfile ]]; do 86 echo "Waiting for netns $i -- $pidfile" 87 sleep 0.5 88 done 89 90 tmux send-keys -t $session:0.0 'iw phy '$phy' set netns `cat '$pidfile'`' C-m 91 92 # wait for phy to exist in netns 93 while [[ -e /sys/class/ieee80211/$phy ]]; do 94 echo "Waiting for $phy to move to netns..." 95 sleep 0.5 96 done 97 98 # start mesh node 99 tmux send-keys -t $win '. func' C-m 100 tmux send-keys -t $win 'meshup-iw '$dev' diamond 2412 '$ip C-m 101 102 i=$((i+1)) 103done 104winct=$i 105 106# start wmediumd 107win=$session:$((winct+1)).0 108winct=$((winct+1)) 109tmux new-window -a -t $session -n wmediumd 110tmux send-keys -t $win '../wmediumd/wmediumd -c diamond.cfg' C-m 111 112# start iperf server on 10.10.10.14 113tmux send-keys -t $session:5 'iperf -s' C-m 114# start iperf server on 10.10.10.16 115tmux send-keys -t $session:7 'iperf -s' C-m 116 117# enable monitor 118tmux send-keys -t $session:0 'ip link set hwsim0 up' C-m 119 120tmux send-keys -t $session:4 'iperf -u -b 100M -c 10.10.10.14 -t 10' C-m 121tmux send-keys -t $session:6 'iperf -u -b 100M -c 10.10.10.16 -t 10' C-m 122 123tmux select-window -t $session:1 124tmux send-keys -t $session:1 'sleep 2; ping -c 5 -W 1 10.10.10.12' C-m 125 126tmux attach 127