Răsfoiți Sursa

thacxx0005 - http_async_client suspend on reply (#19)

* thacxx0006 - re-suspend a request to perform an HTTP query
Giacomo Vacca 4 ani în urmă
părinte
comite
0279010e6b

+ 8 - 0
units/thacxx0005/README.md

@@ -0,0 +1,8 @@
+# http_aysnc_client - Re-suspend reply #
+
+Summary: http_async_client - Re-suspend reply
+
+Following tests are done:
+
+  * run kamailio with kamailio-thacxx0005.cfg and test if re-suspending a reply to perform another HTTP query works
+

+ 23 - 0
units/thacxx0005/http_server.py

@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+from http.server import BaseHTTPRequestHandler, HTTPServer
+
+class HTTPHandler(BaseHTTPRequestHandler):
+    def _set_response(self):
+        self.send_response(200)
+        self.send_header('Content-type', 'text/html')
+        self.end_headers()
+
+    def do_GET(self):
+        self._set_response()
+
+def run(server_class=HTTPServer, handler_class=HTTPHandler, port=8080):
+    server_address = ('', port)
+    httpd = server_class(server_address, handler_class)
+    try:
+        httpd.serve_forever()
+    except KeyboardInterrupt:
+        pass
+    httpd.server_close()
+
+if __name__ == '__main__':
+    run()

+ 55 - 0
units/thacxx0005/kamailio-thacxx0005.cfg

@@ -0,0 +1,55 @@
+#!KAMAILIO
+
+loadmodule "kex.so"
+loadmodule "tm.so"
+loadmodule "tmx.so"
+loadmodule "sl.so"
+loadmodule "rr.so"
+loadmodule "pv.so"
+loadmodule "xlog.so"
+loadmodule "siputils.so"
+loadmodule "textops.so"
+loadmodule "http_async_client.so"
+
+modparam("http_async_client", "workers", 4);
+
+debug=2
+children=4
+
+request_route {
+	if (is_request()) {
+		if (is_method("INVITE")) {
+			t_newtran();
+			t_on_reply("INVITE_REPLY");
+			t_relay("127.0.0.1", "5080");
+			exit;
+		}
+		else if (is_method("ACK")) {
+			t_relay("127.0.0.1", "5080");
+			exit;
+		}
+	}
+	drop;
+}
+
+onreply_route[INVITE_REPLY] {
+	xlog("L_INFO", "[$ci]================ INVITE_REPLY ==================\n");
+	if (status=~"200") {
+		http_async_query("http://127.0.0.1:8080/", "HTTP_REPLY1");
+	}
+}
+
+route[HTTP_REPLY1] {
+	xlog("L_INFO", "[$ci]================ HTTP_REPLY1 ==================\n");
+	if ($http_ok) {
+		xlog("L_INFO", "HTTP GET REPLY1: $http_rs - Response: $http_rb\n");
+		http_async_query("http://127.0.0.1:8080/", "HTTP_REPLY2");
+	}
+	else {
+		xlog("L_ERR", "HTTP error: $http_err\n");
+	}
+}
+
+route[HTTP_REPLY2] {
+	xlog("L_INFO", "[$ci]================ HTTP_REPLY2 ================== DONE\n");
+}

+ 34 - 0
units/thacxx0005/thacxx0005.sh

@@ -0,0 +1,34 @@
+#!/bin/bash
+
+. ../../etc/config
+. ../../libs/utils
+
+python3 http_server.py &
+
+echo "--- start kamailio -f ./kamailio-thacxx0005.cfg"
+${KAMBIN} -P ${KAMPID} -w ${KAMRUN} -Y ${KAMRUN} -f ./kamailio-thacxx0005.cfg -a no -dd -E 2>&1 | tee /tmp/kamailio-thacxx0005.log &
+ret=$?
+
+sleep 3
+
+echo "-------------- starting sipp UAS -------------------------"
+sipp -sf uas.xml -p 5080 -bg
+
+sleep 1
+
+NCALLS=20
+echo "-------------- starting sipp UAC -------------------------"
+sipp -sf uac.xml -m ${NCALLS} 127.0.0.1:5060
+
+kill_pidfile ${KAMPID}
+sleep 1
+killall python3
+sleep 1
+killall sipp
+
+echo
+count="$(grep -c "HTTP_REPLY2" /tmp/kamailio-thacxx0005.log)"
+if [ ! $count -eq $NCALLS ] ; then
+    exit 1
+fi
+exit 0

+ 48 - 0
units/thacxx0005/uac.xml

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<scenario name="Basic UAC scenario">
+ <send>
+  <![CDATA[  
+  INVITE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
+  Via: SIP/2.0/[transport] [local_ip]:[local_port]
+  From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]
+  To: sut <sip:[service]@[remote_ip]:[remote_port]>
+  Call-ID: [call_id]
+  Cseq: 1 INVITE
+  Contact: sip:sipp@[local_ip]:[local_port]
+  Content-Type: application/sdp
+  Content-Length: [len]
+  
+  v=0
+  o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
+  s=-
+  t=0 0
+  c=IN IP[media_ip_type] [media_ip]
+  m=audio [media_port] RTP/AVP 0
+  a=rtpmap:0 PCMU/8000
+  ]]>
+ </send>
+
+ <recv response="100" optional="true">
+ </recv>
+ 
+ <recv response="180" optional="true">
+ </recv>
+ 
+ <recv response="200">
+ </recv>
+
+ <send>
+  <![CDATA[
+  ACK sip:[service]@[remote_ip]:[remote_port] SIP/2.0
+  Via: SIP/2.0/[transport] [local_ip]:[local_port]
+  From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]
+  To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
+  Call-ID: [call_id]
+  Cseq: 1 ACK
+  Contact: sip:sipp@[local_ip]:[local_port]
+  Content-Length: 0
+  ]]>
+ </send>
+
+</scenario>
+

