Jelajahi Sumber

Merge pull request #7 from kamailio/vseva/registrar_xavp_rcd_mask

units/tregxx0001: test for registrar module and xavp_rcd_mask
Victor Seva 5 tahun lalu
induk
melakukan
744995e5f3

+ 12 - 0
units/tregxx0001/README.md

@@ -0,0 +1,12 @@
+# Regisrar - xavp_rcd Tests #
+
+Summary: regisrar - check xavp_rcd values
+
+Following tests are done:
+
+  * run kamailio with kamailio-tregxx0001.cfg send a REGISTER msg and check the
+	xavp_rcd values depending of the xavp_rcd_mask paramater after save(), send
+	a MESSAGE msg and check xavp_rcd values depending of the xavp_rcd_mask
+	paramater after lookup().
+
+  * run that check for different values of xavp_rcd_mask

+ 1 - 0
units/tregxx0001/kamailio-tregxx0001-inc

@@ -0,0 +1 @@
+modparam("registrar", "xavp_rcd_mask", #mask#)

+ 78 - 0
units/tregxx0001/kamailio-tregxx0001.cfg

@@ -0,0 +1,78 @@
+#!KAMAILIO
+
+children=1
+
+loadmodule "kex.so"
+loadmodule "jsonrpcs.so"
+loadmodule "tm.so"
+loadmodule "tmx.so"
+loadmodule "sl.so"
+loadmodule "rr.so"
+loadmodule "pv.so"
+loadmodule "textops.so"
+loadmodule "usrloc.so"
+loadmodule "registrar.so"
+loadmodule "xlog.so"
+
+modparam("jsonrpcs", "pretty_format", 1)
+
+modparam("registrar", "xavp_rcd", "rcd")
+
+include_file "kamailio-tregxx0001-inc.cfg"
+
+request_route {
+    route(REGISTRAR);
+    route(LOCATION);
+    exit;
+}
+
+route[REGISTRAR] {
+    if (!is_method("REGISTER")) return;
+    xlog("registrar: $ru\n");
+    if (!save("location")) {
+        sl_reply_error();
+    }
+    route(CHECK);
+    exit;
+}
+
+route[LOCATION] {
+    if (!is_method("MESSAGE")) return;
+    if (!lookup("location", "sip:[email protected]:5066")) {
+        $var(rc) = $rc;
+        t_newtran();
+        switch ($var(rc)) {
+            case -1:
+            case -3:
+                send_reply("404", "Not Found");
+                exit;
+            case -2:
+                send_reply("405", "Method Not Allowed");
+                exit;
+        }
+    } else {
+        send_reply("200", "OK");
+    }
+    route(CHECK);
+    return;
+}
+
+route[CHECK] {
+    pv_xavp_print();
+    if(pv_isset("$xavp(rcd[0]=>ruid)")) {
+        xlog("check[$rm]: ruid exists\n");
+    }
+    if(pv_isset("$xavp(rcd[0]=>contact)")) {
+        xlog("check[$rm]: contact exists\n");
+    }
+    if(pv_isset("$xavp(rcd[0]=>expires)")) {
+        xlog("check[$rm]: expires exists\n");
+    }
+    if(pv_isset("$xavp(rcd[0]=>received)")) {
+        xlog("check[$rm]: received exists\n");
+    }
+    if(pv_isset("$xavp(rcd[0]=>path)")) {
+        xlog("check[$rm]: path exists\n");
+    }
+    return;
+}

+ 100 - 0
units/tregxx0001/tregxx0001.sh

@@ -0,0 +1,100 @@
+#!/bin/bash
+
+. ../../etc/config
+. ../../libs/utils
+
+LOG=/tmp/kamailio-tregxx0001.log
+
+function run() {
+	sed -e "s/#mask#/${mask}/g" ./kamailio-tregxx0001-inc > ./kamailio-tregxx0001-inc.cfg
+	echo "--- start kamailio -f ./kamailio-tregxx0001.cfg with mask $mask"
+	${KAMBIN} -P ${KAMPID} -w ${KAMRUN} -Y ${KAMRUN} \
+		-f ./kamailio-tregxx0001.cfg -a no -ddd -E 2>&1 | tee ${LOG} &
+	sleep 1
+	sipsak -U -s sip:[email protected] -C sip:[email protected]:5066
+	sipsak -M -s sip:[email protected]
+	sleep 1
+	kill_pidfile ${KAMPID}
+	sleep 1
+}
+
+function check() {
+	local val=${1}
+	local mask=${2}
+	if ! grep -q "check\\[REGISTER\\]: ${val} exists" ${LOG} ; then
+		echo "[${mask}] ${val} not found in REGISTER"
+		exit 1
+	fi
+	if ! grep -q "check\\[MESSAGE\\]: ${val} exists" ${LOG}; then
+		echo "[${mask}] ${val} not found in REGISTER"
+		exit 1
+
+	fi
+}
+
+function check_not() {
+	val=${1}
+	if grep -q "check\\[REGISTER\\]: ${val} exists" ${LOG} ; then
+		echo "[${mask}] ${val} found in REGISTER"
+		exit 1
+	fi
+	if grep -q "check\\[MESSAGE\\]: ${val} exists" ${LOG}; then
+		echo "[${mask}] ${val} found in REGISTER"
+		exit 1
+
+	fi
+}
+
+echo
+echo "--- grep output"
+echo
+
+mask=0
+run
+check ruid
+check contact
+check expires
+
+mask=1
+run
+check_not ruid
+check contact
+check expires
+
+mask=2
+run
+check ruid
+check_not contact
+check expires
+
+mask=3
+run
+check_not ruid
+check_not contact
+check expires
+
+mask=4
+run
+check ruid
+check contact
+check_not expires
+
+mask=5
+run
+check_not ruid
+check contact
+check_not expires
+
+mask=6
+run
+check ruid
+check_not contact
+check_not expires
+
+mask=7
+run
+check_not ruid
+check_not contact
+check_not expires
+
+exit 0