2018-08-22 15:32:21 +00:00
#!/usr/bin/env bash
2019-01-30 15:48:18 +00:00
2022-01-17 14:59:31 +00:00
# tmux: start this script inside a new session
tmux_session = "CN"
if [ " ${ TERMINAL } " = "tmux" ] && [ " $1 " != "inside-tmux" ] ; then
echo " Starting tmux session ' $tmux_session ' "
unset TMUX
exec tmux new-session -s " $tmux_session " -n "RUN" " $0 " "inside-tmux"
fi
2019-01-30 15:48:18 +00:00
if ! ../fill_config.py --check-stale; then
echo
echo "WARNING: STALE CONFIGS - your net configs are older than the templates they should be based on!"
echo " * Hit enter to continue, and use the stale config files"
echo " * Hit ^C and run 'make regen' to regenerate your configs"
read enter_to_continue
fi
2018-08-22 15:32:21 +00:00
dev = " ${ ETH_DEV } "
apn = " ${ APN_DEV } "
sudo true || exit 1
2021-07-07 14:40:36 +00:00
if ! sudo iptables -t nat -C POSTROUTING -s ${ GGSN_NET } -o $dev -j MASQUERADE 2>/dev/null; then
echo "Adding iptables rule for masquerade"
sudo iptables -t nat -I POSTROUTING -s ${ GGSN_NET } -o $dev -j MASQUERADE
2018-08-22 15:32:21 +00:00
fi
if [ " $( sudo cat /proc/sys/net/ipv4/ip_forward) " = "0" ] ; then
sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
fi
if [ -z " $( ip tuntap show | grep $apn ) " ] ; then
sudo ip tuntap add dev $apn mode tun user $USER group $USER
sudo ip addr add ${ GGSN_NET } dev $apn
sudo ip link set $apn up
fi
2019-03-13 14:16:16 +00:00
if [ -z " $( ip addr show | grep " ${ TO_RAN_IP } " ) " ] ; then
echo " No interface has IP address ${ TO_RAN_IP } ! Hit enter to continue anyway. "
2018-09-16 11:49:13 +00:00
read enter_to_continue
fi
2019-03-13 14:16:16 +00:00
if [ -z " $( ip addr show | grep " ${ TO_RAN_IU_IP } " ) " ] ; then
echo " No interface has IP address ${ TO_RAN_IU_IP } ! Hit enter to 'ip addr add ${ TO_RAN_IU_IP } /32 dev $dev ' "
2018-09-16 11:49:13 +00:00
read enter_to_continue
2019-03-13 14:16:16 +00:00
sudo ip addr add ${ TO_RAN_IU_IP } /32 dev $dev
2018-08-22 15:32:21 +00:00
fi
logdir = "current_log"
2022-01-17 14:59:24 +00:00
piddir = "run/pids"
2022-01-18 10:21:37 +00:00
launcherdir = "run/launchers"
rm -rf " $launcherdir "
mkdir -p " $logdir " " $piddir " " $launcherdir "
2018-08-22 15:32:21 +00:00
2018-09-28 09:30:46 +00:00
find_term( ) {
# Find a terminal program and write to the global "terminal" variable
2022-01-17 14:59:31 +00:00
local programs = "urxvt xterm tmux"
2022-01-17 14:59:02 +00:00
if [ -z " ${ TERMINAL } " ] ; then
echo "ERROR: TERMINAL is not defined in your osmo-dev net config file. Please add it."
exit 1
fi
case " $programs " in
*" ${ TERMINAL } " *)
terminal = " ${ TERMINAL } "
if command -v " $terminal " >/dev/null; then
echo " Terminal: ${ TERMINAL } "
return
fi
echo " ERROR: Terminal ' ${ TERMINAL } ' is configured, but not installed "
exit 1
; ;
esac
echo " ERROR: Terminal ' ${ TERMINAL } ' is not in list of supported terminals ( $programs ) "
2018-09-28 09:30:46 +00:00
exit 1
}
2022-01-17 14:59:24 +00:00
pidfiles_must_not_exist( ) {
local pidfile
for pidfile in " $@ " ; do
if [ -e " $pidfile " ] ; then
echo
echo " ERROR: pidfile exists: $pidfile "
echo
kill_pids
exit 1
fi
done
}
2018-08-22 15:32:21 +00:00
term( ) {
title = " $2 "
if [ -z " $title " ] ; then
title = " $( basename $@ ) "
fi
2022-01-17 14:59:24 +00:00
local pidfile = " $piddir / $title .pid "
local pidfile_term = " $piddir / $title .term.pid "
pidfiles_must_not_exist " $pidfile " " $pidfile_term "
2022-01-18 10:21:37 +00:00
local launcher = " $launcherdir / $title .sh "
cat << EOF > " $launcher "
#!/bin/sh
export LD_LIBRARY_PATH = '/usr/local/lib'
$1 &
echo \$ ! > $pidfile
wait
echo
while true; do
echo 'q Enter to close'
2022-02-21 10:25:37 +00:00
read q_to_close < /dev/tty
2022-01-18 10:21:37 +00:00
if [ "x\$q_to_close" = xq ] ; then
break
fi
done
EOF
chmod +x " $launcher "
2022-01-17 14:59:31 +00:00
case " $terminal " in
tmux)
tmux new-window -d -n " $title " " $launcher &; echo \$! > $pidfile_term ; fg; wait "
; ;
*)
$terminal \
-title " CN: $title " \
-e sh -c " $launcher " \
&
2022-01-17 14:59:24 +00:00
2022-01-17 14:59:31 +00:00
echo " $! " > " $pidfile_term "
; ;
esac
2022-01-17 14:59:24 +00:00
}
kill_pids( ) {
local pidfile
local pid
for pidfile in " $piddir " /*.pid; do
if ! [ -e " $pidfile " ] ; then
continue
fi
pid = " $( cat " $pidfile " ) "
echo " killing $( basename " $pidfile " ) ( $pid ) "
sudo kill " $pid "
rm " $pidfile "
done
2018-08-22 15:32:21 +00:00
}
2018-09-28 09:30:46 +00:00
find_term
2022-01-17 14:59:24 +00:00
kill_pids
2018-09-28 09:30:46 +00:00
2018-08-22 15:32:21 +00:00
hnbgw = "osmo-hnbgw"
msc = " gdb -ex run --args $( which osmo-msc) "
2019-08-06 23:35:06 +00:00
# To enable udtrace on osmo-msc MNCC socket, use this with adjusted /path/to/udtrace:
# - LD_LIBRARY_PATH allows linking to titan if udtrace was compiled with titan support.
# - LD_PRELOAD of libasan allows building osmo-msc with the sanitize.opts.
# - the tee saves the stderr logging as well as the udtrace output to new file current_log/osmo-msc.out, since udtrace
# will not show in osmo-msc.log
#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"
2018-08-22 15:32:21 +00:00
gbproxy = "osmo-gbproxy"
sgsn = "osmo-sgsn"
ggsn = "osmo-ggsn"
mgw4msc = "osmo-mgw -c osmo-mgw-for-msc.cfg"
#mgw4bsc="gdb -ex run --args osmo-mgw -c osmo-mgw-for-bsc.cfg"
#mgw4bsc="strace osmo-mgw -c osmo-mgw-for-bsc.cfg"
mgw4bsc = "osmo-mgw -c osmo-mgw-for-bsc.cfg"
2018-12-13 12:27:37 +00:00
hlr = "LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-hlr --db-upgrade"
2021-12-14 15:27:10 +00:00
stp4cn = "osmo-stp -c osmo-stp-cn.cfg"
stp4ran = "osmo-stp -c osmo-stp-ran.cfg"
2018-08-22 15:32:21 +00:00
bsc = "LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-bsc -c osmo-bsc.cfg"
2021-12-14 15:27:10 +00:00
bscnat = "osmo-bsc-nat"
2018-08-22 15:32:21 +00:00
2019-03-03 23:39:32 +00:00
if [ " x ${ MSC_MNCC } " != "xinternal" ] ; then
2018-09-26 14:29:00 +00:00
sipcon = "osmo-sip-connector -c osmo-sip-connector.cfg"
2019-12-04 02:57:56 +00:00
case " ${ PBX_SERVER } " in
2019-11-08 17:16:30 +00:00
"kamailio" )
# Require kamailio (PATH hack is needed for Debian)
kamailio = " $( PATH = " $PATH :/usr/sbin:/sbin " which kamailio) "
if [ -z " $kamailio " ] ; then
echo "ERROR: kamailio is not installed."
echo "After installing it, make sure that it does *not* run as daemon."
exit 1
fi
kamailio = " $kamailio -f kamailio.cfg -D -e -E "
; ;
"freeswitch" )
if [ -z " $( which freeswitch) " ] ; then
echo "ERROR: freeswitch is not installed."
echo "Guide: https://freeswitch.org/confluence/display/FREESWITCH/Debian+10+Buster"
echo "After installing it, make sure that it does *not* run as daemon."
exit 1
fi
; ;
"none" )
; ;
*)
2019-12-04 02:57:56 +00:00
echo " ERROR: unknown value ${ PBX_SERVER } for SIPCON_SERVER! "
2019-11-08 17:16:30 +00:00
exit 1
; ;
esac
2018-09-26 14:29:00 +00:00
fi
2022-01-17 14:59:24 +00:00
PIDFILE_TCPDUMP_DEV = " $piddir /tcpdump. $dev .pid "
PIDFILE_TCPDUMP_LO = " $piddir /tcpdump.lo.pid "
pidfiles_must_not_exist " $PIDFILE_TCPDUMP_DEV " " $PIDFILE_TCPDUMP_LO "
2018-09-26 14:29:00 +00:00
sudo tcpdump -i $dev -n -w current_log/$dev .single.pcap -U not port 22 &
2022-01-17 14:59:24 +00:00
echo " $! " > " $PIDFILE_TCPDUMP_DEV "
2018-09-26 14:29:00 +00:00
sudo tcpdump -i lo -n -w current_log/lo.single.pcap -U not port 22 &
2022-01-17 14:59:24 +00:00
echo " $! " > " $PIDFILE_TCPDUMP_LO "
2018-09-26 14:29:00 +00:00
2022-01-17 14:59:24 +00:00
term " $ggsn " GGSN
2021-12-14 17:12:54 +00:00
2021-12-14 15:27:10 +00:00
if [ " ${ STP_CN_IP } " = " ${ STP_RAN_IP } " ] ; then
sleep .2
2022-01-17 14:59:24 +00:00
term " $stp4cn " STP
2021-12-14 15:27:10 +00:00
else
sleep .2
2022-01-17 14:59:24 +00:00
term " $stp4cn " STP4CN
2021-12-14 15:27:10 +00:00
sleep .2
2022-01-17 14:59:24 +00:00
term " $stp4ran " STP4RAN
2021-12-14 15:27:10 +00:00
sleep .2
2022-01-17 14:59:24 +00:00
term " $bscnat " BSCNAT
2021-12-14 15:27:10 +00:00
fi
2021-12-14 17:12:54 +00:00
2018-08-22 15:32:21 +00:00
sleep .2
2022-01-17 14:59:24 +00:00
term " $hlr " HLR
2021-12-14 17:12:54 +00:00
2018-08-22 15:32:21 +00:00
sleep .2
2022-01-17 14:59:24 +00:00
term " $sgsn " SGSN
2021-12-14 17:12:54 +00:00
2018-08-22 15:32:21 +00:00
sleep .2
2022-01-17 14:59:24 +00:00
term " $gbproxy " GBPROXY
2021-12-14 17:12:54 +00:00
2018-08-22 15:32:21 +00:00
sleep .2
2022-01-17 14:59:24 +00:00
term " $mgw4msc " MGW4MSC
2021-12-14 17:12:54 +00:00
2018-08-22 15:32:21 +00:00
sleep .2
2022-01-17 14:59:24 +00:00
term " $mgw4bsc " MGW4BSC
2021-12-14 17:12:54 +00:00
2018-08-22 15:32:21 +00:00
sleep .2
2022-01-17 14:59:24 +00:00
term " $msc " MSC
2021-12-14 17:12:54 +00:00
2018-08-22 15:32:21 +00:00
sleep 2
2022-01-17 14:59:24 +00:00
term " $hnbgw " HNBGW
2021-12-14 17:12:54 +00:00
2018-08-22 15:32:21 +00:00
sleep .2
2022-01-17 14:59:24 +00:00
term " $bsc " BSC
2018-08-22 15:32:21 +00:00
2019-03-03 23:39:32 +00:00
if [ " x ${ MSC_MNCC } " != "xinternal" ] ; then
2018-09-26 14:29:00 +00:00
sleep .2
2022-01-17 14:59:24 +00:00
term " $sipcon " SIPCON
2021-12-14 17:12:54 +00:00
2018-09-26 14:29:00 +00:00
sleep .2
2019-12-04 02:57:56 +00:00
case " ${ PBX_SERVER } " in
2021-12-14 17:12:54 +00:00
"kamailio" )
2022-01-17 14:59:24 +00:00
term " $kamailio " KAMAILIO
2021-12-14 17:12:54 +00:00
; ;
"freeswitch" )
2022-01-17 14:59:24 +00:00
term "./freeswitch/freeswitch.sh" FREESWITCH
2021-12-14 17:12:54 +00:00
; ;
2019-11-08 17:16:30 +00:00
esac
2018-09-26 14:29:00 +00:00
fi
2018-08-22 15:32:21 +00:00
#ssh bts rm /tmp/bts.log /tmp/pcu.log
#ssh bts neels/run_remote.sh &
echo enter to close
read enter_to_close
echo Closing...
#ssh bts neels/stop_remote.sh
2022-01-17 14:59:24 +00:00
kill_pids
2019-08-06 23:34:12 +00:00
2018-08-22 15:32:21 +00:00
set +e
cp *.cfg " $logdir " /
echo
echo enter name to save log
read log_name
if [ -n " $log_name " ] ; then
newlogdir = " log/ $log_name "
#scp "bts:/tmp/{bts,pcu}.log" "bts:neels/osmo-{bts,pcu}.cfg" "$logdir"
else
2022-02-17 09:08:14 +00:00
log_name = " log_ $( date +%Y-%m-%d_%H-%M-%S) "
newlogdir = " autolog/ $log_name "
2018-08-22 15:32:21 +00:00
fi
mkdir -p " $( dirname " $newlogdir " ) "
mergecap -w " $logdir /trace.pcap " " $logdir / " *.single.pcap && rm -f " $logdir / " *.single.pcap
2022-02-17 09:08:14 +00:00
mv " $logdir /trace.pcap " " $logdir /trace- $log_name .pcap "
2018-08-22 15:32:21 +00:00
if [ -x " $newlogdir " ] ; then
echo " already exists, move it manually: $newlogdir "
else
echo mv " $logdir " " $newlogdir "
mv " $logdir " " $newlogdir "
mkdir -p " $logdir "
logdir = " $newlogdir "
fi
rm lastlog
ln -s " $logdir " lastlog