+ 33 - 0
units/thacxx0005/uas.xml

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<scenario name="Basic UAS scenario">
+ <recv request="INVITE">
+  
+ <!-- since SIPp complains about not used variable reference the trach var -->
+ <Reference variables="trash"/>
+
+ <send retrans="500">
+  <![CDATA[
+  SIP/2.0 200 OK
+  [last_Via:]
+  [last_From:]
+  [last_To:];tag=[pid]SIPpTag01[call_number]
+  [last_Call-ID:]
+  [last_CSeq:]
+  Contact: <sip:[local_ip]:[local_port];transport=[transport]>
+  Content-Type: application/sdp
+  Content-Length: [len]
+  
+  v=0
+  o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
+  s=-
+  c=IN IP[media_ip_type] [media_ip]
+  t=0 0
+  m=audio [media_port] RTP/AVP 0
+  a=rtpmap:0 PCMU/8000
+  ]]>
+ </send>
+
+ <recv request="ACK" optional="true" crlf="true">
+ </recv>
+
+</scenario>

+ 8 - 0
units/thacxx0006/README.md

@@ -0,0 +1,8 @@
+# http_aysnc_client - Re-suspend request #
+
+Summary: http_async_client - Re-suspend request
+
+Following tests are done:
+
+  * run kamailio with kamailio-thacxx0006.cfg and test if suspending a request twice to perform async HTTP requests works
+

+ 23 - 0
units/thacxx0006/http_server.py

@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+from http.server import BaseHTTPRequestHandler, HTTPServer
+
+class HTTPHandler(BaseHTTPRequestHandler):
+    def _set_response(self):
+        self.send_response(200)
+        self.send_header('Content-type', 'text/html')
+        self.end_headers()
+
+    def do_GET(self):
+        self._set_response()
+
+def run(server_class=HTTPServer, handler_class=HTTPHandler, port=8080):
+    server_address = ('', port)
+    httpd = server_class(server_address, handler_class)
+    try:
+        httpd.serve_forever()
+    except KeyboardInterrupt:
+        pass
+    httpd.server_close()
+
+if __name__ == '__main__':
+    run()

+ 56 - 0
units/thacxx0006/kamailio-thacxx0006.cfg

@@ -0,0 +1,56 @@
+#!KAMAILIO
+
+loadmodule "kex.so"
+loadmodule "tm.so"
+loadmodule "tmx.so"
+loadmodule "sl.so"
+loadmodule "rr.so"
+loadmodule "pv.so"
+loadmodule "xlog.so"
+loadmodule "siputils.so"
+loadmodule "textops.so"
+loadmodule "http_async_client.so"
+
+modparam("http_async_client", "workers", 4);
+
+debug=2
+children=4
+
+request_route {
+	if (is_request()) {
+		if (is_method("INVITE")) {
+			t_newtran();
+			http_async_query("http://127.0.0.1:8080/", "HTTP_REPLY1");
+		}
+		else if (is_method("ACK")) {
+			t_relay("127.0.0.1", "5080");
+			exit;
+		}
+	}
+	drop;
+}
+
+route[HTTP_REPLY1] {
+	xlog("L_INFO", "[$ci]================ HTTP_REPLY1 ==================\n");
+	if ($http_ok) {
+		xlog("L_INFO", "HTTP GET REPLY1: $http_rs - Response: $http_rb\n");
+		http_async_query("http://127.0.0.1:8080/", "HTTP_REPLY2");
+	}
+	else {
+		xlog("L_ERR", "HTTP error: $http_err\n");
+	}
+}
+
+route[HTTP_REPLY2] {
+	xlog("L_INFO", "[$ci]================ HTTP_REPLY2 ================== DONE\n");
+	t_on_reply("INVITE_REPLY");
+	t_relay("127.0.0.1", "5080");
+	exit;
+}
+
+onreply_route[INVITE_REPLY] {
+	if (status=~"200") {
+		xlog("L_INFO", "[$ci]============== INVITE_REPLY OK ================\n");
+	}
+}
+

