Browse Source

- some cleanup in existing tests
- add more tests:
12 - script with PVs, transformations and xlog
13 - carrierroute with db
14 - carrierroute with config file


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

Henning Westerholt 18 years ago
parent
commit
676425728b
9 changed files with 475 additions and 36 deletions
  1. 43 34
      test/unit/11.cfg
  2. 107 0
      test/unit/12.cfg
  3. 48 0
      test/unit/12.sh
  4. 76 0
      test/unit/13.sh
  5. 34 0
      test/unit/14.cfg
  6. 66 0
      test/unit/14.sh
  7. 0 1
      test/unit/6.sh
  8. 1 1
      test/unit/7.sh
  9. 100 0
      test/unit/carrierroute.cfg

+ 43 - 34
test/unit/11.cfg

@@ -1,7 +1,7 @@
 # ----------- global configuration parameters ------------------------
 # ----------- global configuration parameters ------------------------
-debug=9            # debug level (cmd line: -dddddddddd)
+debug=3
 fork=yes
 fork=yes
-log_stderror=no    # (cmd line: -E)
+log_stderror=no
 children=1
 children=1
 disable_tcp=yes
 disable_tcp=yes
 
 
@@ -23,39 +23,48 @@ loadmodule "registrar/registrar.so"
 #-------------------------  request routing logic -------------------
 #-------------------------  request routing logic -------------------
 route{
 route{
 
 
-        if (!method=="REGISTER")
-                record_route();
-
-        if (loose_route()) {
-                # mark routing logic in request
-                append_hf("P-hint: rr-enforced\r\n");
-                route(1);
-        };
-
-        if (!uri==myself) {
-                append_hf("P-hint: outbound\r\n");
-                route(1);
-        };
-
-        if (uri==myself) {
-                if (method=="REGISTER") {
-                        save("location");
-                        exit;
-                };
-                if (!lookup("location")) {
-                        sl_send_reply("404", "Not Found");
-                        exit;
-                };
-                append_hf("P-hint: usrloc applied\r\n");
-        };
-
-        route(1);
-}
+	if (!mf_process_maxfwd_header("10")) {
+		sl_send_reply("483","Too Many Hops");
+		exit;
+	}
+
+	if (msg:len >=  2048 ) {
+		sl_send_reply("513", "Message Too Large");
+		exit;
+	}
+
+	if (!method=="REGISTER")
+		record_route();
+
+	if (loose_route()) {
+		# mark routing logic in request
+		append_hf("P-hint: rr-enforced\r\n");
+		route(1);
+	}
 
 
+	if (!uri==myself) {
+		append_hf("P-hint: outbound\r\n");
+		route(1);
+	}
+
+	if (uri==myself) {
+		if (method=="REGISTER") {
+			save("location");
+			exit;
+		}
+		if (!lookup("location")) {
+			sl_send_reply("404", "Not Found");
+			exit;
+		}
+		append_hf("P-hint: usrloc applied\r\n");
+	}
+
+	route(1);
+}
 
 
 route[1] {
 route[1] {
-        if (!t_relay()) {
-                sl_reply_error();
-        };
-        exit;
+	if (!t_relay()) {
+	sl_reply_error();
+	}
+	exit;
 }
 }

+ 107 - 0
test/unit/12.cfg

