blob: 1d78db5f36e1727a7e9944b9265595099a4d6671 [file] [log] [blame]
Neels Hofmeyr697a6172018-08-22 17:32:21 +02001#!/usr/bin/env bash
Oliver Smith24ddf9c2019-01-30 16:48:18 +01002
Oliver Smithcd472bd2022-01-17 15:59:31 +01003# tmux: start this script inside a new session
4tmux_session="CN"
5if [ "${TERMINAL}" = "tmux" ] && [ "$1" != "inside-tmux" ]; then
6 echo "Starting tmux session '$tmux_session'"
7 unset TMUX
8 exec tmux new-session -s "$tmux_session" -n "RUN" "$0" "inside-tmux"
9fi
10
Oliver Smith24ddf9c2019-01-30 16:48:18 +010011if ! ../fill_config.py --check-stale; then
12 echo
13 echo "WARNING: STALE CONFIGS - your net configs are older than the templates they should be based on!"
14 echo " * Hit enter to continue, and use the stale config files"
15 echo " * Hit ^C and run 'make regen' to regenerate your configs"
16 read enter_to_continue
17fi
Neels Hofmeyr697a6172018-08-22 17:32:21 +020018
19dev="${ETH_DEV}"
Neels Hofmeyr697a6172018-08-22 17:32:21 +020020apn="${APN_DEV}"
21
22sudo true || exit 1
23
Oliver Smith4186b952021-07-07 16:40:36 +020024if ! sudo iptables -t nat -C POSTROUTING -s ${GGSN_NET} -o $dev -j MASQUERADE 2>/dev/null; then
25 echo "Adding iptables rule for masquerade"
26 sudo iptables -t nat -I POSTROUTING -s ${GGSN_NET} -o $dev -j MASQUERADE
Neels Hofmeyr697a6172018-08-22 17:32:21 +020027fi
28
29if [ "$(sudo cat /proc/sys/net/ipv4/ip_forward)" = "0" ]; then
30 sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
31fi
32
33if [ -z "$(ip tuntap show | grep $apn)" ]; then
34 sudo ip tuntap add dev $apn mode tun user $USER group $USER
35 sudo ip addr add ${GGSN_NET} dev $apn
36 sudo ip link set $apn up
37fi
38
Oliver Smith2490f692019-03-13 15:16:16 +010039if [ -z "$(ip addr show | grep "${TO_RAN_IP}")" ]; then
40 echo "No interface has IP address ${TO_RAN_IP}! Hit enter to continue anyway."
Neels Hofmeyrede80162018-09-16 13:49:13 +020041 read enter_to_continue
42fi
Oliver Smith2490f692019-03-13 15:16:16 +010043if [ -z "$(ip addr show | grep "${TO_RAN_IU_IP}")" ]; then
44 echo "No interface has IP address ${TO_RAN_IU_IP}! Hit enter to 'ip addr add ${TO_RAN_IU_IP}/32 dev $dev'"
Neels Hofmeyrede80162018-09-16 13:49:13 +020045 read enter_to_continue
Oliver Smith2490f692019-03-13 15:16:16 +010046 sudo ip addr add ${TO_RAN_IU_IP}/32 dev $dev
Neels Hofmeyr697a6172018-08-22 17:32:21 +020047fi
48
49logdir="current_log"
Oliver Smith669f1db2022-01-17 15:59:24 +010050piddir="run/pids"
Oliver Smith63273712022-01-18 11:21:37 +010051launcherdir="run/launchers"
52rm -rf "$launcherdir"
53mkdir -p "$logdir" "$piddir" "$launcherdir"
Neels Hofmeyr697a6172018-08-22 17:32:21 +020054
Oliver Smith4d7072c2018-09-28 11:30:46 +020055find_term() {
56 # Find a terminal program and write to the global "terminal" variable
Oliver Smithcd472bd2022-01-17 15:59:31 +010057 local programs="urxvt xterm tmux"
Oliver Smith4d7072c2018-09-28 11:30:46 +020058
Oliver Smithb28a9102022-01-17 15:59:02 +010059 if [ -z "${TERMINAL}" ]; then
60 echo "ERROR: TERMINAL is not defined in your osmo-dev net config file. Please add it."
61 exit 1
62 fi
63
64 case " $programs " in
65 *" ${TERMINAL} "*)
66 terminal="${TERMINAL}"
67
68 if command -v "$terminal" >/dev/null; then
69 echo "Terminal: ${TERMINAL}"
70 return
71 fi
72
73 echo "ERROR: Terminal '${TERMINAL}' is configured, but not installed"
74 exit 1
75 ;;
76 esac
77
78 echo "ERROR: Terminal '${TERMINAL}' is not in list of supported terminals ($programs)"
Oliver Smith4d7072c2018-09-28 11:30:46 +020079 exit 1
80}
81
Oliver Smith669f1db2022-01-17 15:59:24 +010082pidfiles_must_not_exist() {
83 local pidfile
84
85 for pidfile in "$@"; do
86 if [ -e "$pidfile" ]; then
87 echo
88 echo "ERROR: pidfile exists: $pidfile"
89 echo
90 kill_pids
91 exit 1
92 fi
93 done
94}
95
Neels Hofmeyr697a6172018-08-22 17:32:21 +020096term() {
97 title="$2"
98 if [ -z "$title" ]; then
99 title="$(basename $@)"
100 fi
Oliver Smith669f1db2022-01-17 15:59:24 +0100101
102 local pidfile="$piddir/$title.pid"
103 local pidfile_term="$piddir/$title.term.pid"
104 pidfiles_must_not_exist "$pidfile" "$pidfile_term"
105
Oliver Smith63273712022-01-18 11:21:37 +0100106 local launcher="$launcherdir/$title.sh"
107
108 cat << EOF > "$launcher"
109#!/bin/sh
110
111export LD_LIBRARY_PATH='/usr/local/lib'
112
113$1 &
114echo \$! > $pidfile
115wait
116
117echo
118
119while true; do
120 echo 'q Enter to close'
121 read q_to_close
122 if [ "x\$q_to_close" = xq ]; then
123 break
124 fi
125done
126EOF
127 chmod +x "$launcher"
128
Oliver Smithcd472bd2022-01-17 15:59:31 +0100129 case "$terminal" in
130 tmux)
131 tmux new-window -d -n "$title" "$launcher &; echo \$! > $pidfile_term; fg; wait"
132 ;;
133 *)
134 $terminal \
135 -title "CN:$title" \
136 -e sh -c "$launcher" \
137 &
Oliver Smith669f1db2022-01-17 15:59:24 +0100138
Oliver Smithcd472bd2022-01-17 15:59:31 +0100139 echo "$!" > "$pidfile_term"
140 ;;
141 esac
Oliver Smith669f1db2022-01-17 15:59:24 +0100142}
143
144kill_pids() {
145 local pidfile
146 local pid
147
148 for pidfile in "$piddir"/*.pid; do
149 if ! [ -e "$pidfile" ]; then
150 continue
151 fi
152
153 pid="$(cat "$pidfile")"
154
155 echo "killing $(basename "$pidfile") ($pid)"
156 sudo kill "$pid"
157 rm "$pidfile"
158 done
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200159}
160
Oliver Smith4d7072c2018-09-28 11:30:46 +0200161find_term
Oliver Smith669f1db2022-01-17 15:59:24 +0100162kill_pids
Oliver Smith4d7072c2018-09-28 11:30:46 +0200163
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200164hnbgw="osmo-hnbgw"
165msc="gdb -ex run --args $(which osmo-msc)"
Neels Hofmeyr8e494842019-08-07 01:35:06 +0200166# To enable udtrace on osmo-msc MNCC socket, use this with adjusted /path/to/udtrace:
167# - LD_LIBRARY_PATH allows linking to titan if udtrace was compiled with titan support.
168# - LD_PRELOAD of libasan allows building osmo-msc with the sanitize.opts.
169# - the tee saves the stderr logging as well as the udtrace output to new file current_log/osmo-msc.out, since udtrace
170# will not show in osmo-msc.log
171#msc="LD_LIBRARY_PATH=/usr/lib/titan LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.5:/path/to/udtrace/libudtrace.so osmo-msc 2>&1 | tee -a current_log/osmo-msc.out"
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200172gbproxy="osmo-gbproxy"
173sgsn="osmo-sgsn"
174ggsn="osmo-ggsn"
175mgw4msc="osmo-mgw -c osmo-mgw-for-msc.cfg"
176#mgw4bsc="gdb -ex run --args osmo-mgw -c osmo-mgw-for-bsc.cfg"
177#mgw4bsc="strace osmo-mgw -c osmo-mgw-for-bsc.cfg"
178mgw4bsc="osmo-mgw -c osmo-mgw-for-bsc.cfg"
Oliver Smith5467ef92018-12-13 13:27:37 +0100179hlr="LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-hlr --db-upgrade"
Oliver Smitha3a1a0d2021-12-14 16:27:10 +0100180stp4cn="osmo-stp -c osmo-stp-cn.cfg"
181stp4ran="osmo-stp -c osmo-stp-ran.cfg"
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200182bsc="LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-bsc -c osmo-bsc.cfg"
Oliver Smitha3a1a0d2021-12-14 16:27:10 +0100183bscnat="osmo-bsc-nat"
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200184
Neels Hofmeyrcbdd7182019-03-04 00:39:32 +0100185if [ "x${MSC_MNCC}" != "xinternal" ]; then
Oliver Smithd9f3d342018-09-26 16:29:00 +0200186 sipcon="osmo-sip-connector -c osmo-sip-connector.cfg"
Oliver Smithd9f3d342018-09-26 16:29:00 +0200187
Neels Hofmeyrba0a8282019-12-04 03:57:56 +0100188 case "${PBX_SERVER}" in
Oliver Smith667f19b2019-11-08 18:16:30 +0100189 "kamailio")
190 # Require kamailio (PATH hack is needed for Debian)
191 kamailio="$(PATH="$PATH:/usr/sbin:/sbin" which kamailio)"
192 if [ -z "$kamailio" ]; then
193 echo "ERROR: kamailio is not installed."
194 echo "After installing it, make sure that it does *not* run as daemon."
195 exit 1
196 fi
197 kamailio="$kamailio -f kamailio.cfg -D -e -E"
198 ;;
199 "freeswitch")
200 if [ -z "$(which freeswitch)" ]; then
201 echo "ERROR: freeswitch is not installed."
202 echo "Guide: https://freeswitch.org/confluence/display/FREESWITCH/Debian+10+Buster"
203 echo "After installing it, make sure that it does *not* run as daemon."
204 exit 1
205 fi
206 ;;
207 "none")
208 ;;
209 *)
Neels Hofmeyrba0a8282019-12-04 03:57:56 +0100210 echo "ERROR: unknown value ${PBX_SERVER} for SIPCON_SERVER!"
Oliver Smith667f19b2019-11-08 18:16:30 +0100211 exit 1
212 ;;
213 esac
Oliver Smithd9f3d342018-09-26 16:29:00 +0200214fi
215
Oliver Smith669f1db2022-01-17 15:59:24 +0100216PIDFILE_TCPDUMP_DEV="$piddir/tcpdump.$dev.pid"
217PIDFILE_TCPDUMP_LO="$piddir/tcpdump.lo.pid"
218pidfiles_must_not_exist "$PIDFILE_TCPDUMP_DEV" "$PIDFILE_TCPDUMP_LO"
219
Oliver Smithd9f3d342018-09-26 16:29:00 +0200220sudo tcpdump -i $dev -n -w current_log/$dev.single.pcap -U not port 22 &
Oliver Smith669f1db2022-01-17 15:59:24 +0100221echo "$!" > "$PIDFILE_TCPDUMP_DEV"
Oliver Smithd9f3d342018-09-26 16:29:00 +0200222sudo tcpdump -i lo -n -w current_log/lo.single.pcap -U not port 22 &
Oliver Smith669f1db2022-01-17 15:59:24 +0100223echo "$!" > "$PIDFILE_TCPDUMP_LO"
Oliver Smithd9f3d342018-09-26 16:29:00 +0200224
Oliver Smith669f1db2022-01-17 15:59:24 +0100225term "$ggsn" GGSN
Oliver Smith8fd50982021-12-14 18:12:54 +0100226
Oliver Smitha3a1a0d2021-12-14 16:27:10 +0100227if [ "${STP_CN_IP}" = "${STP_RAN_IP}" ]; then
228 sleep .2
Oliver Smith669f1db2022-01-17 15:59:24 +0100229 term "$stp4cn" STP
Oliver Smitha3a1a0d2021-12-14 16:27:10 +0100230else
231 sleep .2
Oliver Smith669f1db2022-01-17 15:59:24 +0100232 term "$stp4cn" STP4CN
Oliver Smitha3a1a0d2021-12-14 16:27:10 +0100233
234 sleep .2
Oliver Smith669f1db2022-01-17 15:59:24 +0100235 term "$stp4ran" STP4RAN
Oliver Smitha3a1a0d2021-12-14 16:27:10 +0100236
237 sleep .2
Oliver Smith669f1db2022-01-17 15:59:24 +0100238 term "$bscnat" BSCNAT
Oliver Smitha3a1a0d2021-12-14 16:27:10 +0100239fi
Oliver Smith8fd50982021-12-14 18:12:54 +0100240
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200241sleep .2
Oliver Smith669f1db2022-01-17 15:59:24 +0100242term "$hlr" HLR
Oliver Smith8fd50982021-12-14 18:12:54 +0100243
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200244sleep .2
Oliver Smith669f1db2022-01-17 15:59:24 +0100245term "$sgsn" SGSN
Oliver Smith8fd50982021-12-14 18:12:54 +0100246
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200247sleep .2
Oliver Smith669f1db2022-01-17 15:59:24 +0100248term "$gbproxy" GBPROXY
Oliver Smith8fd50982021-12-14 18:12:54 +0100249
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200250sleep .2
Oliver Smith669f1db2022-01-17 15:59:24 +0100251term "$mgw4msc" MGW4MSC
Oliver Smith8fd50982021-12-14 18:12:54 +0100252
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200253sleep .2
Oliver Smith669f1db2022-01-17 15:59:24 +0100254term "$mgw4bsc" MGW4BSC
Oliver Smith8fd50982021-12-14 18:12:54 +0100255
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200256sleep .2
Oliver Smith669f1db2022-01-17 15:59:24 +0100257term "$msc" MSC
Oliver Smith8fd50982021-12-14 18:12:54 +0100258
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200259sleep 2
Oliver Smith669f1db2022-01-17 15:59:24 +0100260term "$hnbgw" HNBGW
Oliver Smith8fd50982021-12-14 18:12:54 +0100261
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200262sleep .2
Oliver Smith669f1db2022-01-17 15:59:24 +0100263term "$bsc" BSC
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200264
Neels Hofmeyrcbdd7182019-03-04 00:39:32 +0100265if [ "x${MSC_MNCC}" != "xinternal" ]; then
Oliver Smithd9f3d342018-09-26 16:29:00 +0200266 sleep .2
Oliver Smith669f1db2022-01-17 15:59:24 +0100267 term "$sipcon" SIPCON
Oliver Smith8fd50982021-12-14 18:12:54 +0100268
Oliver Smithd9f3d342018-09-26 16:29:00 +0200269 sleep .2
Neels Hofmeyrba0a8282019-12-04 03:57:56 +0100270 case "${PBX_SERVER}" in
Oliver Smith8fd50982021-12-14 18:12:54 +0100271 "kamailio")
Oliver Smith669f1db2022-01-17 15:59:24 +0100272 term "$kamailio" KAMAILIO
Oliver Smith8fd50982021-12-14 18:12:54 +0100273 ;;
274 "freeswitch")
Oliver Smith669f1db2022-01-17 15:59:24 +0100275 term "./freeswitch/freeswitch.sh" FREESWITCH
Oliver Smith8fd50982021-12-14 18:12:54 +0100276 ;;
Oliver Smith667f19b2019-11-08 18:16:30 +0100277 esac
Oliver Smithd9f3d342018-09-26 16:29:00 +0200278fi
279
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200280#ssh bts rm /tmp/bts.log /tmp/pcu.log
281#ssh bts neels/run_remote.sh &
282
283echo enter to close
284read enter_to_close
285echo Closing...
286
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200287#ssh bts neels/stop_remote.sh
288
Oliver Smith669f1db2022-01-17 15:59:24 +0100289kill_pids
Neels Hofmeyrfecf1562019-08-07 01:34:12 +0200290
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200291set +e
292cp *.cfg "$logdir"/
293
294echo
295echo enter name to save log
296read log_name
297if [ -n "$log_name" ]; then
298 newlogdir="log/$log_name"
299 #scp "bts:/tmp/{bts,pcu}.log" "bts:neels/osmo-{bts,pcu}.cfg" "$logdir"
300else
301 newlogdir="autolog/log_$(date +%Y-%m-%d_%H-%M-%S)"
302fi
303mkdir -p "$(dirname "$newlogdir")"
304
305mergecap -w "$logdir/trace.pcap" "$logdir/"*.single.pcap && rm -f "$logdir/"*.single.pcap
306
307if [ -x "$newlogdir" ]; then
308 echo "already exists, move it manually: $newlogdir"
309else
310 echo mv "$logdir" "$newlogdir"
311 mv "$logdir" "$newlogdir"
312 mkdir -p "$logdir"
313 logdir="$newlogdir"
314fi
315rm lastlog
316ln -s "$logdir" lastlog