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