37.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/bash
  2. # loading times for bigger carrierroute config from mysql database
  3. # Copyright (C) 2007 1&1 Internet AG
  4. #
  5. # This file is part of Kamailio, a free SIP server.
  6. #
  7. # Kamailio is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version
  11. #
  12. # Kamailio is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program; if not, write to the Free Software
  19. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  20. source include/common
  21. source include/require
  22. source include/database
  23. CFG=13.cfg
  24. # number of routes, multiplied with 10
  25. # if you want to increase this above 4500, comment the fifo command below,
  26. # otherwise this will fails with memory allocation errors (with 1MB PKG mem)
  27. NR=450
  28. if ! (check_kamailio && check_module "carrierroute" && check_module "db_mysql" && check_mysql); then
  29. exit 0
  30. fi ;
  31. cp $CFG $CFG.bak
  32. # setup config
  33. echo "loadmodule \"db_mysql/db_mysql.so\"" >> $CFG
  34. echo "modparam(\"carrierroute\", \"config_source\", \"db\")" >> $CFG
  35. # setup database
  36. $MYSQL "insert into carrier_name (id, carrier) values ('1', 'default');"
  37. $MYSQL "insert into carrier_name (id, carrier) values ('2', 'carrier2');"
  38. $MYSQL "insert into carrier_name (id, carrier) values ('3', 'carrier3');"
  39. $MYSQL "insert into carrier_name (id, carrier) values ('4', 'carrier4');"
  40. $MYSQL "insert into carrier_name (id, carrier) values ('5', 'carrier5');"
  41. $MYSQL "insert into carrier_name (id, carrier) values ('6', 'carrier6');"
  42. $MYSQL "insert into carrier_name (id, carrier) values ('7', 'carrier7');"
  43. $MYSQL "insert into carrier_name (id, carrier) values ('8', 'carrier8');"
  44. $MYSQL "insert into carrier_name (id, carrier) values ('9', 'carrier9');"
  45. $MYSQL "insert into carrier_name (id, carrier) values ('10', 'carrier10');"
  46. $MYSQL "insert into carrier_name (id, carrier) values ('11', 'carrier11');"
  47. COUNTER=0
  48. while [ $COUNTER -lt $NR ]; do
  49. COUNTER=$(($COUNTER+1))
  50. domain=`expr $COUNTER % 9`
  51. $MYSQL "insert into domain_name (id, domain) values ('$COUNTER', '$domain');"
  52. $MYSQL "insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('2','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('3','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('4','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('5','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('6','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('7','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('8','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('9','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('10','$COUNTER','$RANDOM','0.5','0','host-$RANDOM'); insert into carrierroute (carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('11','$COUNTER','$RANDOM','0.5','0','host-$RANDOM');"
  53. done
  54. $BIN -L $MOD_DIR -Y $RUN_DIR -P $PIDFILE -m 128 -w . -f $CFG > /dev/null
  55. ret=$?
  56. # adjust if you have bigger rule sets
  57. sleep 20
  58. if [ $ret -eq 0 ] ; then
  59. tmp=`$CTL fifo cr_dump_routes | grep "host-" | wc -l`
  60. let "TMPNR = $NR * 10"
  61. if ! [ $tmp -eq $TMPNR ]; then
  62. ret=1
  63. fi;
  64. fi ;
  65. kill_kamailio
  66. # cleanup database
  67. $MYSQL "delete from carrier_name where id = 1;"
  68. $MYSQL "delete from carrier_name where id = 2;"
  69. $MYSQL "delete from carrier_name where id = 3;"
  70. $MYSQL "delete from carrier_name where id = 4;"
  71. $MYSQL "delete from carrier_name where id = 5;"
  72. $MYSQL "delete from carrier_name where id = 6;"
  73. $MYSQL "delete from carrier_name where id = 7;"
  74. $MYSQL "delete from carrier_name where id = 8;"
  75. $MYSQL "delete from carrier_name where id = 9;"
  76. $MYSQL "delete from carrier_name where id = 10;"
  77. $MYSQL "delete from carrier_name where id = 11;"
  78. COUNTER=0
  79. while [ $COUNTER -lt $NR ]; do
  80. COUNTER=$(($COUNTER+1))
  81. $MYSQL "delete from domain_name where id = $COUNTER;"
  82. done
  83. $MYSQL "delete from carrierroute where carrier=1;"
  84. $MYSQL "delete from carrierroute where carrier=2;"
  85. $MYSQL "delete from carrierroute where carrier=3;"
  86. $MYSQL "delete from carrierroute where carrier=4;"
  87. $MYSQL "delete from carrierroute where carrier=5;"
  88. $MYSQL "delete from carrierroute where carrier=6;"
  89. $MYSQL "delete from carrierroute where carrier=7;"
  90. $MYSQL "delete from carrierroute where carrier=8;"
  91. $MYSQL "delete from carrierroute where carrier=9;"
  92. $MYSQL "delete from carrierroute where carrier=10;"
  93. $MYSQL "delete from carrierroute where carrier=11;"
  94. mv $CFG.bak $CFG
  95. exit $ret