-
Notifications
You must be signed in to change notification settings - Fork 0
/
sun
executable file
·176 lines (155 loc) · 4.75 KB
/
sun
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/sh
VERSION=$(git describe --abbrev=7 --always --long --match v* master)
set -e
COMPOSE="docker-compose"
if ! command -v docker-compose %> /dev/null
then
echo "docker-compose not found, using 'docker compose'"
COMPOSE="docker compose"
fi
echo "SUN - Simulated UAV Network"
echo
help() {
echo "Usage: sun [command] [command options]"
echo "Commands:"
echo " run <scenario_dir> start simulation scenarion"
echo " stop stop (stale) simulation"
echo " new <scenario_name> create new scenario"
echo " build build all docker images"
echo " clear remove scenario results and temporary files"
echo " nsh <node_name> open shell for given node"
echo " version print version information"
echo " help print this help"
echo
echo "Nodes: uav|core|station|<coreemu virtual node name>"
}
scenario_new() {
if [ -d "scenarios/$1" ]; then
echo "Scenario $1 already exists"
exit 1
fi
echo "generating new scenario: $1"
mkdir -p scenarios/$1
cp -r templates/shared-TEMPLATE/* scenarios/$1
cat templates/shared-TEMPLATE/experiment.conf | sed -e "s/SCENARIONAME/$1/g" >scenarios/$1/experiment.conf
}
stop() {
echo "stopping simulation"
$COMPOSE down
}
build() {
echo "building images"
if [ ! -f "docker-compose.yml" ]; then
echo "no config found, generating one..."
cat templates/docker-compose.yml.TEMPLATE | sed -e 's/SHAREDDIR/.\/shared/g' >docker-compose.yml
fi
$COMPOSE build
}
clear() {
echo "clear scenarios"
sudo rm -rf shared/results-*
sudo rm -rf scenarios/*/results-*
sudo rm shared/experiment.log
sudo rm -rf scenarios/*/experiment.log
}
nsh() {
echo "opening shell for $1"
echo
if [ "$1" = "uav" ]; then
docker exec -it sun_uav_1 /bin/bash
elif [ "$1" = "core" ]; then
docker exec -it sun_core_1 /bin/bash
elif [ "$1" = "station" ]; then
docker exec -it sun_station_1 /bin/bash
else
docker exec -it sun_core_1 cbash $1
fi
}
run() {
echo "running scenario: $1"
cat templates/docker-compose.yml.TEMPLATE | sed -e "s+SHAREDDIR+./$1+g" >docker-compose.yml
$COMPOSE build
if [ -f "$1/env.conf" ]; then
echo "Loading environment variables from $1/env.conf"
set -o allexport
. $1/env.conf
set +o allexport
echo $PX4_HOME_LAT,$PX4_HOME_LON,$PX4_HOME_ALT
fi
$COMPOSE up -d --remove-orphans
sleep 5
# connect core gui: password netsim
#ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -Y -p 2022 root@localhost core-pygui -s 1 &
echo "ground station: vnc://127.0.0.1:15901"
echo "core network: vnc://127.0.0.1:15902"
echo "core network: ssh://root@127.0.0.1:2022"
sleep 2
#docker exec -it sun_core_1 core-cli query session -i 1
BASE_X=$(docker exec -it sun_core_1 core-pos uav0 | egrep -ex | awk '{print $2}' | sed 's/,*\r*$//')
BASE_Y=$(docker exec -it sun_core_1 core-pos uav0 | egrep -ey | awk '{print $2}' | sed 's/,*\r*$//')
echo "base xy: $BASE_X,$BASE_Y"
docker exec -it sun_core_1 core-cli node edit -i 4 -p $BASE_X,$BASE_Y -ic /root/.coregui/icons/uav.png
sleep 1
if [ -f "$1/px4-params.txt" ]; then
echo "Loading parameters from $1/px4-params.txt"
for i in $(cat $1/px4-params.txt | grep -v "^#" | grep "="); do
PARAM=$(echo $i | sed -e 's/=/ /g')
docker exec -it sun_uav_1 /root/PX4-Autopilot/build/px4_sitl_default/bin/px4-param set $PARAM
#echo $PARAM
sleep 1
done
else
echo "File $1/px4-params.txt not found, not setting extra PX4 parameters"
fi
if [ -f "$1/autostart.sh" ]; then
echo "Running $1/autostart.sh"
bash $1/autostart.sh
fi
set +e
docker exec -it sun_uav_1 python3 /usr/local/bin/gz_pose.py
# mutli node mesh setup: babeld -D -C 'redistribute metric 256' eth0
#tail -f /dev/null
set -e
$COMPOSE stop
$COMPOSE rm -f core
$COMPOSE rm -f uav
$COMPOSE rm -f station
}
# if no parameters given then print usage
if [ $# -eq 0 ]; then
help
exit 0
fi
if [ "$1" = "new" ]; then
if [ $# -ne 2 ]; then
help
exit 0
fi
scenario_new $2
elif [ "$1" = "run" ]; then
if [ $# -ne 2 ]; then
help
exit 0
fi
run $2
elif [ "$1" = "stop" ]; then
stop
elif [ "$1" = "build" ]; then
build
elif [ "$1" = "clear" ]; then
clear
elif [ "$1" = "nsh" ]; then
if [ $# -ne 2 ]; then
help
exit 0
fi
nsh $2
elif [ "$1" = "version" ]; then
echo "version: $VERSION"
elif [ "$1" = "help" ]; then
help
else
echo "unknown command"
echo
help
fi