blob: 8571a42eb5dc7d1dd14cb124e5c6b708fc615c12 [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"
47 local program
48 for program in $programs; do
49 terminal="$(which $program)"
50 [ -n "$terminal" ] && return
51 done
52
53 # No terminal found
54 echo "ERROR: Couldn't find terminal program! Looked for: $programs"
55 exit 1
56}
57
Neels Hofmeyr697a6172018-08-22 17:32:21 +020058term() {
59 title="$2"
60 if [ -z "$title" ]; then
61 title="$(basename $@)"
62 fi
Neels Hofmeyr697a6172018-08-22 17:32:21 +020063 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"
64}
65
Oliver Smith4d7072c2018-09-28 11:30:46 +020066find_term
67
Neels Hofmeyr697a6172018-08-22 17:32:21 +020068hnbgw="osmo-hnbgw"
69msc="gdb -ex run --args $(which osmo-msc)"
Neels Hofmeyr8e494842019-08-07 01:35:06 +020070# To enable udtrace on osmo-msc MNCC socket, use this with adjusted /path/to/udtrace:
71# - LD_LIBRARY_PATH allows linking to titan if udtrace was compiled with titan support.
72# - LD_PRELOAD of libasan allows building osmo-msc with the sanitize.opts.
73# - the tee saves the stderr logging as well as the udtrace output to new file current_log/osmo-msc.out, since udtrace
74# will not show in osmo-msc.log
75#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 +020076gbproxy="osmo-gbproxy"
77sgsn="osmo-sgsn"
78ggsn="osmo-ggsn"
79mgw4msc="osmo-mgw -c osmo-mgw-for-msc.cfg"
80#mgw4bsc="gdb -ex run --args osmo-mgw -c osmo-mgw-for-bsc.cfg"
81#mgw4bsc="strace osmo-mgw -c osmo-mgw-for-bsc.cfg"
82mgw4bsc="osmo-mgw -c osmo-mgw-for-bsc.cfg"
Oliver Smith5467ef92018-12-13 13:27:37 +010083hlr="LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-hlr --db-upgrade"
Neels Hofmeyr697a6172018-08-22 17:32:21 +020084stp="osmo-stp"
85bsc="LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-bsc -c osmo-bsc.cfg"
86
Neels Hofmeyrcbdd7182019-03-04 00:39:32 +010087if [ "x${MSC_MNCC}" != "xinternal" ]; then
Oliver Smithd9f3d342018-09-26 16:29:00 +020088 sipcon="osmo-sip-connector -c osmo-sip-connector.cfg"
Oliver Smithd9f3d342018-09-26 16:29:00 +020089
Neels Hofmeyrba0a8282019-12-04 03:57:56 +010090 case "${PBX_SERVER}" in
Oliver Smith667f19b2019-11-08 18:16:30 +010091 "kamailio")
92 # Require kamailio (PATH hack is needed for Debian)
93 kamailio="$(PATH="$PATH:/usr/sbin:/sbin" which kamailio)"
94 if [ -z "$kamailio" ]; then
95 echo "ERROR: kamailio is not installed."
96 echo "After installing it, make sure that it does *not* run as daemon."
97 exit 1
98 fi
99 kamailio="$kamailio -f kamailio.cfg -D -e -E"
100 ;;
101 "freeswitch")
102 if [ -z "$(which freeswitch)" ]; then
103 echo "ERROR: freeswitch is not installed."
104 echo "Guide: https://freeswitch.org/confluence/display/FREESWITCH/Debian+10+Buster"
105 echo "After installing it, make sure that it does *not* run as daemon."
106 exit 1
107 fi
108 ;;
109 "none")
110 ;;
111 *)
Neels Hofmeyrba0a8282019-12-04 03:57:56 +0100112 echo "ERROR: unknown value ${PBX_SERVER} for SIPCON_SERVER!"
Oliver Smith667f19b2019-11-08 18:16:30 +0100113 exit 1
114 ;;
115 esac
Oliver Smithd9f3d342018-09-26 16:29:00 +0200116fi
117
118sudo tcpdump -i $dev -n -w current_log/$dev.single.pcap -U not port 22 &
119sudo tcpdump -i lo -n -w current_log/lo.single.pcap -U not port 22 &
120
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200121term "$ggsn" GGSN &
122sleep .2
123term "$stp" STP &
124sleep .2
125term "$hlr" HLR &
126sleep .2
127term "$sgsn" SGSN &
128sleep .2
129term "$gbproxy" GBPROXY &
130sleep .2
131term "$mgw4msc" MGW4MSC &
132sleep .2
133term "$mgw4bsc" MGW4BSC &
134sleep .2
135term "$msc" MSC &
136sleep 2
137term "$hnbgw" HNBGW &
138sleep .2
139term "$bsc" BSC &
140
Neels Hofmeyrcbdd7182019-03-04 00:39:32 +0100141if [ "x${MSC_MNCC}" != "xinternal" ]; then
Oliver Smithd9f3d342018-09-26 16:29:00 +0200142 sleep .2
143 term "$sipcon" SIPCON &
144 sleep .2
Neels Hofmeyrba0a8282019-12-04 03:57:56 +0100145 case "${PBX_SERVER}" in
Oliver Smith667f19b2019-11-08 18:16:30 +0100146 "kamailio") term "$kamailio" KAMAILIO &;;
147 "freeswitch") term "./freeswitch/freeswitch.sh" FREESWITCH &;;
148 esac
Oliver Smithd9f3d342018-09-26 16:29:00 +0200149fi
150
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200151#ssh bts rm /tmp/bts.log /tmp/pcu.log
152#ssh bts neels/run_remote.sh &
153
154echo enter to close
155read enter_to_close
156echo Closing...
157
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200158#ssh bts neels/stop_remote.sh
159
Neels Hofmeyrfecf1562019-08-07 01:34:12 +0200160kill %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200161killall osmo-msc
162killall osmo-bsc
163killall osmo-gbproxy
164killall osmo-sgsn
165#killall osmo-hnbgw
166killall osmo-mgw
167killall osmo-hlr
168killall -9 osmo-stp
169sudo killall tcpdump
170killall osmo-ggsn
171
Neels Hofmeyrfecf1562019-08-07 01:34:12 +0200172if [ "x${MSC_MNCC}" != "xinternal" ]; then
173 # 'killall' seems to work only with the shortened name
174 killall osmo-sip-connec
Neels Hofmeyrba0a8282019-12-04 03:57:56 +0100175 killall "${PBX_SERVER}"
Neels Hofmeyrfecf1562019-08-07 01:34:12 +0200176fi
177
178
Neels Hofmeyr697a6172018-08-22 17:32:21 +0200179set +e
180cp *.cfg "$logdir"/
181
182echo
183echo enter name to save log
184read log_name
185if [ -n "$log_name" ]; then
186 newlogdir="log/$log_name"
187 #scp "bts:/tmp/{bts,pcu}.log" "bts:neels/osmo-{bts,pcu}.cfg" "$logdir"
188else
189 newlogdir="autolog/log_$(date +%Y-%m-%d_%H-%M-%S)"
190fi
191mkdir -p "$(dirname "$newlogdir")"
192
193mergecap -w "$logdir/trace.pcap" "$logdir/"*.single.pcap && rm -f "$logdir/"*.single.pcap
194
195if [ -x "$newlogdir" ]; then
196 echo "already exists, move it manually: $newlogdir"
197else
198 echo mv "$logdir" "$newlogdir"
199 mv "$logdir" "$newlogdir"
200 mkdir -p "$logdir"
201 logdir="$newlogdir"
202fi
203rm lastlog
204ln -s "$logdir" lastlog