@@ -0,0 +1,107 @@
+mpath="../modules/"
+loadmodule "mysql/mysql.so"
+loadmodule "sl/sl.so"
+loadmodule "tm/tm.so"
+loadmodule "rr/rr.so"
+loadmodule "maxfwd/maxfwd.so"
+loadmodule "textops/textops.so"
+loadmodule "xlog/xlog.so"
+loadmodule "usrloc/usrloc.so"
+loadmodule "registrar/registrar.so"
+loadmodule "mi_fifo/mi_fifo.so"
+modparam("mi_fifo", "fifo_name", "/tmp/openser_fifo")
+
+avp_aliases="identity_user=i:81"
+avp_aliases="identity_domain=i:82"
+avp_aliases="identity_uri=i:83"
+
+route{
+	xlog("received by openser[$pp] at '$Tf' from $si:$sp, method: $rm, transport: $rP:$Ri:$rp, user agent: $ua");
+
+	if !(route(39)) {
+		xlog("L_ERR", "Error getting identity");
+		exit;
+	}
+	xlog("L_ERR", "My identity: $avp(identity_uri)\n");
+
+	if (!method=="REGISTER")
+		record_route();
+
+	if (loose_route()) {
+		# mark routing logic in request
+		append_hf("P-hint: rr-enforced\r\n");
+		route(1);
+	};
+
+	if (!uri==myself) {
+		append_hf("P-hint: outbound\r\n");
+		route(1);
+	};
+	xlog("From header tag: $(hdr(From){param.value,tag})");
+	
+	if(is_method("REGISTER")) {
+		if(is_present_hf("Expires")) {
+			xlog("Expires header field present");
+			if($(hdr(Expires){s.int}) > 0) {
+				xlog("this is an registration\n");
+			}
+			if($(hdr(Expires){s.int}) == 0) {
+				xlog("this is an unregistration\n");
+			}
+		}
+		if(is_present_hf("Contact")) {
+			xlog("Contact header field present");
+			if ($(hdr(Contact){param.value,expires}{s.int}) > 0) {
+				xlog("this is an registration\n");
+			}
+			if ($(ct{param.value,expires}{s.int}) == 0) {
+				xlog("this is an unregistration\n");
+			}
+		}
+	}
+
+	if (uri==myself) {
+		if (method=="REGISTER") {
+		save("location");
+		exit;
+		}
+		if (!lookup("location")) {
+			sl_send_reply("404", "Not Found");
+			exit;
+		}
+		append_hf("P-hint: usrloc applied\r\n");
+	}
+
+	route(1);
+}
+
+route[1] {
+	if (!t_relay()) {
+		sl_reply_error();
+	}
+	exit;
+}
+
+route[39] {
+	if ($ai) {
+		$avp(identity_user)=$(ai{uri.user});
+		$avp(identity_domain)=$(ai{uri.domain});
+		$avp(identity_uri)=$ai;
+		xlog("L_ERR", "Getting identity from P-Asserted-Identity header\n");
+	} else if ($pu) {
+		$avp(identity_user)=$(pu{uri.user});
+		$avp(identity_domain)=$(pu{uri.domain});
+		$avp(identity_uri)=$pu;
+		xlog("L_ERR", "Getting identity from P-Preferred-Identity header\n");
+	} else if ($fu) {
+		$avp(identity_user)=$(fu{uri.user});
+		$avp(identity_domain)=$(fu{uri.domain});
+		$avp(identity_uri)=$fu;
+		xlog("L_ERR", "Getting identity from FROM URI\n");
+	} else {
+		xlog("L_ERR", "No identity for $rm: $fu -> $ru\n");
+		return(-1);
+	}
+
+	return (1);
+}

+ 48 - 0
test/unit/12.sh

@@ -0,0 +1,48 @@
+#!/bin/bash
+# configuration with pseudo-variables, transformations and xlog output
+
+# needs the netcat utility to run
+
+CFG=12.cfg
+
+which nc > /dev/null
+ret=$?
+
+if [ ! $? -eq 0 ] ; then
+	echo "netcat not found, not run"
+	exit 0
+fi ;
+
+../openser -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+
+# register a user
+cat register.sip | nc -q 1 -u localhost 5060 > /dev/null
+
+cd ../scripts
+
+if [ "$ret" -eq 0 ] ; then
+	./openserctl ul show | grep "AOR:: 1000" > /dev/null
+	ret=$?
+fi ;
+
+# unregister the user
+cat ../test/unregister.sip | nc -q 1 -u localhost 5060 > /dev/null
+
+if [ "$ret" -eq 0 ] ; then
+	./openserctl ul show | grep "AOR:: 1000" > /dev/null
+	ret=$?
+	if [ "$ret" -eq 0 ] ; then
+		ret=1
+	else
+		ret=0
+	fi ;
+fi ;
+
+cd ../test
+
+killall -9 openser
+
+exit $ret

