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