blob: 0eacb0f07953d6d18a1913d588e91d5fcb885295 [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
16if [ -z "$(sudo iptables -L -t nat | grep MASQUERADE)" ]; then
17 sudo iptables -t nat -A POSTROUTING -s ${GGSN_NET} -o $dev -j MASQUERADE
18fi
19
20if [ "$(sudo cat /proc/sys/net/ipv4/ip_forward)" = "0" ]; then
21 sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
22fi
23
24if [ -z "$(ip tuntap show | grep $apn)" ]; then
25 sudo ip tuntap add dev $apn mode tun user $USER group $USER
26 sudo ip addr add ${GGSN_NET} dev $apn
27 sudo ip link set $apn up
28fi
29
Oliver Smith2490f692019-03-13 15:16:16 +010030if [ -z "$(ip addr show | grep "${TO_RAN_IP}")" ]; then
31 echo "No interface has IP address ${TO_RAN_IP}! Hit enter to continue anyway."
Neels Hofmeyrede80162018-09-16 13:49:13 +020032 read enter_to_continue
33fi
Oliver Smith2490f692019-03-13 15:16:16 +010034if [ -z "$(ip addr show | grep "${TO_RAN_IU_IP}")" ]; then
35 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 +020036 read enter_to_continue
Oliver Smith2490f692019-03-13 15:16:16 +010037 sudo ip addr add ${TO_RAN_IU_IP}/32 dev $dev
Neels Hofmeyr697a6172018-08-22 17:32:21 +020038fi
39
40logdir="current_log"
41mkdir -p "$logdir"
42
Oliver Smith4d7072c2018-09-28 11:30:46 +020043find_term() {
44 # Find a terminal program and write to the global "terminal" variable
45 local programs="urxvt xterm"
46 local program
47 for program in $programs; do
48 terminal="$(which $program)"
49 [ -n "$terminal" ] && return
50 done
51
52 # No terminal found
53 echo "ERROR: Couldn't find terminal program! Looked for: $programs"
54 exit 1
55}
56
Neels Hofmeyr697a6172018-08-22 17:32:21 +020057term() {
58 title="$2"
59 if [ -z "$title" ]; then
60 title="$(basename $@)"
61 fi
Neels Hofmeyr697a6172018-08-22 17:32:21 +020062 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"
63}
64
Oliver Smith4d7072c2018-09-28 11:30:46 +020065find_term
66
Neels Hofmeyr697a6172018-08-22 17:32:21 +020067hnbgw="osmo-hnbgw"
68msc="gdb -ex run --args $(which osmo-msc)"
Neels Hofmeyr8e494842019-08-07 01:35:06 +020069# To enable udtrace on osmo-msc MNCC socket, use this with adjusted /path/to/udtrace:
70# - LD_LIBRARY_PATH allows linking to titan if udtrace was compiled with titan support.
71# - LD_PRELOAD of libasan allows building osmo-msc with the sanitize.opts.
72# - the tee saves the stderr logging as well as the udtrace output to new file current_log/osmo-msc.out, since udtrace
73# will not show in osmo-msc.log
74#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 +020075gbproxy="osmo-gbproxy"
76sgsn="osmo-sgsn"
77ggsn="osmo-ggsn"
78mgw4msc="osmo-mgw -c osmo-mgw-for-msc.cfg"
79#mgw4bsc="gdb -ex run --args osmo-mgw -c osmo-mgw-for-bsc.cfg"
80#mgw4bsc="strace osmo-mgw -c osmo-mgw-for-bsc.cfg"
81mgw4bsc="osmo-mgw -c osmo-mgw-for-bsc.cfg"
Oliver Smith5467ef92018-12-13 13:27:37 +010082hlr="LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-hlr --db-upgrade"
Neels Hofmeyr697a6172018-08-22 17:32:21 +020083stp="osmo-stp"
84bsc="LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-bsc -c osmo-bsc.cfg"
85
Neels Hofmeyrcbdd7182019-03-04 00:39:32 +010086if [ "x${MSC_MNCC}" != "xinternal" ]; then
Oliver Smithd9f3d342018-09-26 16:29:00 +020087 sipcon="osmo-sip-connector -c osmo-sip-connector.cfg"
Oliver Smithd9f3d342018-09-26 16:29:00 +020088
Neels Hofmeyrba0a8282019-12-04 03:57:56 +010089 case "${PBX_SERVER}" in
Oliver Smith667f19b2019-11-08 18:16:30 +010090 "kamailio")
91 # Require kamailio (PATH hack is needed for Debian)
92 kamailio="$(PATH="$PATH:/usr/sbin:/sbin" which kamailio)"
93 if [ -z "$kamailio" ]; then
94 echo "ERROR: kamailio is not installed."
95 echo "After installing it, make sure that it does *not* run as daemon."
96 exit 1
97 fi
98 kamailio="$kamailio -f kamailio.cfg -D -e -E"
99 ;;
100 "freeswitch")
101 if [ -z "$(which freeswitch)" ]; then
102 echo "ERROR: freeswitch is not installed."
103 echo "Guide: https://freeswitch.org/confluence/display/FREESWITCH/Debian+10+Buster"
104 echo "After installing it, make sure that it does *not* run as daemon."
105 exit 1
106 fi
107 ;;
108 "none")
109 ;;
110 *)
Neels Hofmeyrba0a8282019-12-04 03:57:56 +0100111 echo "ERROR: unknown value ${PBX_SERVER} for SIPCON_SERVER!"
Oliver Smith667f19b2019-11-08 18:16:30 +0100112 exit 1
113 ;;
114 esac
Oliver Smithd9f3d342018-09-26 16:29:00 +0200115fi
116
117sudo tcpdump -i $dev -n -w current_log/$dev.single.pcap -U not port 22 &
118sudo tcpdump -i lo -n -w current_log/lo.single.pcap -U not port 22 &
119
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200120term "$ggsn" GGSN &
121sleep .2
122term "$stp" STP &
123sleep .2
124term "$hlr" HLR &
125sleep .2
126term "$sgsn" SGSN &
127sleep .2
128term "$gbproxy" GBPROXY &
129sleep .2
130term "$mgw4msc" MGW4MSC &
131sleep .2
132term "$mgw4bsc" MGW4BSC &
133sleep .2
134term "$msc" MSC &
135sleep 2
136term "$hnbgw" HNBGW &
137sleep .2
138term "$bsc" BSC &
139
Neels Hofmeyrcbdd7182019-03-04 00:39:32 +0100140if [ "x${MSC_MNCC}" != "xinternal" ]; then
Oliver Smithd9f3d342018-09-26 16:29:00 +0200141 sleep .2
142 term "$sipcon" SIPCON &
143 sleep .2
Neels Hofmeyrba0a8282019-12-04 03:57:56 +0100144 case "${PBX_SERVER}" in
Oliver Smith667f19b2019-11-08 18:16:30 +0100145 "kamailio") term "$kamailio" KAMAILIO &;;
146 "freeswitch") term "./freeswitch/freeswitch.sh" FREESWITCH &;;
147 esac
Oliver Smithd9f3d342018-09-26 16:29:00 +0200148fi
149
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200150#ssh bts rm /tmp/bts.log /tmp/pcu.log
151#ssh bts neels/run_remote.sh &
152
153echo enter to close
154read enter_to_close
155echo Closing...
156
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200157#ssh bts neels/stop_remote.sh
158
Neels Hofmeyrfecf1562019-08-07 01:34:12 +0200159kill %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200160killall osmo-msc
161killall osmo-bsc
162killall osmo-gbproxy
163killall osmo-sgsn
164#killall osmo-hnbgw
165killall osmo-mgw
166killall osmo-hlr
167killall -9 osmo-stp
168sudo killall tcpdump
169killall osmo-ggsn
170
Neels Hofmeyrfecf1562019-08-07 01:34:12 +0200171if [ "x${MSC_MNCC}" != "xinternal" ]; then
172 # 'killall' seems to work only with the shortened name
173 killall osmo-sip-connec
Neels Hofmeyrba0a8282019-12-04 03:57:56 +0100174 killall "${PBX_SERVER}"
Neels Hofmeyrfecf1562019-08-07 01:34:12 +0200175fi
176
177
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200178set +e
179cp *.cfg "$logdir"/
180
181echo
182echo enter name to save log
183read log_name
184if [ -n "$log_name" ]; then
185 newlogdir="log/$log_name"
186 #scp "bts:/tmp/{bts,pcu}.log" "bts:neels/osmo-{bts,pcu}.cfg" "$logdir"
187else
188 newlogdir="autolog/log_$(date +%Y-%m-%d_%H-%M-%S)"
189fi
190mkdir -p "$(dirname "$newlogdir")"
191
192mergecap -w "$logdir/trace.pcap" "$logdir/"*.single.pcap && rm -f "$logdir/"*.single.pcap
193
194if [ -x "$newlogdir" ]; then
195 echo "already exists, move it manually: $newlogdir"
196else
197 echo mv "$logdir" "$newlogdir"
198 mv "$logdir" "$newlogdir"
199 mkdir -p "$logdir"
200 logdir="$newlogdir"
201fi
202rm lastlog
203ln -s "$logdir" lastlog