+ 76 - 0
test/unit/13.sh

@@ -0,0 +1,76 @@
+#!/bin/bash
+# loads a carrierroute config for loadbalancing from database
+
+CFG=14.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 \"mysql/mysql.so\"" >> $CFG
+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');"
+
+../openser -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+
+cd ../scripts
+
+TMPFILE=`mktemp -t openser-test.XXXXXXXXXX`
+
+if [ "$ret" -eq 0 ] ; then
+	./openserctl fifo cr_dump_routes > $TMPFILE
+	ret=$?
+fi ;
+
+if [ "$ret" -eq 0 ] ; then
+	tmp=`grep -v "Printing routing information:
+Printing tree for carrier carrier1 (1)
+Printing tree for domain 0
+        42: 70.140 %, 'host4.local': ON, '0', '', '', ''
+        42: 30.060 %, 'host3.local': ON, '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 carrier default (2)
+Printing tree for domain 0
+      NULL: 100.000 %, 'host6.local': ON, '0', '', '', ''" $TMPFILE`
+	if [ "$tmp" = "" ] ; then
+		ret=0
+	else
+		ret=1
+	fi ;
+fi ;
+
+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;"
+
+cd ../test
+
+mv $CFG.bak $CFG
+rm $TMPFILE
+
+exit $ret

+ 34 - 0
test/unit/14.cfg

@@ -0,0 +1,34 @@
+mpath="../modules"
+loadmodule "sl/sl.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")
+
+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;
+	};
+	if (method == "REGISTER") {
+		if!(cr_rewrite_uri("register", "call_id")) {
+			sl_send_reply("403", "Not allowed");
+		}
+		sl_send_reply("200", "OK");
+		return;
+	}
+	if (method == "INVITE") {
+		if!(cr_rewrite_uri("proxy", "call_id")) {
+			sl_send_reply("403", "Not allowed");
+		}
+		sl_send_reply("100", "Trying");
+		return;
+	}
+}

+ 66 - 0
test/unit/14.sh

@@ -0,0 +1,66 @@
+#!/bin/bash
+# loads a carrierroute config for loadbalancing from config file
+
+CFG=14.cfg
+
+if [ ! -e ../modules/carrierroute/carrierroute.so ] ; then
+	echo "carrierroute not found, not run"
+	exit 0
+fi ;
+
+cp $CFG $CFG.bak
+
+# setup config
+echo "modparam(\"carrierroute\", \"config_file\", \"`pwd`/../test/carrierroute.cfg\")" >> $CFG
+
+../openser -f $CFG > /dev/null
+ret=$?
+
+sleep 1
+
+cd ../scripts
+
+TMPFILE=`mktemp -t openser-test.XXXXXXXXXX`
+
+if [ "$ret" -eq 0 ] ; then
+	./openserctl fifo cr_dump_routes > $TMPFILE
+	ret=$?
+fi ;
+
+if [ "$ret" -eq 0 ] ; then
+	tmp=`grep -v "Printing routing information:
+Printing tree for carrier default (1)
+Printing tree for domain register
+      NULL: 0.000 %, 'test1': OFF, '0', '', '', ''
+      NULL: 50.000 %, 'test2.localdomain': ON, '0', '', '', ''
+      NULL: 50.000 %, 'test3.localdomain': ON, '0', '', '', ''
+Printing tree for domain proxy
+         2: 87.610 %, 'test7.localdomain': ON, '0', '', '', ''
+         2: 12.516 %, 'test8.localdomain': ON, '0', '', '', ''
+        42: 70.070 %, 'test4': ON, '0', '', '', ''
+        42: 20.020 %, 'test5.localdomain': ON, '0', '', '', ''
+        42: 10.010 %, 'test6.localdomain': ON, '0', '', '', ''
+        49: 0.000 %, 'test5.localdomain': OFF, '0', '', '', ''
+        49: 44.444 %, 'test4': ON, '0', '', '', ''
+        49: 55.556 %, 'test6.localdomain': ON, '0', '', '', ''
+Printing tree for domain other
+      NULL: 0.000 %, 'test1': OFF, '0', '', '', ''
+      NULL: 50.000 %, 'test2.localdomain': OFF, '0', '', '', ''
+            Rule is backed up by: test3.localdomain
+      NULL: 50.000 %, 'test3.localdomain': ON, '0', '', '', ''
+            Rule is backup for: test2.localdomain" $TMPFILE`
+	if [ "$tmp" = "" ] ; then
+		ret=0
+	else
+		ret=1
+	fi ;
+fi ;
+
+killall -9 openser
+
+cd ../test
+
+mv $CFG.bak $CFG
+rm -f $TMPFILE
+
+exit $ret

