Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Oliver Smith | 24ddf9c | 2019-01-30 16:48:18 +0100 | [diff] [blame] | 2 | |
| 3 | if ! ../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 |
| 9 | fi |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 10 | |
| 11 | dev="${ETH_DEV}" |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 12 | apn="${APN_DEV}" |
| 13 | |
| 14 | sudo true || exit 1 |
| 15 | |
| 16 | if [ -z "$(sudo iptables -L -t nat | grep MASQUERADE)" ]; then |
| 17 | sudo iptables -t nat -A POSTROUTING -s ${GGSN_NET} -o $dev -j MASQUERADE |
| 18 | fi |
| 19 | |
| 20 | if [ "$(sudo cat /proc/sys/net/ipv4/ip_forward)" = "0" ]; then |
| 21 | sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" |
| 22 | fi |
| 23 | |
| 24 | if [ -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 |
| 28 | fi |
| 29 | |
Oliver Smith | 2490f69 | 2019-03-13 15:16:16 +0100 | [diff] [blame] | 30 | if [ -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 Hofmeyr | ede8016 | 2018-09-16 13:49:13 +0200 | [diff] [blame] | 32 | read enter_to_continue |
| 33 | fi |
Oliver Smith | 2490f69 | 2019-03-13 15:16:16 +0100 | [diff] [blame] | 34 | if [ -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 Hofmeyr | ede8016 | 2018-09-16 13:49:13 +0200 | [diff] [blame] | 36 | read enter_to_continue |
Oliver Smith | 2490f69 | 2019-03-13 15:16:16 +0100 | [diff] [blame] | 37 | sudo ip addr add ${TO_RAN_IU_IP}/32 dev $dev |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 38 | fi |
| 39 | |
| 40 | logdir="current_log" |
| 41 | mkdir -p "$logdir" |
| 42 | |
Oliver Smith | 4d7072c | 2018-09-28 11:30:46 +0200 | [diff] [blame] | 43 | find_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 Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 57 | term() { |
| 58 | title="$2" |
| 59 | if [ -z "$title" ]; then |
| 60 | title="$(basename $@)" |
| 61 | fi |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 62 | 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 Smith | 4d7072c | 2018-09-28 11:30:46 +0200 | [diff] [blame] | 65 | find_term |
| 66 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 67 | hnbgw="osmo-hnbgw" |
| 68 | msc="gdb -ex run --args $(which osmo-msc)" |
Neels Hofmeyr | 8e49484 | 2019-08-07 01:35:06 +0200 | [diff] [blame] | 69 | # 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 Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 75 | gbproxy="osmo-gbproxy" |
| 76 | sgsn="osmo-sgsn" |
| 77 | ggsn="osmo-ggsn" |
| 78 | mgw4msc="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" |
| 81 | mgw4bsc="osmo-mgw -c osmo-mgw-for-bsc.cfg" |
Oliver Smith | 5467ef9 | 2018-12-13 13:27:37 +0100 | [diff] [blame] | 82 | hlr="LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-hlr --db-upgrade" |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 83 | stp="osmo-stp" |
| 84 | bsc="LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-bsc -c osmo-bsc.cfg" |
| 85 | |
Neels Hofmeyr | cbdd718 | 2019-03-04 00:39:32 +0100 | [diff] [blame] | 86 | if [ "x${MSC_MNCC}" != "xinternal" ]; then |
Oliver Smith | d9f3d34 | 2018-09-26 16:29:00 +0200 | [diff] [blame] | 87 | sipcon="osmo-sip-connector -c osmo-sip-connector.cfg" |
Oliver Smith | d9f3d34 | 2018-09-26 16:29:00 +0200 | [diff] [blame] | 88 | |
Neels Hofmeyr | ba0a828 | 2019-12-04 03:57:56 +0100 | [diff] [blame] | 89 | case "${PBX_SERVER}" in |
Oliver Smith | 667f19b | 2019-11-08 18:16:30 +0100 | [diff] [blame] | 90 | "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 Hofmeyr | ba0a828 | 2019-12-04 03:57:56 +0100 | [diff] [blame] | 111 | echo "ERROR: unknown value ${PBX_SERVER} for SIPCON_SERVER!" |
Oliver Smith | 667f19b | 2019-11-08 18:16:30 +0100 | [diff] [blame] | 112 | exit 1 |
| 113 | ;; |
| 114 | esac |
Oliver Smith | d9f3d34 | 2018-09-26 16:29:00 +0200 | [diff] [blame] | 115 | fi |
| 116 | |
| 117 | sudo tcpdump -i $dev -n -w current_log/$dev.single.pcap -U not port 22 & |
| 118 | sudo tcpdump -i lo -n -w current_log/lo.single.pcap -U not port 22 & |
| 119 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 120 | term "$ggsn" GGSN & |
| 121 | sleep .2 |
| 122 | term "$stp" STP & |
| 123 | sleep .2 |
| 124 | term "$hlr" HLR & |
| 125 | sleep .2 |
| 126 | term "$sgsn" SGSN & |
| 127 | sleep .2 |
| 128 | term "$gbproxy" GBPROXY & |
| 129 | sleep .2 |
| 130 | term "$mgw4msc" MGW4MSC & |
| 131 | sleep .2 |
| 132 | term "$mgw4bsc" MGW4BSC & |
| 133 | sleep .2 |
| 134 | term "$msc" MSC & |
| 135 | sleep 2 |
| 136 | term "$hnbgw" HNBGW & |
| 137 | sleep .2 |
| 138 | term "$bsc" BSC & |
| 139 | |
Neels Hofmeyr | cbdd718 | 2019-03-04 00:39:32 +0100 | [diff] [blame] | 140 | if [ "x${MSC_MNCC}" != "xinternal" ]; then |
Oliver Smith | d9f3d34 | 2018-09-26 16:29:00 +0200 | [diff] [blame] | 141 | sleep .2 |
| 142 | term "$sipcon" SIPCON & |
| 143 | sleep .2 |
Neels Hofmeyr | ba0a828 | 2019-12-04 03:57:56 +0100 | [diff] [blame] | 144 | case "${PBX_SERVER}" in |
Oliver Smith | 667f19b | 2019-11-08 18:16:30 +0100 | [diff] [blame] | 145 | "kamailio") term "$kamailio" KAMAILIO &;; |
| 146 | "freeswitch") term "./freeswitch/freeswitch.sh" FREESWITCH &;; |
| 147 | esac |
Oliver Smith | d9f3d34 | 2018-09-26 16:29:00 +0200 | [diff] [blame] | 148 | fi |
| 149 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 150 | #ssh bts rm /tmp/bts.log /tmp/pcu.log |
| 151 | #ssh bts neels/run_remote.sh & |
| 152 | |
| 153 | echo enter to close |
| 154 | read enter_to_close |
| 155 | echo Closing... |
| 156 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 157 | #ssh bts neels/stop_remote.sh |
| 158 | |
Neels Hofmeyr | fecf156 | 2019-08-07 01:34:12 +0200 | [diff] [blame] | 159 | kill %1 %2 %3 %4 %5 %6 %7 %8 %9 %10 %11 %12 %13 %14 |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 160 | killall osmo-msc |
| 161 | killall osmo-bsc |
| 162 | killall osmo-gbproxy |
| 163 | killall osmo-sgsn |
| 164 | #killall osmo-hnbgw |
| 165 | killall osmo-mgw |
| 166 | killall osmo-hlr |
| 167 | killall -9 osmo-stp |
| 168 | sudo killall tcpdump |
| 169 | killall osmo-ggsn |
| 170 | |
Neels Hofmeyr | fecf156 | 2019-08-07 01:34:12 +0200 | [diff] [blame] | 171 | if [ "x${MSC_MNCC}" != "xinternal" ]; then |
| 172 | # 'killall' seems to work only with the shortened name |
| 173 | killall osmo-sip-connec |
Neels Hofmeyr | ba0a828 | 2019-12-04 03:57:56 +0100 | [diff] [blame] | 174 | killall "${PBX_SERVER}" |
Neels Hofmeyr | fecf156 | 2019-08-07 01:34:12 +0200 | [diff] [blame] | 175 | fi |
| 176 | |
| 177 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 178 | set +e |
| 179 | cp *.cfg "$logdir"/ |
| 180 | |
| 181 | echo |
| 182 | echo enter name to save log |
| 183 | read log_name |
| 184 | if [ -n "$log_name" ]; then |
| 185 | newlogdir="log/$log_name" |
| 186 | #scp "bts:/tmp/{bts,pcu}.log" "bts:neels/osmo-{bts,pcu}.cfg" "$logdir" |
| 187 | else |
| 188 | newlogdir="autolog/log_$(date +%Y-%m-%d_%H-%M-%S)" |
| 189 | fi |
| 190 | mkdir -p "$(dirname "$newlogdir")" |
| 191 | |
| 192 | mergecap -w "$logdir/trace.pcap" "$logdir/"*.single.pcap && rm -f "$logdir/"*.single.pcap |
| 193 | |
| 194 | if [ -x "$newlogdir" ]; then |
| 195 | echo "already exists, move it manually: $newlogdir" |
| 196 | else |
| 197 | echo mv "$logdir" "$newlogdir" |
| 198 | mv "$logdir" "$newlogdir" |
| 199 | mkdir -p "$logdir" |
| 200 | logdir="$newlogdir" |
| 201 | fi |
| 202 | rm lastlog |
| 203 | ln -s "$logdir" lastlog |