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 | |
Oliver Smith | 4186b95 | 2021-07-07 16:40:36 +0200 | [diff] [blame] | 16 | if ! 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 Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 19 | fi |
| 20 | |
| 21 | if [ "$(sudo cat /proc/sys/net/ipv4/ip_forward)" = "0" ]; then |
| 22 | sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward" |
| 23 | fi |
| 24 | |
| 25 | if [ -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 |
| 29 | fi |
| 30 | |
Oliver Smith | 2490f69 | 2019-03-13 15:16:16 +0100 | [diff] [blame] | 31 | if [ -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 Hofmeyr | ede8016 | 2018-09-16 13:49:13 +0200 | [diff] [blame] | 33 | read enter_to_continue |
| 34 | fi |
Oliver Smith | 2490f69 | 2019-03-13 15:16:16 +0100 | [diff] [blame] | 35 | if [ -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 Hofmeyr | ede8016 | 2018-09-16 13:49:13 +0200 | [diff] [blame] | 37 | read enter_to_continue |
Oliver Smith | 2490f69 | 2019-03-13 15:16:16 +0100 | [diff] [blame] | 38 | sudo ip addr add ${TO_RAN_IU_IP}/32 dev $dev |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 39 | fi |
| 40 | |
| 41 | logdir="current_log" |
| 42 | mkdir -p "$logdir" |
| 43 | |
Oliver Smith | 4d7072c | 2018-09-28 11:30:46 +0200 | [diff] [blame] | 44 | find_term() { |
| 45 | # Find a terminal program and write to the global "terminal" variable |
| 46 | local programs="urxvt xterm" |
Oliver Smith | 4d7072c | 2018-09-28 11:30:46 +0200 | [diff] [blame] | 47 | |
Oliver Smith | b28a910 | 2022-01-17 15:59:02 +0100 | [diff] [blame^] | 48 | 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 Smith | 4d7072c | 2018-09-28 11:30:46 +0200 | [diff] [blame] | 68 | exit 1 |
| 69 | } |
| 70 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 71 | term() { |
| 72 | title="$2" |
| 73 | if [ -z "$title" ]; then |
| 74 | title="$(basename $@)" |
| 75 | fi |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 76 | 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 Smith | 4d7072c | 2018-09-28 11:30:46 +0200 | [diff] [blame] | 79 | find_term |
| 80 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 81 | hnbgw="osmo-hnbgw" |
| 82 | msc="gdb -ex run --args $(which osmo-msc)" |
Neels Hofmeyr | 8e49484 | 2019-08-07 01:35:06 +0200 | [diff] [blame] | 83 | # 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 Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 89 | gbproxy="osmo-gbproxy" |
| 90 | sgsn="osmo-sgsn" |
| 91 | ggsn="osmo-ggsn" |
| 92 | mgw4msc="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" |
| 95 | mgw4bsc="osmo-mgw -c osmo-mgw-for-bsc.cfg" |
Oliver Smith | 5467ef9 | 2018-12-13 13:27:37 +0100 | [diff] [blame] | 96 | hlr="LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-hlr --db-upgrade" |
Oliver Smith | a3a1a0d | 2021-12-14 16:27:10 +0100 | [diff] [blame] | 97 | stp4cn="osmo-stp -c osmo-stp-cn.cfg" |
| 98 | stp4ran="osmo-stp -c osmo-stp-ran.cfg" |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 99 | bsc="LD_LIBRARY_PATH=/usr/local/lib gdb -ex run --args osmo-bsc -c osmo-bsc.cfg" |
Oliver Smith | a3a1a0d | 2021-12-14 16:27:10 +0100 | [diff] [blame] | 100 | bscnat="osmo-bsc-nat" |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 101 | |
Neels Hofmeyr | cbdd718 | 2019-03-04 00:39:32 +0100 | [diff] [blame] | 102 | if [ "x${MSC_MNCC}" != "xinternal" ]; then |
Oliver Smith | d9f3d34 | 2018-09-26 16:29:00 +0200 | [diff] [blame] | 103 | sipcon="osmo-sip-connector -c osmo-sip-connector.cfg" |
Oliver Smith | d9f3d34 | 2018-09-26 16:29:00 +0200 | [diff] [blame] | 104 | |
Neels Hofmeyr | ba0a828 | 2019-12-04 03:57:56 +0100 | [diff] [blame] | 105 | case "${PBX_SERVER}" in |
Oliver Smith | 667f19b | 2019-11-08 18:16:30 +0100 | [diff] [blame] | 106 | "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 Hofmeyr | ba0a828 | 2019-12-04 03:57:56 +0100 | [diff] [blame] | 127 | echo "ERROR: unknown value ${PBX_SERVER} for SIPCON_SERVER!" |
Oliver Smith | 667f19b | 2019-11-08 18:16:30 +0100 | [diff] [blame] | 128 | exit 1 |
| 129 | ;; |
| 130 | esac |
Oliver Smith | d9f3d34 | 2018-09-26 16:29:00 +0200 | [diff] [blame] | 131 | fi |
| 132 | |
| 133 | sudo tcpdump -i $dev -n -w current_log/$dev.single.pcap -U not port 22 & |
| 134 | sudo tcpdump -i lo -n -w current_log/lo.single.pcap -U not port 22 & |
| 135 | |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 136 | PIDS="" |
| 137 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 138 | term "$ggsn" GGSN & |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 139 | PIDS="$PIDS $!" |
| 140 | |
Oliver Smith | a3a1a0d | 2021-12-14 16:27:10 +0100 | [diff] [blame] | 141 | if [ "${STP_CN_IP}" = "${STP_RAN_IP}" ]; then |
| 142 | sleep .2 |
| 143 | term "$stp4cn" STP & |
| 144 | PIDS="$PIDS $!" |
| 145 | else |
| 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 $!" |
| 157 | fi |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 158 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 159 | sleep .2 |
| 160 | term "$hlr" HLR & |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 161 | PIDS="$PIDS $!" |
| 162 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 163 | sleep .2 |
| 164 | term "$sgsn" SGSN & |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 165 | PIDS="$PIDS $!" |
| 166 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 167 | sleep .2 |
| 168 | term "$gbproxy" GBPROXY & |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 169 | PIDS="$PIDS $!" |
| 170 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 171 | sleep .2 |
| 172 | term "$mgw4msc" MGW4MSC & |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 173 | PIDS="$PIDS $!" |
| 174 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 175 | sleep .2 |
| 176 | term "$mgw4bsc" MGW4BSC & |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 177 | PIDS="$PIDS $!" |
| 178 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 179 | sleep .2 |
| 180 | term "$msc" MSC & |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 181 | PIDS="$PIDS $!" |
| 182 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 183 | sleep 2 |
| 184 | term "$hnbgw" HNBGW & |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 185 | PIDS="$PIDS $!" |
| 186 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 187 | sleep .2 |
| 188 | term "$bsc" BSC & |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 189 | PIDS="$PIDS $!" |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 190 | |
Neels Hofmeyr | cbdd718 | 2019-03-04 00:39:32 +0100 | [diff] [blame] | 191 | if [ "x${MSC_MNCC}" != "xinternal" ]; then |
Oliver Smith | d9f3d34 | 2018-09-26 16:29:00 +0200 | [diff] [blame] | 192 | sleep .2 |
| 193 | term "$sipcon" SIPCON & |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 194 | PIDS="$PIDS $!" |
| 195 | |
Oliver Smith | d9f3d34 | 2018-09-26 16:29:00 +0200 | [diff] [blame] | 196 | sleep .2 |
Neels Hofmeyr | ba0a828 | 2019-12-04 03:57:56 +0100 | [diff] [blame] | 197 | case "${PBX_SERVER}" in |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 198 | "kamailio") |
| 199 | term "$kamailio" KAMAILIO & |
| 200 | PIDS="$PIDS $!" |
| 201 | ;; |
| 202 | "freeswitch") |
| 203 | term "./freeswitch/freeswitch.sh" FREESWITCH & |
| 204 | PIDS="$PIDS $!" |
| 205 | ;; |
Oliver Smith | 667f19b | 2019-11-08 18:16:30 +0100 | [diff] [blame] | 206 | esac |
Oliver Smith | d9f3d34 | 2018-09-26 16:29:00 +0200 | [diff] [blame] | 207 | fi |
| 208 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 209 | #ssh bts rm /tmp/bts.log /tmp/pcu.log |
| 210 | #ssh bts neels/run_remote.sh & |
| 211 | |
| 212 | echo enter to close |
| 213 | read enter_to_close |
| 214 | echo Closing... |
| 215 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 216 | #ssh bts neels/stop_remote.sh |
| 217 | |
Oliver Smith | 8fd5098 | 2021-12-14 18:12:54 +0100 | [diff] [blame] | 218 | for i in $PIDS; do |
| 219 | kill "$i" |
| 220 | done |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 221 | killall osmo-msc |
| 222 | killall osmo-bsc |
| 223 | killall osmo-gbproxy |
| 224 | killall osmo-sgsn |
| 225 | #killall osmo-hnbgw |
| 226 | killall osmo-mgw |
| 227 | killall osmo-hlr |
| 228 | killall -9 osmo-stp |
| 229 | sudo killall tcpdump |
| 230 | killall osmo-ggsn |
Oliver Smith | a3a1a0d | 2021-12-14 16:27:10 +0100 | [diff] [blame] | 231 | killall osmo-bsc-nat |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 232 | |
Neels Hofmeyr | fecf156 | 2019-08-07 01:34:12 +0200 | [diff] [blame] | 233 | if [ "x${MSC_MNCC}" != "xinternal" ]; then |
| 234 | # 'killall' seems to work only with the shortened name |
| 235 | killall osmo-sip-connec |
Neels Hofmeyr | ba0a828 | 2019-12-04 03:57:56 +0100 | [diff] [blame] | 236 | killall "${PBX_SERVER}" |
Neels Hofmeyr | fecf156 | 2019-08-07 01:34:12 +0200 | [diff] [blame] | 237 | fi |
| 238 | |
| 239 | |
Neels Hofmeyr | 697a617 | 2018-08-22 17:32:21 +0200 | [diff] [blame] | 240 | set +e |
| 241 | cp *.cfg "$logdir"/ |
| 242 | |
| 243 | echo |
| 244 | echo enter name to save log |
| 245 | read log_name |
| 246 | if [ -n "$log_name" ]; then |
| 247 | newlogdir="log/$log_name" |
| 248 | #scp "bts:/tmp/{bts,pcu}.log" "bts:neels/osmo-{bts,pcu}.cfg" "$logdir" |
| 249 | else |
| 250 | newlogdir="autolog/log_$(date +%Y-%m-%d_%H-%M-%S)" |
| 251 | fi |
| 252 | mkdir -p "$(dirname "$newlogdir")" |
| 253 | |
| 254 | mergecap -w "$logdir/trace.pcap" "$logdir/"*.single.pcap && rm -f "$logdir/"*.single.pcap |
| 255 | |
| 256 | if [ -x "$newlogdir" ]; then |
| 257 | echo "already exists, move it manually: $newlogdir" |
| 258 | else |
| 259 | echo mv "$logdir" "$newlogdir" |
| 260 | mv "$logdir" "$newlogdir" |
| 261 | mkdir -p "$logdir" |
| 262 | logdir="$newlogdir" |
| 263 | fi |
| 264 | rm lastlog |
| 265 | ln -s "$logdir" lastlog |