<p>laforge has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/23019">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">remsim: factor-out HTTP_Adapter.ttcn<br><br>There are other test suites (like osmo-cbc) which can reuse some of<br>the HTTP utility code that was developed within the remsim test suite<br><br>Change-Id: I87a728272d47649e4faa628fad44d6f8673c8169<br>---<br>A library/HTTP_Adapter.ttcn<br>M remsim/RemsimServer_Tests.ttcn<br>M remsim/gen_links.sh<br>3 files changed, 103 insertions(+), 82 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks refs/changes/19/23019/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/library/HTTP_Adapter.ttcn b/library/HTTP_Adapter.ttcn</span><br><span>new file mode 100644</span><br><span>index 0000000..a9d0d83</span><br><span>--- /dev/null</span><br><span>+++ b/library/HTTP_Adapter.ttcn</span><br><span>@@ -0,0 +1,101 @@</span><br><span style="color: hsl(120, 100%, 40%);">+module HTTP_Adapter {</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* HTTP Adapter component, originally part of Integration Tests for osmo-remsim-server</span><br><span style="color: hsl(120, 100%, 40%);">+ * (C) 2019 by Harald Welte <laforge@gnumonks.org></span><br><span style="color: hsl(120, 100%, 40%);">+ * All rights reserved.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Released under the terms of GNU General Public License, Version 2 or</span><br><span style="color: hsl(120, 100%, 40%);">+ * (at your option) any later version.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * SPDX-License-Identifier: GPL-2.0-or-later</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This test suite tests osmo-remsim-server by attaching to the external interfaces</span><br><span style="color: hsl(120, 100%, 40%);">+ * such as RSPRO for simulated clients + bankds and RSRES (REST backend interface).</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+import from HTTPmsg_Types all;</span><br><span style="color: hsl(120, 100%, 40%);">+import from HTTPmsg_PortType all;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+type component http_CT {</span><br><span style="color: hsl(120, 100%, 40%);">+       port HTTPmsg_PT HTTP;</span><br><span style="color: hsl(120, 100%, 40%);">+ var charstring g_http_host;</span><br><span style="color: hsl(120, 100%, 40%);">+   var integer g_http_port;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+function f_http_init(charstring host, integer http_port) runs on http_CT {</span><br><span style="color: hsl(120, 100%, 40%);">+    map(self:HTTP, system:HTTP);</span><br><span style="color: hsl(120, 100%, 40%);">+  g_http_host := host;</span><br><span style="color: hsl(120, 100%, 40%);">+  g_http_port := http_port;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+template (value) Connect ts_HTTP_Connect(template (value) charstring hostname,</span><br><span style="color: hsl(120, 100%, 40%);">+                                         template (value) integer http_port := 80,</span><br><span style="color: hsl(120, 100%, 40%);">+                                     template (value) boolean use_ssl := false) := {</span><br><span style="color: hsl(120, 100%, 40%);">+      hostname := hostname,</span><br><span style="color: hsl(120, 100%, 40%);">+ portnumber := http_port,</span><br><span style="color: hsl(120, 100%, 40%);">+      use_ssl := use_ssl</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+template (value) Close ts_HTTP_Close := { client_id := omit };</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+template (value) HeaderLines ts_HTTP_Header(charstring body) := {</span><br><span style="color: hsl(120, 100%, 40%);">+    { header_name := "Content-Type", header_value := "application/json" },</span><br><span style="color: hsl(120, 100%, 40%);">+    { header_name := "Content-Length", header_value := int2str(lengthof(body)) }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+template (value) HTTPMessage ts_HTTP_Req(charstring url,</span><br><span style="color: hsl(120, 100%, 40%);">+                                  charstring method := "GET",</span><br><span style="color: hsl(120, 100%, 40%);">+                                         charstring body := "",</span><br><span style="color: hsl(120, 100%, 40%);">+                                      integer v_maj := 1, integer v_min := 1) := {</span><br><span style="color: hsl(120, 100%, 40%);">+ request := {</span><br><span style="color: hsl(120, 100%, 40%);">+          client_id := omit,</span><br><span style="color: hsl(120, 100%, 40%);">+            method := method,</span><br><span style="color: hsl(120, 100%, 40%);">+             uri := url,</span><br><span style="color: hsl(120, 100%, 40%);">+           version_major := v_maj,</span><br><span style="color: hsl(120, 100%, 40%);">+               version_minor := v_min,</span><br><span style="color: hsl(120, 100%, 40%);">+               header := ts_HTTP_Header(body),</span><br><span style="color: hsl(120, 100%, 40%);">+               body := body</span><br><span style="color: hsl(120, 100%, 40%);">+  }</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+template HTTPMessage tr_HTTP_Resp(template integer sts := ?) := {</span><br><span style="color: hsl(120, 100%, 40%);">+     response := {</span><br><span style="color: hsl(120, 100%, 40%);">+         client_id := ?,</span><br><span style="color: hsl(120, 100%, 40%);">+               version_major := ?,</span><br><span style="color: hsl(120, 100%, 40%);">+           version_minor := ?,</span><br><span style="color: hsl(120, 100%, 40%);">+           statuscode := sts,</span><br><span style="color: hsl(120, 100%, 40%);">+            statustext := ?,</span><br><span style="color: hsl(120, 100%, 40%);">+              header := ?,</span><br><span style="color: hsl(120, 100%, 40%);">+          body := ?</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+template HTTPMessage tr_HTTP_Resp2xx := tr_HTTP_Resp((200..299));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/* run a HTTP request and return the response */</span><br><span style="color: hsl(120, 100%, 40%);">+function f_http_transact(charstring url, charstring method := "GET",</span><br><span style="color: hsl(120, 100%, 40%);">+                         charstring body := "", template HTTPMessage exp := tr_HTTP_Resp2xx)</span><br><span style="color: hsl(120, 100%, 40%);">+runs on http_CT return HTTPMessage {</span><br><span style="color: hsl(120, 100%, 40%);">+  var HTTPMessage resp;</span><br><span style="color: hsl(120, 100%, 40%);">+ timer T := 2.0;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     HTTP.send(ts_HTTP_Connect(g_http_host, g_http_port));</span><br><span style="color: hsl(120, 100%, 40%);">+ //HTTP.receive(Connect_result:?);</span><br><span style="color: hsl(120, 100%, 40%);">+     HTTP.send(ts_HTTP_Req(url, method, body));</span><br><span style="color: hsl(120, 100%, 40%);">+    T.start;</span><br><span style="color: hsl(120, 100%, 40%);">+      alt {</span><br><span style="color: hsl(120, 100%, 40%);">+ [] HTTP.receive(exp) -> value resp {</span><br><span style="color: hsl(120, 100%, 40%);">+               setverdict(pass);</span><br><span style="color: hsl(120, 100%, 40%);">+             }</span><br><span style="color: hsl(120, 100%, 40%);">+     [] HTTP.receive(tr_HTTP_Resp) -> value resp {</span><br><span style="color: hsl(120, 100%, 40%);">+              setverdict(fail, "Unexpected HTTP response ", resp);</span><br><span style="color: hsl(120, 100%, 40%);">+                }</span><br><span style="color: hsl(120, 100%, 40%);">+     [] T.timeout {</span><br><span style="color: hsl(120, 100%, 40%);">+                setverdict(fail, "Timeout waiting for HTTP response");</span><br><span style="color: hsl(120, 100%, 40%);">+              self.stop;</span><br><span style="color: hsl(120, 100%, 40%);">+            }</span><br><span style="color: hsl(120, 100%, 40%);">+     }</span><br><span style="color: hsl(120, 100%, 40%);">+     HTTP.send(ts_HTTP_Close);</span><br><span style="color: hsl(120, 100%, 40%);">+     return resp;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span>diff --git a/remsim/RemsimServer_Tests.ttcn b/remsim/RemsimServer_Tests.ttcn</span><br><span>index 1ca5ce9..fd7a1a4 100644</span><br><span>--- a/remsim/RemsimServer_Tests.ttcn</span><br><span>+++ b/remsim/RemsimServer_Tests.ttcn</span><br><span>@@ -24,90 +24,9 @@</span><br><span> </span><br><span> import from HTTPmsg_Types all;</span><br><span> import from HTTPmsg_PortType all;</span><br><span style="color: hsl(120, 100%, 40%);">+import from HTTP_Adapter all;</span><br><span> import from JSON_Types all;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-type component http_CT {</span><br><span style="color: hsl(0, 100%, 40%);">-     port HTTPmsg_PT HTTP;</span><br><span style="color: hsl(0, 100%, 40%);">-   var charstring g_http_host;</span><br><span style="color: hsl(0, 100%, 40%);">-     var integer g_http_port;</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-function f_http_init(charstring host, integer http_port) runs on http_CT {</span><br><span style="color: hsl(0, 100%, 40%);">-    map(self:HTTP, system:HTTP);</span><br><span style="color: hsl(0, 100%, 40%);">-    g_http_host := host;</span><br><span style="color: hsl(0, 100%, 40%);">-    g_http_port := http_port;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-template (value) Connect ts_HTTP_Connect(template (value) charstring hostname,</span><br><span style="color: hsl(0, 100%, 40%);">-                                         template (value) integer http_port := 80,</span><br><span style="color: hsl(0, 100%, 40%);">-                                       template (value) boolean use_ssl := false) := {</span><br><span style="color: hsl(0, 100%, 40%);">-        hostname := hostname,</span><br><span style="color: hsl(0, 100%, 40%);">-   portnumber := http_port,</span><br><span style="color: hsl(0, 100%, 40%);">-        use_ssl := use_ssl</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-template (value) Close ts_HTTP_Close := { client_id := omit };</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-template (value) HeaderLines ts_HTTP_Header(charstring body) := {</span><br><span style="color: hsl(0, 100%, 40%);">-      { header_name := "Content-Type", header_value := "application/json" },</span><br><span style="color: hsl(0, 100%, 40%);">-      { header_name := "Content-Length", header_value := int2str(lengthof(body)) }</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-template (value) HTTPMessage ts_HTTP_Req(charstring url,</span><br><span style="color: hsl(0, 100%, 40%);">-                                  charstring method := "GET",</span><br><span style="color: hsl(0, 100%, 40%);">-                                   charstring body := "",</span><br><span style="color: hsl(0, 100%, 40%);">-                                        integer v_maj := 1, integer v_min := 1) := {</span><br><span style="color: hsl(0, 100%, 40%);">-   request := {</span><br><span style="color: hsl(0, 100%, 40%);">-            client_id := omit,</span><br><span style="color: hsl(0, 100%, 40%);">-              method := method,</span><br><span style="color: hsl(0, 100%, 40%);">-               uri := url,</span><br><span style="color: hsl(0, 100%, 40%);">-             version_major := v_maj,</span><br><span style="color: hsl(0, 100%, 40%);">-         version_minor := v_min,</span><br><span style="color: hsl(0, 100%, 40%);">-         header := ts_HTTP_Header(body),</span><br><span style="color: hsl(0, 100%, 40%);">-         body := body</span><br><span style="color: hsl(0, 100%, 40%);">-    }</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-template HTTPMessage tr_HTTP_Resp(template integer sts := ?) := {</span><br><span style="color: hsl(0, 100%, 40%);">-     response := {</span><br><span style="color: hsl(0, 100%, 40%);">-           client_id := ?,</span><br><span style="color: hsl(0, 100%, 40%);">-         version_major := ?,</span><br><span style="color: hsl(0, 100%, 40%);">-             version_minor := ?,</span><br><span style="color: hsl(0, 100%, 40%);">-             statuscode := sts,</span><br><span style="color: hsl(0, 100%, 40%);">-              statustext := ?,</span><br><span style="color: hsl(0, 100%, 40%);">-                header := ?,</span><br><span style="color: hsl(0, 100%, 40%);">-            body := ?</span><br><span style="color: hsl(0, 100%, 40%);">-       }</span><br><span style="color: hsl(0, 100%, 40%);">-};</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-template HTTPMessage tr_HTTP_Resp2xx := tr_HTTP_Resp((200..299));</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">-/* run a HTTP request and return the response */</span><br><span style="color: hsl(0, 100%, 40%);">-function f_http_transact(charstring url, charstring method := "GET",</span><br><span style="color: hsl(0, 100%, 40%);">-                       charstring body := "", template HTTPMessage exp := tr_HTTP_Resp2xx)</span><br><span style="color: hsl(0, 100%, 40%);">-runs on http_CT return HTTPMessage {</span><br><span style="color: hsl(0, 100%, 40%);">-      var HTTPMessage resp;</span><br><span style="color: hsl(0, 100%, 40%);">-   timer T := 2.0;</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span style="color: hsl(0, 100%, 40%);">- HTTP.send(ts_HTTP_Connect(g_http_host, g_http_port));</span><br><span style="color: hsl(0, 100%, 40%);">-   //HTTP.receive(Connect_result:?);</span><br><span style="color: hsl(0, 100%, 40%);">-       HTTP.send(ts_HTTP_Req(url, method, body));</span><br><span style="color: hsl(0, 100%, 40%);">-      T.start;</span><br><span style="color: hsl(0, 100%, 40%);">-        alt {</span><br><span style="color: hsl(0, 100%, 40%);">-   [] HTTP.receive(exp) -> value resp {</span><br><span style="color: hsl(0, 100%, 40%);">-         setverdict(pass);</span><br><span style="color: hsl(0, 100%, 40%);">-               }</span><br><span style="color: hsl(0, 100%, 40%);">-       [] HTTP.receive(tr_HTTP_Resp) -> value resp {</span><br><span style="color: hsl(0, 100%, 40%);">-                setverdict(fail, "Unexpected HTTP response ", resp);</span><br><span style="color: hsl(0, 100%, 40%);">-          }</span><br><span style="color: hsl(0, 100%, 40%);">-       [] T.timeout {</span><br><span style="color: hsl(0, 100%, 40%);">-          setverdict(fail, "Timeout waiting for HTTP response");</span><br><span style="color: hsl(0, 100%, 40%);">-                self.stop;</span><br><span style="color: hsl(0, 100%, 40%);">-              }</span><br><span style="color: hsl(0, 100%, 40%);">-       }</span><br><span style="color: hsl(0, 100%, 40%);">-       HTTP.send(ts_HTTP_Close);</span><br><span style="color: hsl(0, 100%, 40%);">-       return resp;</span><br><span style="color: hsl(0, 100%, 40%);">-}</span><br><span style="color: hsl(0, 100%, 40%);">-</span><br><span> /* run a HTTP GET on specified URL expecting json in RSRES format as response */</span><br><span> function f_rsres_get(charstring url, template integer exp_sts := 200)</span><br><span> runs on http_CT return JsRoot {</span><br><span>diff --git a/remsim/gen_links.sh b/remsim/gen_links.sh</span><br><span>index 995abfb..b25375b 100755</span><br><span>--- a/remsim/gen_links.sh</span><br><span>+++ b/remsim/gen_links.sh</span><br><span>@@ -42,6 +42,7 @@</span><br><span> FILES+="IPA_Types.ttcn IPA_CodecPort.ttcn IPA_CodecPort_CtrlFunct.ttcn IPA_CodecPort_CtrlFunctDef.cc IPA_Emulation.ttcnpp IPA_CodecPort.ttcn " #RSL_Types.ttcn RSL_Emulation.ttcn "</span><br><span> FILES+="Osmocom_CTRL_Types.ttcn Osmocom_CTRL_Functions.ttcn Osmocom_CTRL_Adapter.ttcn  "</span><br><span> FILES+="Native_Functions.ttcn Native_FunctionDefs.cc "</span><br><span style="color: hsl(120, 100%, 40%);">+FILES+="HTTP_Adapter.ttcn "</span><br><span> FILES+="VPCD_Types.ttcn VPCD_CodecPort.ttcn VPCD_CodecPort_CtrlFunct.ttcn VPCD_CodecPort_CtrlFunctDef.cc</span><br><span> VPCD_Adapter.ttcn "</span><br><span> gen_links $DIR $FILES</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/23019">change 23019</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/23019"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-ttcn3-hacks </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I87a728272d47649e4faa628fad44d6f8673c8169 </div>
<div style="display:none"> Gerrit-Change-Number: 23019 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: laforge <laforge@osmocom.org> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>