+ 0 - 1
test/unit/6.sh

@@ -8,6 +8,5 @@ CFG=2.cfg
 ret=$?
 ret=$?
 
 
 sleep 1
 sleep 1
-killall -9 openser
 
 
 exit $ret
 exit $ret

+ 1 - 1
test/unit/7.sh

@@ -1,5 +1,5 @@
 #!/bin/bash
 #!/bin/bash
-# loads a SIP Proxy/Registrar config with Offnet-Termination and Accounting
+# loads a SIP proxy/registrar config with offnet-termination and accounting
 
 
 # config generated by sipwise wizard
 # config generated by sipwise wizard
 
 

+ 100 - 0
test/unit/carrierroute.cfg

@@ -0,0 +1,100 @@
+domain register {
+	prefix NULL {
+		max_targets = 3
+
+		target test1 {
+			prob = 0.400000
+			hash_index = 3
+			status = 0
+		}
+		target test3.localdomain {
+			prob = 0.500000
+			hash_index = 2
+			status = 1
+		}
+		target test2.localdomain {
+			prob = 0.500000
+			hash_index = 1
+			status = 1
+		}
+	}
+}
+
+domain proxy {
+	prefix 2 {
+		max_targets = 2
+
+		target test8.localdomain {
+			prob = 0.100000
+			hash_index = 2
+			status = 1
+		}
+		target test7.localdomain {
+			prob = 0.700000
+			hash_index = 1
+			status = 1
+		}
+	}
+	prefix 42 {
+		max_targets = 3
+
+		target test6.localdomain {
+			prob = 0.100000
+			hash_index = 2
+			status = 1
+		}
+		target test5.localdomain {
+			prob = 0.200000
+			hash_index = 1
+			status = 1
+		}
+		target test4 {
+			prob = 0.700000
+			hash_index = 3
+			status = 1
+		}
+	}
+	prefix 49 {
+		max_targets = 3
+
+		target test6.localdomain {
+			prob = 0.500000
+			hash_index = 3
+			status = 1
+		}
+		target test5.localdomain {
+			prob = 0.500000
+			hash_index = 1
+			status = 0
+		}
+		target test4 {
+			prob = 0.400000
+			hash_index = 2
+			status = 1
+		}
+	}
+}
+
+domain other {
+	prefix NULL {
+		max_targets = 3
+
+		target test1 {
+			prob = 0.400000
+			hash_index = 3
+			status = 0
+		}
+		target test3.localdomain {
+			prob = 0.500000
+			hash_index = 2
+			status = 1
+			backed_up = {1}
+		}
+		target test2.localdomain {
+			prob = 0.500000
+			hash_index = 1
+			status = 0
+			backup = 2
+		}
+	}
+}