소스 검색

- update test 13 with some carrierfailureroute data
- add a new test that exercise some simple routing


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@3812 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt 17 년 전
부모
커밋
c7e02d5c9c
3개의 변경된 파일188개의 추가작업 그리고 12개의 파일을 삭제
  1. 42 12
      test/unit/13.sh
  2. 43 0
      test/unit/26.cfg
  3. 103 0
      test/unit/26.sh

+ 42 - 12
test/unit/13.sh

@@ -35,17 +35,33 @@ echo "modparam(\"carrierroute\", \"config_source\", \"db\")" >> $CFG
 # setup database
 MYSQL="mysql openser -u openser --password=openserrw -e"
 
-$MYSQL "insert into openser.route_tree (id, carrier) values ('1', 'carrier1');"
-$MYSQL "insert into openser.route_tree (id, carrier) values ('2', 'default');"
-
-$MYSQL "insert into openser.carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('1','1','49','0','0.5','0','host1.local');"
-$MYSQL "insert into openser.carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('2','1','49','0','0.5','0','host2.local');"
-$MYSQL "insert into openser.carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('3','1','42','0','0.3','0','host3.local');"
-$MYSQL "insert into openser.carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('4','1','42','0','0.7','0','host4.local');"
-$MYSQL "insert into openser.carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('5','1','','0','0.1','0','host5.local');"
-$MYSQL "insert into openser.carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('6','2','','0','1','0','host6.local');"
+$MYSQL "insert into route_tree (id, carrier) values ('1', 'carrier1');"
+$MYSQL "insert into route_tree (id, carrier) values ('2', 'default');"
+$MYSQL "insert into route_tree (id, carrier) values ('3', 'carrier2');"
+
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('1','1','0','49','0.5','0','host1.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('2','1','0','49','0.5','0','host2.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('3','1','0','42','0.3','0','host3.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('4','1','0','42','0.7','0','host4.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('5','1','0','','0.1','0','host5.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('6','1','1','','0.1','0','host5.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('7','1','2','','0.1','0','host5.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('8','2','0','','1','0','host6.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('9','2','1','','1','0','host6.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('10','2','2','','1','0','host6.local');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('11','3','0','','1','0','host1.local');"
+
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code, flags,
+mask, next_domain) values ('1', '1', '1', '49', 'host1.local', '404', '', '', '2');"
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code, flags,
+mask, next_domain) values ('2', '1', '1', '49', 'host1.local', '4..', '', '', '3');"
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code, flags,
+mask, next_domain) values ('3', '2', '1', '49', 'host1.local', '503', '', '', '2');"
+$MYSQL "insert into carrierfailureroute(id, carrier, domain, scan_prefix, host_name, reply_code, flags,
+mask, next_domain) values ('4', '2', '2', '49', 'host1.local', '5..', '', '', '3');"
 
 ../openser -w . -f $CFG > /dev/null
+
 ret=$?
 
 sleep 1
@@ -68,9 +84,18 @@ Printing tree for domain 0
         49: 50.000 %, 'host2.local': ON, '0', '', '', ''
         49: 50.000 %, 'host1.local': ON, '0', '', '', ''
       NULL: 100.000 %, 'host5.local': ON, '0', '', '', ''
+Printing tree for domain 1
+      NULL: 100.000 %, 'host5.local': ON, '0', '', '', ''
+Printing tree for domain 2
+      NULL: 100.000 %, 'host5.local': ON, '0', '', '', ''
 Printing tree for carrier default (2)
 Printing tree for domain 0
-      NULL: 100.000 %, 'host6.local': ON, '0', '', '', ''" $TMPFILE`
+      NULL: 100.000 %, 'host6.local': ON, '0', '', '', ''
+Printing tree for domain 1
+      NULL: 100.000 %, 'host6.local': ON, '0', '', '', ''
+Printing tree for carrier carrier2 (3)
+Printing tree for domain 0
+      NULL: 100.000 %, 'host1.local': ON, '0', '', '', ''" $TMPFILE`
 	if [ "$tmp" = "" ] ; then
 		ret=0
 	else
@@ -83,8 +108,13 @@ killall -9 openser
 # cleanup database
 $MYSQL "delete from route_tree where id = 1;"
 $MYSQL "delete from route_tree where id = 2;"
-$MYSQL "delete from openser.carrierroute where carrier=1;"
-$MYSQL "delete from openser.carrierroute where carrier=2;"
+$MYSQL "delete from route_tree where id = 3;"
+$MYSQL "delete from carrierroute where carrier=1;"
+$MYSQL "delete from carrierroute where carrier=2;"
+$MYSQL "delete from carrierroute where carrier=3;"
+$MYSQL "delete from carrierfailureroute where carrier=1;"
+$MYSQL "delete from carrierfailureroute where carrier=2;"
+$MYSQL "delete from carrierfailureroute where carrier=3;"
 
 cd ../test
 

+ 43 - 0
test/unit/26.cfg

@@ -0,0 +1,43 @@
+debug=3
+mpath="../modules"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "xlog/xlog.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "carrierroute/carrierroute.so"
+loadmodule "mi_fifo/mi_fifo.so"
+
+modparam("mi_fifo", "fifo_name", "/tmp/openser_fifo")
+
+avp_aliases="domain=s:10"
+avp_aliases="carrier=s:11"
+avp_aliases="host=s:12"
+
+route{
+	# initial sanity checks
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		return;
+	}
+	if (msg:len >  max_len) {
+		sl_send_reply("513", "Message too big");
+		return;
+	}
+	# user route
+	if(cr_user_carrier("$rU", "$rd", "$avp(carrier)")) {
+		$avp(domain)="0";
+		if (!cr_route("$avp(carrier)", "$avp(domain)", "$rU", "$rU", "call_id", "$avp(host)")) {
+			xlog("L_ERR", "cr_route failed\n");
+			exit;
+		}
+	} else {
+	# default route
+		if (!cr_route("default", "0", "$rU", "$rU", "call_id")) {
+			xlog("L_ERR", "cr_route failed\n");
+			exit;
+		}
+	}
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+}

