blob: c2f42eed6ead06b93a701b5c74607e43846fa532 [file] [log] [blame]
Neels Hofmeyr697a6172018-08-22 17:32:21 +02001#!/usr/bin/env bash
Oliver Smith24ddf9c2019-01-30 16:48:18 +01002
3if ! ../fill_config.py --check-stale; then
4 echo
5 echo "WARNING: STALE CONFIGS - your net configs are older than the templates they should be based on!"
6 echo " * Hit enter to continue, and use the stale config files"
7 echo " * Hit ^C and run 'make regen' to regenerate your configs"
8 read enter_to_continue
9fi
Neels Hofmeyr697a6172018-08-22 17:32:21 +020010
11dev="${ETH_DEV}"
Neels Hofmeyr697a6172018-08-22 17:32:21 +020012apn="${APN_DEV}"
13
14sudo true || exit 1
15
Oliver Smith4186b952021-07-07 16:40:36 +020016if ! sudo iptables -t nat -C POSTROUTING -s ${GGSN_NET} -o $dev -j MASQUERADE 2>/dev/null; then
17 echo "Adding iptables rule for masquerade"
18 sudo iptables -t nat -I POSTROUTING -s ${GGSN_NET} -o $dev -j MASQUERADE
Neels Hofmeyr697a6172018-08-22 17:32:21 +020019fi
20
21if [ "$(sudo cat /proc/sys/net/ipv4/ip_forward)" = "0" ]; then
22 sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
23fi
24
25if [ -z "$(ip tuntap show | grep $apn)" ]; then
26 sudo ip tuntap add dev $apn mode tun user $USER group $USER
27 sudo ip addr add ${GGSN_NET} dev $apn
28 sudo ip link set $apn up
29fi
30
Oliver Smith2490f692019-03-13 15:16:16 +010031if [ -z "$(ip addr show | grep "${TO_RAN_IP}")" ]; then
32 echo "No interface has IP address ${TO_RAN_IP}! Hit enter to continue anyway."
Neels Hofmeyrede80162018-09-16 13:49:13 +020033 read enter_to_continue
34fi
Oliver Smith2490f692019-03-13 15:16:16 +010035if [ -z "$(ip addr show | grep "${TO_RAN_IU_IP}")" ]; then
36 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 +020037 read enter_to_continue
Oliver Smith2490f692019-03-13 15:16:16 +010038 sudo ip addr add ${TO_RAN_IU_IP}/32 dev $dev
Neels Hofmeyr697a6172018-08-22 17:32:21 +020039fi
40
41logdir="current_log"
42mkdir -p "$logdir"
43
Oliver Smith4d7072c2018-09-28 11:30:46 +020044find_term() {
45 # Find a terminal program and write to the global "terminal" variable
46 local programs="urxvt xterm"
Oliver Smith4d7072c2018-09-28 11:30:46 +020047
Oliver Smithb28a9102022-01-17 15:59:02 +010048 if [ -z "${TERMINAL}" ]; then
49 echo "ERROR: TERMINAL is not defined in your osmo-dev net config file. Please add it."
50 exit 1
51 fi
52
53 case " $programs " in
54 *" ${TERMINAL} "*)
55 terminal="${TERMINAL}"
56
57 if command -v "$terminal" >/dev/null; then
58 echo "Terminal: ${TERMINAL}"
59 return
60 fi
61
62 echo "ERROR: Terminal '${TERMINAL}' is configured, but not installed"
63 exit 1
64 ;;
65 esac
66
67 echo "ERROR: Terminal '${TERMINAL}' is not in list of supported terminals ($programs)"
Oliver Smith4d7072c2018-09-28 11:30:46 +020068 exit 1
69}
70
Neels Hofmeyr697a6172018-08-22 17:32:21 +020071term() {
72 title="$2"
73 if [ -z "$title" ]; then
74 title="$(basename $@)"
75 fi
Neels Hofmeyr697a6172018-08-22 17:32:21 +020076 exec $terminal -title "CN:$title" -e sh -c "export LD_LIBRARY_PATH='/usr/local/lib'; $1; echo; while true; do echo 'q Enter to close'; read q_to_close; if [ \"x\$q_to_close\" = xq ]; then break; fi; done"
77}
78
Oliver Smith4d7072c2018-09-28 11:30:46 +020079find_term
80
Neels Hofmeyr697a6172018-08-22 17:32:21 +020081hnbgw="osmo-hnbgw"
82msc="gdb -ex run --args $(which osmo-msc)"
Neels Hofmeyr8e494842019-08-07 01:35:06 +020083# To enable udtrace on osmo-msc MNCC socket, use this with adjusted /path/to/udtrace:
84# - LD_LIBRARY_PATH allows linking to titan if udtrace was compiled with titan support.
85# - LD_PRELOAD of libasan allows building osmo-msc with the sanitize.opts.
86# - the tee saves the stderr logging as well as the udtrace output to new file current_log/osmo-msc.out, since udtrace
87# will not show in osmo-msc.log
88#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 +020089gbproxy="osmo-gbproxy"
90sgsn="osmo-sgsn"
91ggsn="osmo-ggsn"
92mgw4msc="osmo-mgw -c osmo-mgw-for-msc.cfg"
93#mgw4bsc="gdb -ex run --args osmo-mgw -c osmo-mgw-for-bsc.cfg"
94#mgw4bsc="strace osmo-mgw -c osmo-mgw-for-bsc.cfg"
95mgw4bsc="osmo-mgw -c osmo-mgw-for-bsc.cfg"
Oliver Smith5467ef92018-12-13 13:27:37 +010096hlr="LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-hlr --db-upgrade"
Oliver Smitha3a1a0d2021-12-14 16:27:10 +010097stp4cn="osmo-stp -c osmo-stp-cn.cfg"
98stp4ran="osmo-stp -c osmo-stp-ran.cfg"
Neels Hofmeyr697a6172018-08-22 17:32:21 +020099bsc="LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-bsc -c osmo-bsc.cfg"
Oliver Smitha3a1a0d2021-12-14 16:27:10 +0100100bscnat="osmo-bsc-nat"
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200101
Neels Hofmeyrcbdd7182019-03-04 00:39:32 +0100102if [ "x${MSC_MNCC}" != "xinternal" ]; then
Oliver Smithd9f3d342018-09-26 16:29:00 +0200103 sipcon="osmo-sip-connector -c osmo-sip-connector.cfg"
Oliver Smithd9f3d342018-09-26 16:29:00 +0200104
Neels Hofmeyrba0a8282019-12-04 03:57:56 +0100105 case "${PBX_SERVER}" in
Oliver Smith667f19b2019-11-08 18:16:30 +0100106 "kamailio")
107 # Require kamailio (PATH hack is needed for Debian)
108 kamailio="$(PATH="$PATH:/usr/sbin:/sbin" which kamailio)"
109 if [ -z "$kamailio" ]; then
110 echo "ERROR: kamailio is not installed."
111 echo "After installing it, make sure that it does *not* run as daemon."
112 exit 1
113 fi
114 kamailio="$kamailio -f kamailio.cfg -D -e -E"
115 ;;
116 "freeswitch")
117 if [ -z "$(which freeswitch)" ]; then
118 echo "ERROR: freeswitch is not installed."
119 echo "Guide: https://freeswitch.org/confluence/display/FREESWITCH/Debian+10+Buster"
120 echo "After installing it, make sure that it does *not* run as daemon."
121 exit 1
122 fi
123 ;;
124 "none")
125 ;;
126 *)
Neels Hofmeyrba0a8282019-12-04 03:57:56 +0100127 echo "ERROR: unknown value ${PBX_SERVER} for SIPCON_SERVER!"
Oliver Smith667f19b2019-11-08 18:16:30 +0100128 exit 1
129 ;;
130 esac
Oliver Smithd9f3d342018-09-26 16:29:00 +0200131fi
132
133sudo tcpdump -i $dev -n -w current_log/$dev.single.pcap -U not port 22 &
134sudo tcpdump -i lo -n -w current_log/lo.single.pcap -U not port 22 &
135
Oliver Smith8fd50982021-12-14 18:12:54 +0100136PIDS=""
137
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200138term "$ggsn" GGSN &
Oliver Smith8fd50982021-12-14 18:12:54 +0100139PIDS="$PIDS $!"
140
Oliver Smitha3a1a0d2021-12-14 16:27:10 +0100141if [ "${STP_CN_IP}" = "${STP_RAN_IP}" ]; then
142 sleep .2
143 term "$stp4cn" STP &
144 PIDS="$PIDS $!"
145else
146 sleep .2
147 term "$stp4cn" STP4CN &
148 PIDS="$PIDS $!"
149
150 sleep .2
151 term "$stp4ran" STP4RAN &
152 PIDS="$PIDS $!"
153
154 sleep .2
155 term "$bscnat" BSCNAT &
156 PIDS="$PIDS $!"
157fi
Oliver Smith8fd50982021-12-14 18:12:54 +0100158
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200159sleep .2
160term "$hlr" HLR &
Oliver Smith8fd50982021-12-14 18:12:54 +0100161PIDS="$PIDS $!"
162
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200163sleep .2
164term "$sgsn" SGSN &
Oliver Smith8fd50982021-12-14 18:12:54 +0100165PIDS="$PIDS $!"
166
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200167sleep .2
168term "$gbproxy" GBPROXY &
Oliver Smith8fd50982021-12-14 18:12:54 +0100169PIDS="$PIDS $!"
170
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200171sleep .2
172term "$mgw4msc" MGW4MSC &
Oliver Smith8fd50982021-12-14 18:12:54 +0100173PIDS="$PIDS $!"
174
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200175sleep .2
176term "$mgw4bsc" MGW4BSC &
Oliver Smith8fd50982021-12-14 18:12:54 +0100177PIDS="$PIDS $!"
178
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200179sleep .2
180term "$msc" MSC &
Oliver Smith8fd50982021-12-14 18:12:54 +0100181PIDS="$PIDS $!"
182
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200183sleep 2
184term "$hnbgw" HNBGW &
Oliver Smith8fd50982021-12-14 18:12:54 +0100185PIDS="$PIDS $!"
186
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200187sleep .2
188term "$bsc" BSC &
Oliver Smith8fd50982021-12-14 18:12:54 +0100189PIDS="$PIDS $!"
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200190
Neels Hofmeyrcbdd7182019-03-04 00:39:32 +0100191if [ "x${MSC_MNCC}" != "xinternal" ]; then
Oliver Smithd9f3d342018-09-26 16:29:00 +0200192 sleep .2
193 term "$sipcon" SIPCON &
Oliver Smith8fd50982021-12-14 18:12:54 +0100194 PIDS="$PIDS $!"
195
Oliver Smithd9f3d342018-09-26 16:29:00 +0200196 sleep .2
Neels Hofmeyrba0a8282019-12-04 03:57:56 +0100197 case "${PBX_SERVER}" in
Oliver Smith8fd50982021-12-14 18:12:54 +0100198 "kamailio")
199 term "$kamailio" KAMAILIO &
200 PIDS="$PIDS $!"
201 ;;
202 "freeswitch")
203 term "./freeswitch/freeswitch.sh" FREESWITCH &
204 PIDS="$PIDS $!"
205 ;;
Oliver Smith667f19b2019-11-08 18:16:30 +0100206 esac
Oliver Smithd9f3d342018-09-26 16:29:00 +0200207fi
208
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200209#ssh bts rm /tmp/bts.log /tmp/pcu.log
210#ssh bts neels/run_remote.sh &
211
212echo enter to close
213read enter_to_close
214echo Closing...
215
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200216#ssh bts neels/stop_remote.sh
217
Oliver Smith8fd50982021-12-14 18:12:54 +0100218for i in $PIDS; do
219 kill "$i"
220done
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200221killall osmo-msc
222killall osmo-bsc
223killall osmo-gbproxy
224killall osmo-sgsn
225#killall osmo-hnbgw
226killall osmo-mgw
227killall osmo-hlr
228killall -9 osmo-stp
229sudo killall tcpdump
230killall osmo-ggsn
Oliver Smitha3a1a0d2021-12-14 16:27:10 +0100231killall osmo-bsc-nat
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200232
Neels Hofmeyrfecf1562019-08-07 01:34:12 +0200233if [ "x${MSC_MNCC}" != "xinternal" ]; then
234 # 'killall' seems to work only with the shortened name
235 killall osmo-sip-connec
Neels Hofmeyrba0a8282019-12-04 03:57:56 +0100236 killall "${PBX_SERVER}"
Neels Hofmeyrfecf1562019-08-07 01:34:12 +0200237fi
238
239
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200240set +e
241cp *.cfg "$logdir"/
242
243echo
244echo enter name to save log
245read log_name
246if [ -n "$log_name" ]; then
247 newlogdir="log/$log_name"
248 #scp "bts:/tmp/{bts,pcu}.log" "bts:neels/osmo-{bts,pcu}.cfg" "$logdir"
249else
250 newlogdir="autolog/log_$(date +%Y-%m-%d_%H-%M-%S)"
251fi
252mkdir -p "$(dirname "$newlogdir")"
253
254mergecap -w "$logdir/trace.pcap" "$logdir/"*.single.pcap && rm -f "$logdir/"*.single.pcap
255
256if [ -x "$newlogdir" ]; then
257 echo "already exists, move it manually: $newlogdir"
258else
259 echo mv "$logdir" "$newlogdir"
260 mv "$logdir" "$newlogdir"
261 mkdir -p "$logdir"
262 logdir="$newlogdir"
263fi
264rm lastlog
265ln -s "$logdir" lastlog