+ 34 - 0
units/thacxx0006/thacxx0006.sh

@@ -0,0 +1,34 @@
+#!/bin/bash
+
+. ../../etc/config
+. ../../libs/utils
+
+python3 http_server.py &
+
+echo "--- start kamailio -f ./kamailio-thacxx0006.cfg"
+${KAMBIN} -P ${KAMPID} -w ${KAMRUN} -Y ${KAMRUN} -f ./kamailio-thacxx0006.cfg -a no -dd -E 2>&1 | tee /tmp/kamailio-thacxx0006.log &
+ret=$?
+
+sleep 3
+
+echo "-------------- starting sipp UAS -------------------------"
+sipp -sf uas.xml -p 5080 -bg
+
+sleep 1
+
+NCALLS=20
+echo "-------------- starting sipp UAC -------------------------"
+sipp -sf uac.xml -m ${NCALLS} 127.0.0.1:5060
+
+kill_pidfile ${KAMPID}
+sleep 1
+killall python3
+sleep 1
+killall sipp
+
+echo
+count="$(grep -c "INVITE_REPLY OK" /tmp/kamailio-thacxx0006.log)"
+if [ ! $count -eq $NCALLS ] ; then
+    exit 1
+fi
+exit 0

+ 48 - 0
units/thacxx0006/uac.xml

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<scenario name="Basic UAC scenario">
+ <send>
+  <![CDATA[  
+  INVITE sip:[service]@[remote_ip]:[remote_port] SIP/2.0
+  Via: SIP/2.0/[transport] [local_ip]:[local_port]
+  From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]
+  To: sut <sip:[service]@[remote_ip]:[remote_port]>
+  Call-ID: [call_id]
+  Cseq: 1 INVITE
+  Contact: sip:sipp@[local_ip]:[local_port]
+  Content-Type: application/sdp
+  Content-Length: [len]
+  
+  v=0
+  o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
+  s=-
+  t=0 0
+  c=IN IP[media_ip_type] [media_ip]
+  m=audio [media_port] RTP/AVP 0
+  a=rtpmap:0 PCMU/8000
+  ]]>
+ </send>
+
+ <recv response="100" optional="true">
+ </recv>
+ 
+ <recv response="180" optional="true">
+ </recv>
+ 
+ <recv response="200">
+ </recv>
+
+ <send>
+  <![CDATA[
+  ACK sip:[service]@[remote_ip]:[remote_port] SIP/2.0
+  Via: SIP/2.0/[transport] [local_ip]:[local_port]
+  From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]
+  To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]
+  Call-ID: [call_id]
+  Cseq: 1 ACK
+  Contact: sip:sipp@[local_ip]:[local_port]
+  Content-Length: 0
+  ]]>
+ </send>
+
+</scenario>
+

+ 33 - 0
units/thacxx0006/uas.xml

@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<scenario name="Basic UAS scenario">
+ <recv request="INVITE">
+  
+ <!-- since SIPp complains about not used variable reference the trach var -->
+ <Reference variables="trash"/>
+
+ <send retrans="500">
+  <![CDATA[
+  SIP/2.0 200 OK
+  [last_Via:]
+  [last_From:]
+  [last_To:];tag=[pid]SIPpTag01[call_number]
+  [last_Call-ID:]
+  [last_CSeq:]
+  Contact: <sip:[local_ip]:[local_port];transport=[transport]>
+  Content-Type: application/sdp
+  Content-Length: [len]
+  
+  v=0
+  o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
+  s=-
+  c=IN IP[media_ip_type] [media_ip]
+  t=0 0
+  m=audio [media_port] RTP/AVP 0
+  a=rtpmap:0 PCMU/8000
+  ]]>
+ </send>
+
+ <recv request="ACK" optional="true" crlf="true">
+ </recv>
+
+</scenario>