+ 103 - 0
test/unit/26.sh

@@ -0,0 +1,103 @@
+#!/bin/bash
+# loads a carrierroute config for loadbalancing from mysql database
+
+# Copyright (C) 2007 1&1 Internet AG
+#
+# This file is part of openser, a free SIP server.
+#
+# openser is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version
+#
+# openser is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+
+CFG=26.cfg
+
+if [ ! -e ../modules/carrierroute/carrierroute.so ] ; then
+	echo "carrierroute not found, not run"
+	exit 0
+fi ;
+
+cp $CFG $CFG.bak
+
+# setup config
+echo "loadmodule \"db_mysql/db_mysql.so\"" >> $CFG
+echo "modparam(\"carrierroute\", \"config_source\", \"db\")" >> $CFG
+
+# setup database
+MYSQL="mysql openser -u openser --password=openserrw -e"
+
+$MYSQL "insert into route_tree (id, carrier) values ('1', 'default');"
+$MYSQL "insert into route_tree (id, carrier) values ('2', 'carrier1');"
+$MYSQL "insert into route_tree (id, carrier) values ('3', 'carrier2');"
+
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('1','1','0','49','0.5','0','127.0.0.1:7000');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('2','1','0','49','0.5','0','127.0.0.1:8000');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('3','2','0','49','1','0','127.0.0.1:9000');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('4','3','0','49','1','0','127.0.0.1:10000');"
+$MYSQL "insert into carrierroute (id, carrier, domain, scan_prefix, prob, strip, rewrite_host) values ('5','3','test','49','1','0','127.0.0.1:10000');"
+
+$MYSQL "alter table subscriber add cr_preferred_carrier int(10) default NULL;"
+
+$MYSQL "insert into subscriber (username, cr_preferred_carrier) values ('49721123456786', 2);"
+$MYSQL "insert into subscriber (username, cr_preferred_carrier) values ('49721123456785', 3);"
+
+
+../openser -w . -f $CFG > /dev/null
+
+ret=$?
+
+sleep 1
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -sn uas -bg -i localhost -m 10 -p 7000 &> /dev/null
+	sipp -sn uas -bg -i localhost -m 10 -p 8000 &> /dev/null
+	sipp -sn uac -s 49721123456787 127.0.0.1:5060 -i 127.0.0.1 -m 20 -p 5061 &> /dev/null
+	ret=$?
+fi;
+killall -9 sipp
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -sn uas -bg -i localhost -m 10 -p 9000 &> /dev/null
+	sipp -sn uac -s 49721123456786 127.0.0.1:5060 -i 127.0.0.1 -m 10 -p 5061 &> /dev/null
+	ret=$?
+fi;
+killall -9 sipp
+
+if [ "$ret" -eq 0 ] ; then
+	sipp -sn uas -bg -i localhost -m 10 -p 10000 &> /dev/null
+	sipp -sn uac -s 49721123456785 127.0.0.1:5060 -i 127.0.0.1 -m 10 -p 5061 &> /dev/null
+	ret=$?
+fi;
+
+killall -9 openser
+killall -9 sipp
+
+# cleanup database
+$MYSQL "delete from route_tree where id = 1;"
+$MYSQL "delete from route_tree where id = 2;"
+$MYSQL "delete from route_tree where id = 3;"
+$MYSQL "delete from carrierroute where carrier=1;"
+$MYSQL "delete from carrierroute where carrier=2;"
+$MYSQL "delete from carrierroute where carrier=3;"
+$MYSQL "delete from carrierfailureroute where carrier=1;"
+$MYSQL "delete from carrierfailureroute where carrier=2;"
+$MYSQL "delete from carrierfailureroute where carrier=3;"
+
+$MYSQL "delete from subscriber where username='49721123456786';"
+$MYSQL "delete from subscriber where username='49721123456785';"
+$MYSQL "alter table subscriber drop cr_preferred_carrier;"
+
+cd ../test
+
+mv $CFG.bak $CFG
+
+exit $ret