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