aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2019-05-06 17:20:44 +0200
committerlaforge <laforge@gnumonks.org>2019-09-04 10:45:41 +0000
commitcd451ef0830508d7f8656b2377b96ffcf78ff196 (patch)
treecc4ab25118bd36cf69db82a012a30e86a76d65eb
parentea260349dee80886014748784f8ab3c27ebe0b3c (diff)
Add CBSP_CodecPort + CBSP_Adapter
-rw-r--r--library/CBSP_Adapter.ttcn77
-rw-r--r--library/CBSP_CodecPort.ttcn64
-rw-r--r--library/CBSP_CodecPort_CtrlFunct.ttcn52
-rw-r--r--library/CBSP_CodecPort_CtrlFunctdef.cc66
4 files changed, 259 insertions, 0 deletions
diff --git a/library/CBSP_Adapter.ttcn b/library/CBSP_Adapter.ttcn
new file mode 100644
index 00000000..8dbee6a6
--- /dev/null
+++ b/library/CBSP_Adapter.ttcn
@@ -0,0 +1,77 @@
+module CBSP_Adapter {
+
+/* CBSP Adapter layer, sitting on top of CBSP_CodecPort.
+ * test suites can 'inherit' in order to have a CBSP connection to the IUT which they're testing
+ *
+ * (C) 2018-2019 by Harald Welte <laforge@gnumonks.org>
+ * All rights reserved.
+ *
+ * Released under the terms of GNU General Public License, Version 2 or
+ * (at your option) any later version.
+ */
+
+
+import from Osmocom_Types all;
+import from General_Types all;
+import from CBSP_Types all;
+import from CBSP_Templates all;
+import from CBSP_CodecPort all;
+import from CBSP_CodecPort_CtrlFunct all;
+import from IPL4asp_Types all;
+import from IPL4asp_PortType all;
+import from Socket_API_Definitions all;
+
+const integer NUM_CBSP := 3;
+
+type component CBSP_Adapter_CT {
+ /* down-facing port to CBSP Codec port */
+ port CBSP_CODEC_PT CBSP[NUM_CBSP];
+ var IPL4asp_Types.ConnectionId g_cbsp_conn_id[NUM_CBSP] := { -1, -1, -1 };
+}
+
+private function f_set_tcp_segmentation(integer idx) runs on CBSP_Adapter_CT {
+ /* Set function for dissecting the binary stream into packets */
+ var f_IPL4_getMsgLen vl_f := refers(f_IPL4_fixedMsgLen);
+ /* Offset: 1, size of length: 3, delta: 4, multiplier: 1, big-endian */
+ CBSP_CodecPort_CtrlFunct.f_IPL4_setGetMsgLen(CBSP[idx], g_cbsp_conn_id[idx], vl_f, {1, 3, 4, 1, 0});
+}
+
+function f_connect(charstring remote_host, IPL4asp_Types.PortNumber remote_port,
+ charstring local_host, IPL4asp_Types.PortNumber local_port, integer idx := 0)
+runs on CBSP_Adapter_CT {
+ var IPL4asp_Types.Result res;
+ map(self:CBSP[idx], system:CBSP);
+ res := CBSP_CodecPort_CtrlFunct.f_IPL4_connect(CBSP[idx], remote_host, remote_port,
+ local_host, local_port, 0, { tcp :={} });
+ if (not ispresent(res.connId)) {
+ setverdict(fail, "Could not connect to CBSP port, check your configuration");
+ mtc.stop;
+ }
+ g_cbsp_conn_id[idx] := res.connId;
+
+ f_set_tcp_segmentation(idx);
+}
+
+/* Function to use to bind to a local port as IPA server, accepting remote clients */
+function f_bind(charstring local_host, IPL4asp_Types.PortNumber local_port, integer idx := 0)
+runs on CBSP_Adapter_CT {
+ var IPL4asp_Types.Result res;
+ map(self:CBSP[idx], system:CBSP);
+ res := CBSP_CodecPort_CtrlFunct.f_IPL4_listen(CBSP[idx], local_host, local_port, { tcp:={} });
+ g_cbsp_conn_id[idx] := res.connId;
+
+ f_set_tcp_segmentation(idx);
+}
+
+function f_cbsp_send(template (value) CBSP_PDU pdu, integer idx := 0) runs on CBSP_Adapter_CT {
+ CBSP[idx].send(ts_CBSP_Send(g_cbsp_conn_id[idx], pdu));
+}
+
+function f_cbsp_exp(template CBSP_PDU exp, integer idx := 0) runs on CBSP_Adapter_CT return CBSP_PDU {
+ var CBSP_RecvFrom rf;
+ CBSP[idx].receive(tr_CBSP_Recv(g_cbsp_conn_id[idx], exp)) -> value rf;
+ return rf.msg;
+}
+
+
+}
diff --git a/library/CBSP_CodecPort.ttcn b/library/CBSP_CodecPort.ttcn
new file mode 100644
index 00000000..442b3e41
--- /dev/null
+++ b/library/CBSP_CodecPort.ttcn
@@ -0,0 +1,64 @@
+module CBSP_CodecPort {
+
+/* Simple CBSP Codec Port, translating between raw TCP octetstring payload
+ * towards the IPL4asp port provider, and CBSP primitives
+ * which carry the decoded CBSP data types as payload.
+ *
+ * (C) 2018 by Harald Welte <laforge@gnumonks.org>
+ * All rights reserved.
+ *
+ * Released under the terms of GNU General Public License, Version 2 or
+ * (at your option) any later version.
+ */
+
+
+import from IPL4asp_PortType all;
+import from IPL4asp_Types all;
+import from CBSP_Types all;
+
+type record CBSP_RecvFrom {
+ ConnectionId connId,
+ CBSP_PDU msg
+}
+
+type record CBSP_Send {
+ ConnectionId connId,
+ CBSP_PDU msg
+}
+
+template (value) CBSP_Send ts_CBSP_Send(ConnectionId conn_id, template (value) CBSP_PDU msg) := {
+ connId := conn_id,
+ msg := msg
+}
+
+template CBSP_RecvFrom tr_CBSP_Recv(template ConnectionId conn_id, template CBSP_PDU msg) := {
+ connId := conn_id,
+ msg := msg
+}
+
+private function IPL4_to_CBSP_RecvFrom(in ASP_RecvFrom pin, out CBSP_RecvFrom pout) {
+ pout.connId := pin.connId;
+ pout.msg := dec_CBSP_PDU(pin.msg);
+} with { extension "prototype(fast)" }
+
+private function CBSP_to_IPL4_Send(in CBSP_Send pin, out ASP_Send pout) {
+ pout.connId := pin.connId;
+ pout.proto := { tcp := {} };
+ pout.msg := enc_CBSP_PDU(pin.msg);
+} with { extension "prototype(fast)" }
+
+type port CBSP_CODEC_PT message {
+ out CBSP_Send;
+ in CBSP_RecvFrom,
+ ASP_ConnId_ReadyToRelease,
+ ASP_Event;
+} with { extension "user IPL4asp_PT
+ out(CBSP_Send -> ASP_Send: function(CBSP_to_IPL4_Send))
+ in(ASP_RecvFrom -> CBSP_RecvFrom: function(IPL4_to_CBSP_RecvFrom);
+ ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
+ ASP_Event -> ASP_Event: simple)"
+}
+
+
+
+}
diff --git a/library/CBSP_CodecPort_CtrlFunct.ttcn b/library/CBSP_CodecPort_CtrlFunct.ttcn
new file mode 100644
index 00000000..9a5d44ba
--- /dev/null
+++ b/library/CBSP_CodecPort_CtrlFunct.ttcn
@@ -0,0 +1,52 @@
+module CBSP_CodecPort_CtrlFunct {
+
+ import from CBSP_CodecPort all;
+ import from IPL4asp_Types all;
+
+ external function f_IPL4_listen(
+ inout CBSP_CODEC_PT portRef,
+ in HostName locName,
+ in PortNumber locPort,
+ in ProtoTuple proto,
+ in OptionList options := {}
+ ) return Result;
+
+ external function f_IPL4_connect(
+ inout CBSP_CODEC_PT portRef,
+ in HostName remName,
+ in PortNumber remPort,
+ in HostName locName,
+ in PortNumber locPort,
+ in ConnectionId connId,
+ in ProtoTuple proto,
+ in OptionList options := {}
+ ) return Result;
+
+ external function f_IPL4_close(
+ inout CBSP_CODEC_PT portRef,
+ in ConnectionId id,
+ in ProtoTuple proto := { unspecified := {} }
+ ) return Result;
+
+ external function f_IPL4_setUserData(
+ inout CBSP_CODEC_PT portRef,
+ in ConnectionId id,
+ in UserData userData
+ ) return Result;
+
+ external function f_IPL4_getUserData(
+ inout CBSP_CODEC_PT portRef,
+ in ConnectionId id,
+ out UserData userData
+ ) return Result;
+
+ external function f_IPL4_setGetMsgLen(
+ inout CBSP_CODEC_PT portRef,
+ in ConnectionId id,
+ inout f_IPL4_getMsgLen f,
+ in ro_integer msgLenArgs
+ );
+
+
+}
+
diff --git a/library/CBSP_CodecPort_CtrlFunctdef.cc b/library/CBSP_CodecPort_CtrlFunctdef.cc
new file mode 100644
index 00000000..6d5e96b0
--- /dev/null
+++ b/library/CBSP_CodecPort_CtrlFunctdef.cc
@@ -0,0 +1,66 @@
+#include "IPL4asp_PortType.hh"
+#include "CBSP_CodecPort.hh"
+#include "IPL4asp_PT.hh"
+
+namespace CBSP__CodecPort__CtrlFunct {
+
+ IPL4asp__Types::Result f__IPL4__listen(
+ CBSP__CodecPort::CBSP__CODEC__PT& portRef,
+ const IPL4asp__Types::HostName& locName,
+ const IPL4asp__Types::PortNumber& locPort,
+ const IPL4asp__Types::ProtoTuple& proto,
+ const IPL4asp__Types::OptionList& options)
+ {
+ return f__IPL4__PROVIDER__listen(portRef, locName, locPort, proto, options);
+ }
+
+ IPL4asp__Types::Result f__IPL4__connect(
+ CBSP__CodecPort::CBSP__CODEC__PT& portRef,
+ const IPL4asp__Types::HostName& remName,
+ const IPL4asp__Types::PortNumber& remPort,
+ const IPL4asp__Types::HostName& locName,
+ const IPL4asp__Types::PortNumber& locPort,
+ const IPL4asp__Types::ConnectionId& connId,
+ const IPL4asp__Types::ProtoTuple& proto,
+ const IPL4asp__Types::OptionList& options)
+ {
+ return f__IPL4__PROVIDER__connect(portRef, remName, remPort,
+ locName, locPort, connId, proto, options);
+ }
+
+ IPL4asp__Types::Result f__IPL4__close(
+ CBSP__CodecPort::CBSP__CODEC__PT& portRef,
+ const IPL4asp__Types::ConnectionId& connId,
+ const IPL4asp__Types::ProtoTuple& proto)
+ {
+ return f__IPL4__PROVIDER__close(portRef, connId, proto);
+ }
+
+ IPL4asp__Types::Result f__IPL4__setUserData(
+ CBSP__CodecPort::CBSP__CODEC__PT& portRef,
+ const IPL4asp__Types::ConnectionId& connId,
+ const IPL4asp__Types::UserData& userData)
+ {
+ return f__IPL4__PROVIDER__setUserData(portRef, connId, userData);
+ }
+
+ IPL4asp__Types::Result f__IPL4__getUserData(
+ CBSP__CodecPort::CBSP__CODEC__PT& portRef,
+ const IPL4asp__Types::ConnectionId& connId,
+ IPL4asp__Types::UserData& userData)
+ {
+ return f__IPL4__PROVIDER__getUserData(portRef, connId, userData);
+ }
+
+ void f__IPL4__setGetMsgLen(
+ CBSP__CodecPort::CBSP__CODEC__PT& portRef,
+ const IPL4asp__Types::ConnectionId& connId,
+ Socket__API__Definitions::f__getMsgLen& f,
+ const Socket__API__Definitions::ro__integer& msgLenArgs)
+ {
+ return f__IPL4__PROVIDER__setGetMsgLen(portRef, connId, f, msgLenArgs);
+ }
+
+
+}
+