puppet/modules/rhizo_base/templates/rccn-functions.sh.erb
Keith Whyte 983453313d Add shell vty helper
Yet another vty helper that opens vtys in tmux - this one
is more related to PS service.
2023-07-18 23:32:53 +02:00

358 lines
10 KiB
Text

#
# Shell Functions for Rhizomatica Community Celular Network
#
OSMO_STACK="split"
OSMO_HLR_OLD="/var/lib/osmocom/hlr.sqlite3"
OSMO_HLR="<%= @hlr_db %>"
OSMO_SMS="<%= @sms_db %>"
DID="<%= @voip_did %>"
_get_vty_ctrl_ip() {
if [ "$1" == "" ]; then
echo "127.0.0.1"
else
echo "127.0.0.$(($1+1))"
fi
}
waitfor0calls () {
while (( $((`fs_cli -x "show calls count" | awk '$1{print $1}'`)) > 0 ))
do
sleep 1
done
}
chans ()
{
while [ 1 == 1 ]; do
_output=`fs_cli -x 'show channels as delim |' | csvcut -d\| -c 3,2,6,8,10,11,13,15,18 | csvlook -I`;
clear;
echo "$_output";
sleep 1;
done
}
topcalls () {
while [ 1 == 1 ]
do
clear
fs_cli -x "show calls" \
| gawk -F, '!/uuid/ && !/^$/ && !/total/ { printf "\033[34;1m" $8 "("$28") \033[0m \033[200D\033[25C calls \033[32;1m "$10"("$30") \033[0m \033[200D\033[60C for %02d:%02d:%02d \033[200D\033[80C \033[31;1m Call State: "$6"/"$13"/"$33 "\n",(systime()-$4)/60/60%24,(systime()-$4)/60%60,(systime()-$4)%60 }' \
| sed "s/$DID/DID/g" \
| sort -r -k5
echo "show lchan " | nc -q1 localhost 4242 | awk 'BEGIN { RS = "BTS"; FS = "\n" } /TCH/ {print $7"\t\t\t\t BTS"$1} '
sleep $1
done
}
hlr() {
sudo /usr/bin/sqlite3 -column -header $OSMO_HLR
}
hlr2() {
sudo /usr/bin/sqlite3 -column -header $OSMO_HLR_OLD
}
sms() {
sudo /usr/bin/sqlite3 -column -header $OSMO_SMS
}
tl() {
if [ "$1" == "" ] ; then
tail -f /var/log/rccn/*log
else
less -RS +F /var/log/rccn/$1.log
fi
}
r() {
sudo -i bash -c "cd /var/rhizomatica/rccn; exec bash --login"
}
o() {
sudo -i bash -c "cd /etc/osmocom; exec bash --login"
}
f() {
tmux has-session -t SIP 2>/dev/null
if [ $? -eq 0 ] ; then
tmux a -t SIP
return
fi
tmux new-session -s SIP "sudo sngrep -d any" \; splitw -p 60 "fs_cli -r" \; select-window -t SIP \;
}
check_trx() {
echo "show trx" | nc -q1 localhost 4242 | awk 'BEGIN { RS="TRX"; } /OK/ { print "BTS"$4" TRX"$1": OK"; }'
}
<% @bts.each_with_index do |bts, index| -%>
b<%= index %>() {
ssh -t -o StrictHostKeyChecking=no <%= @bts_user[bts["model"]] %><%= bts["ip"] %> $*
}
<% end -%>
vt ()
{
tmux has-session -t vtys 2>/dev/null
if [ $? -eq 0 ] ; then
tmux a -t vtys
return
fi
tmux start-server;
tmux new -s vtys -d -n VTY "vty bsc $*";
for vty in msc mgw hlr;
do
if [ "$vty" == "msc" ]; then
pane=0;
fi;
if [ "$vty" == "hlr" ]; then
pane=2;
fi;
if [ "$vty" == "mgw" -o "$vty" == "hlr" ]; then
split=h;
else
split=v;
fi;
tmux split-window -t $pane -$split "vty $vty $*";
done;
tmux select-pane -t:.0
tmux attach -t vtys ;
}
vtps ()
{
tmux has-session -t vty_ps 2> /dev/null;
if [ $? -eq 0 ]; then
tmux a -t vty_ps
return;
fi;
tmux start-server;
tmux new -s vty_ps -d -n VTY;
for vty in msc sg hlr;
do
if [ "$vty" == "msc" ]; then
pane=0;
fi;
if [ "$vty" == "hlr" ]; then
pane=2;
fi;
if [ "$vty" == "sg" -o "$vty" == "hlr" ]; then
split=h;
else
split=v;
fi;
tmux split-window -t $pane -$split "vty $vty $*";
done;
tmux select-pane -t:.0;
tmux send "b0 /usr/local/bin/pcu" C-m
tmux select-pane -t:.1;
tmux send "show mm-context all" C-m
tmux select-pane -t:.2;
tmux send "show subscriber cache" C-m
tmux select-pane -t:.3;
tmux send "show subscribers last-seen" C-m
tmux select-pane -t:.0;
tmux send "show ms all" C-m
tmux attach -t vty_ps
}
bA() {
source /home/rhizomatica/bin/vars.sh
tmux has-session -t bts 2>/dev/null
if [ $? -eq 0 ] ; then
tmux a -t bts
return
fi
tmux start-server
tmux new -s bts -d -n BTS0 "source /etc/profile.d/rccn-functions.sh ; b0 $*"
# This won't look great for more than 4 windows, but
# that is not a lot of space anyway.
pane=0
for bts in "${!BTS[@]}" ; do
if [ $bts == 0 ] ; then continue; fi
if [ $bts == 3 ] ; then
pane=2;
fi
if [ $bts -lt 2 ] ; then
split=h
else
split=v
fi
tmux split-window -t $pane -$split "source /etc/profile.d/rccn-functions.sh ; b$bts $*"
done
tmux attach -t bts
}
pdp () {
expect -c 'spawn -noecho telnet 0 4245; expect >; send enable\r; expect #; send "show pdp-context all\r"; expect #' | grep "PDP Address" | grep -v invalid | sort -t. -n -k3,3n -k4,4n;
echo Count: $(pdpc)
}
pdpc () {
expect -c 'spawn -noecho telnet 0 4245; expect >; send enable\r; expect #; send "show pdp-context all\r"; expect #' | grep "PDP Address" | grep -v invalid | wc -l
}
mmc () {
expect -c 'spawn -noecho telnet 0 4245; expect >; send enable\r; expect #; send "show mm-context all\r"; expect #' | grep IMEI | wc -l
}
ns () {
expect -c 'spawn -noecho telnet 0 4245; expect >; send enable\r; expect #; send "show ns\r"; expect #' | grep NSEI | grep ALIVE;
}
mgwc () {
echo -n "VI: "
expect -c 'spawn -noecho telnet 0 4243; expect >; send enable\r; expect #; send "show mgcp active\r"; expect #' | egrep 'Virtual.*endpoint ' | wc -l
echo -n "E1: "
expect -c 'spawn -noecho telnet 0 4243; expect >; send enable\r; expect #; send "show mgcp active\r"; expect #' | egrep 'E1.*endpoint ' | wc -l;
expect -c 'spawn -noecho telnet 0 4243; expect >; send enable\r; expect #; send "show mgcp\r"; expect #' \
| egrep 'E1.*endpoint ' | nl -v0 | grep su16 | awk '{printf( "%x", $1) ; print $0}' > /tmp/list
expect -c 'spawn -noecho telnet 0 4243; expect >; send enable\r; expect #; send "show mgcp active\r"; expect #' | grep 'E1.*endpoint '\
| awk '{ cmd ="grep "$5" /tmp/list" ; cmd | getline res ; print res} '
}
trx ()
{
echo "show trx" | nc -q1 0 4242 | egrep '( |Carrier) NM State.*OK' | wc -l
}
lc () {
_h=`_get_vty_ctrl_ip $1`
expect -c 'set h '$_h'; spawn -noecho telnet $h 4242; expect >; send enable\r; expect #; send "show lchan summary\r"; expect #' | grep TCH
}
rotate_e1_pcap () {
_suf=`date +%H_%M_%S`
expect -c 'set file '$_suf'; spawn telnet localhost 4242; expect ">"; send "enable\r"; expect "#"; send "configure terminal\r"; expect "#";
send "e1_input\r"; expect "#"; send "e1_line 0 pcap /root/cap/abis.$file\r"; expect "#";
send "exit \r"; expect "#"; send "exit\r"; expect "#"'
}
pp () {
ps awxf | grep [p]ython
}
op () {
ps awxf | grep [o]smo\-
}
ho () {
if [ $# -lt 5 ] ; then
echo "BTS TRX TS SS BTS"
return
fi
expect -c 'set bts '$1'; set trx '$2'; set ts '$3'; set ss '$4'; set dst '$5'; spawn telnet localhost 4242; expect ">"; send "enable\r"; expect "#";
send "bts $bts trx $trx timeslot $ts sub-slot $ss handover $dst\r"; expect "#";
send "exit\r"; expect "#";';
}
lock () {
if [ "$1" == "" ] ; then
echo "BTS #?"
return
fi
expect -c 'set bts '$1'; spawn telnet localhost 4242; expect ">"; send "enable\r"; expect "#"; send "configure terminal\r"; expect "#";
send "network\r"; expect "#"; send "bts $bts\r"; expect "#"; send "trx 0\r"; expect "#"; send "rf_locked 1\r";
expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"';
}
unlock () {
if [ "$1" == "" ] ; then
echo "BTS #?"
return
fi
expect -c 'set bts '$1'; spawn telnet localhost 4242; expect ">"; send "enable\r"; expect "#"; send "configure terminal\r"; expect "#";
send "network\r"; expect "#"; send "bts $bts\r"; expect "#"; send "trx 0\r"; expect "#"; send "rf_locked 0\r";
expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"';
}
bar ()
{
if [ "$1" == "" ]; then
echo "BTS #?";
return;
fi;
_h=`_get_vty_ctrl_ip $2`
expect -c 'set bts '$1'; set h '$_h' ; spawn telnet $h 4242; expect ">"; send "enable\r"; expect "#"; send "configure terminal\r"; expect "#";
send "network\r"; expect "#"; send "bts $bts\r"; expect "#"; send "cell barred 1\r"; expect "#"; send "exit \r";
expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"; send "bts $bts resend-system-information\r"; expect "#"; send "exit\r"; expect "#"'
}
unbar ()
{
if [ "$1" == "" ]; then
echo "BTS #?";
return;
fi;
_h=`_get_vty_ctrl_ip $2`
expect -c 'set bts '$1'; set h '$_h' ; spawn telnet $h 4242; expect ">"; send "enable\r"; expect "#"; send "configure terminal\r"; expect "#";
send "network\r"; expect "#"; send "bts $bts\r"; expect "#"; send "cell barred 0\r"; expect "#"; send "exit \r";
expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"; send "bts $bts resend-system-information\r"; expect "#"; send "exit\r"; expect "#"'
}
red ()
{
if [ "$1" == "" ]; then
echo "BTS #?";
return;
fi;
if [ "$2" == "" ]; then
echo "Power Reduction?";
return;
fi;
expect -c 'set bts '$1'; set red '$2'; spawn telnet localhost 4242; expect ">"; send "enable\r"; expect "#"; send "configure terminal\r"; expect "#";
send "network\r"; expect "#"; send "bts $bts\r"; expect "#"; send "trx 0\r"; expect "#"; send "max_power_red $red\r";
expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"; send "exit\r"; expect "#"'
}
smsq-max()
{
if [ "$1" == "" ]; then
echo "Set max-pending to what?";
return;
fi;
expect -c 'set queue '$1'; set port 4254; spawn telnet localhost $port; expect ">"; send "enable\r"; expect "#"; send "sms-queue max-pending $queue\r"; expect "#";
send "sms-queue trigger\r"; expect "#";'
}
remote-bts() {
if [ "$1" == "" ]; then
ip route add 172.16.0.99 src 172.16.0.1 via 10.23.100.21 dev rhizomatica
else
ip route del 172.16.0.99
fi
}
amr_modes() {
if [ "$1" == "" ]; then
echo "Need Interface"
return;
fi
tshark -i $1 -o rtp.heuristic_rtp:TRUE -o amr.dynamic.payload.type:98 \
-T fields -e ip.src -e ip.dst -e amr.nb.toc.ft -e amr.nb.cmr \
-f 'udp and not port 23000 and not port 8125'
}
cap_abis() {
if [ "$1" == "" ]; then
echo "Need Interface"
return;
fi
mkdir -p /var/pcap
cd /var/pcap
/usr/sbin/tcpdump -ni $1 -G 600 -w 'abis.%H_%M_%S.pcap' portrange 3002-3003
}
cap_mgw() {
mkdir -p /var/pcap
cd /var/pcap
/usr/sbin/tcpdump -ni lo -G 600 -w 'mgw-lo.%H_%M_%S.pcap' port 2427 or portrange 4002-8001
}
cap_A() {
mkdir -p /var/pcap
cd /var/pcap
/usr/sbin/tcpdump -ni lo -G 600 -w 'A-lo.%H_%M_%S.pcap' port 2905
}