initial check-in of the UECUPS daemon and the related TTCN3 code

Change-Id: I5acf7059722b58e6f57dbf31e18abcc385533970
diff --git a/ttcn3/UECUPS_CodecPort.ttcn b/ttcn3/UECUPS_CodecPort.ttcn
new file mode 100644
index 0000000..8f9d962
--- /dev/null
+++ b/ttcn3/UECUPS_CodecPort.ttcn
@@ -0,0 +1,70 @@
+module UECUPS_CodecPort {
+
+/* (C) 2020 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.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+	import from IPL4asp_PortType all;
+	import from IPL4asp_Types all;
+	import from UECUPS_Types all;
+
+	type record UECUPS_RecvFrom {
+		ConnectionId	connId,
+		HostName	remName,
+		PortNumber	remPort,
+		HostName	locName,
+		PortNumber	locPort,
+		PDU_UECUPS	msg
+	};
+
+	template UECUPS_RecvFrom t_UECUPS_RecvFrom(template PDU_UECUPS msg) := {
+		connId := ?,
+		remName := ?,
+		remPort := ?,
+		locName := ?,
+		locPort := ?,
+		msg := msg
+	}
+
+	type record UECUPS_Send {
+		ConnectionId	connId,
+		PDU_UECUPS	msg
+	}
+
+	template UECUPS_Send t_UECUPS_Send(template ConnectionId connId, template PDU_UECUPS msg) := {
+		connId := connId,
+		msg := msg
+	}
+
+	private function IPL4_to_UECUPS_RecvFrom(in ASP_RecvFrom pin, out UECUPS_RecvFrom pout) {
+		pout.connId := pin.connId;
+		pout.remName := pin.remName;
+		pout.remPort := pin.remPort;
+		pout.locName := pin.locName;
+		pout.locPort := pin.locPort;
+		pout.msg := f_dec_PDU_UECUPS(pin.msg);
+	} with { extension "prototype(fast)" };
+
+	private function UECUPS_to_IPL4_Send(in UECUPS_Send pin, out ASP_Send pout) {
+		pout.connId := pin.connId;
+		pout.proto := { sctp := {} };
+		pout.msg := f_enc_PDU_UECUPS(pin.msg);
+	} with { extension "prototype(fast)" };
+
+	type port UECUPS_CODEC_PT message {
+		out	UECUPS_Send;
+		in	UECUPS_RecvFrom,
+			ASP_ConnId_ReadyToRelease,
+			ASP_Event;
+	} with { extension "user IPL4asp_PT
+		out(UECUPS_Send -> ASP_Send:function(UECUPS_to_IPL4_Send))
+		in(ASP_RecvFrom -> UECUPS_RecvFrom: function(IPL4_to_UECUPS_RecvFrom);
+		   ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
+		   ASP_Event -> ASP_Event: simple)"
+	}
+}
diff --git a/ttcn3/UECUPS_CodecPort_CtrlFunct.ttcn b/ttcn3/UECUPS_CodecPort_CtrlFunct.ttcn
new file mode 100644
index 0000000..365b7cb
--- /dev/null
+++ b/ttcn3/UECUPS_CodecPort_CtrlFunct.ttcn
@@ -0,0 +1,44 @@
+module UECUPS_CodecPort_CtrlFunct {
+
+  import from UECUPS_CodecPort all;
+  import from IPL4asp_Types all;
+
+  external function f_IPL4_listen(
+    inout UECUPS_CODEC_PT portRef,
+    in HostName locName,
+    in PortNumber locPort,
+    in ProtoTuple proto,
+    in OptionList options := {}
+  ) return Result;
+
+  external function f_IPL4_connect(
+    inout UECUPS_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 UECUPS_CODEC_PT portRef,
+    in ConnectionId id,
+    in ProtoTuple proto := { unspecified := {} }
+  ) return Result;
+
+  external function f_IPL4_setUserData(
+    inout UECUPS_CODEC_PT portRef,
+    in ConnectionId id,
+    in UserData userData
+  ) return Result;
+
+  external function f_IPL4_getUserData(
+    inout UECUPS_CODEC_PT portRef,
+    in ConnectionId id,
+    out UserData userData
+  ) return Result;
+
+}
+
diff --git a/ttcn3/UECUPS_CodecPort_CtrlFunctDef.cc b/ttcn3/UECUPS_CodecPort_CtrlFunctDef.cc
new file mode 100644
index 0000000..b069b11
--- /dev/null
+++ b/ttcn3/UECUPS_CodecPort_CtrlFunctDef.cc
@@ -0,0 +1,56 @@
+#include "IPL4asp_PortType.hh"
+#include "UECUPS_CodecPort.hh"
+#include "IPL4asp_PT.hh"
+
+namespace UECUPS__CodecPort__CtrlFunct {
+
+  IPL4asp__Types::Result f__IPL4__listen(
+    UECUPS__CodecPort::UECUPS__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(
+    UECUPS__CodecPort::UECUPS__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(
+    UECUPS__CodecPort::UECUPS__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(
+    UECUPS__CodecPort::UECUPS__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(
+    UECUPS__CodecPort::UECUPS__CODEC__PT& portRef,
+    const IPL4asp__Types::ConnectionId& connId,
+    IPL4asp__Types::UserData& userData)
+  {
+    return f__IPL4__PROVIDER__getUserData(portRef, connId, userData);
+  }
+  
+}
+
diff --git a/ttcn3/UECUPS_Types.ttcn b/ttcn3/UECUPS_Types.ttcn
new file mode 100644
index 0000000..8c00090
--- /dev/null
+++ b/ttcn3/UECUPS_Types.ttcn
@@ -0,0 +1,91 @@
+module UECUPS_Types {
+
+import from General_Types all;
+import from Osmocom_Types all;
+
+type enumerated UECUPS_AddrType {
+	IPV4	(1),
+	IPV6	(2)
+};
+
+type enumerated UECUPS_Result {
+	OK			(1),
+	ERR_INVALID_DATA	(2),
+	ERR_NOT_FOUND		(3)
+};
+
+type record UECUPS_SockAddr {
+	UECUPS_AddrType	addr_type,
+	OCT4_16n	ip,
+	uint16_t	Port
+};
+
+/* Create a new GTP-U tunnel in the user plane */
+type record UECUPS_CreateTun {
+	/* TEID in transmit + receive direction */
+	uint32_t	tx_teid,
+	uint32_t	rx_teid,
+
+	/* user address (allocated inside the tunnel) */
+	UECUPS_AddrType user_addr_type,
+	OCT4_16n	user_addr,
+
+	/* GTP endpoint (UDP IP/Port tuples) */
+	UECUPS_SockAddr local_gtp_ep,
+	UECUPS_SockAddr remote_gtp_ep,
+
+	/* TUN device */
+	charstring	tun_dev_name,
+	charstring	tun_netns_name optional
+};
+
+type record UECUPS_CreateTunRes {
+	UECUPS_Result	result
+};
+
+/* Destroy an existing GTP-U tunnel in the user plane */
+type record UECUPS_DestroyTun {
+	/* local GTP endpoint + TEID are sufficient for unique identification */
+	UECUPS_SockAddr local_gtp_ep,
+	uint32_t	rx_teid
+};
+
+type record UECUPS_DestroyTunRes {
+	UECUPS_Result	result
+};
+
+type union PDU_UECUPS {
+	UECUPS_CreateTun	create_tun,
+	UECUPS_CreateTunRes	create_tun_res,
+	UECUPS_DestroyTun	destroy_tun,
+	UECUPS_DestroyTunRes	destroy_tun_res
+};
+
+
+
+external function f_enc_PDU_UECUPS(in PDU_UECUPS inp) return octetstring
+        with { extension "prototype(convert) encode(JSON)" }
+external function f_dec_PDU_UECUPS(in octetstring inp) return PDU_UECUPS
+        with { extension "prototype(convert) decode(JSON)" }
+
+
+private function f_get_addrtype(OCT4_16n addr) return UECUPS_AddrType
+{
+	if (lengthof(addr) == 4) {
+		return IPV4;
+	} else {
+		return IPV6;
+	}
+}
+
+private const integer GTP1U_PORT := 2152;
+
+template (value) UECUPS_SockAddr
+ts_UECUPS_SockAddr(OCT4_16n ip, uint16_t Port := GTP1U_PORT) := {
+	addr_type := f_get_addrtype(ip),
+	ip := ip,
+	Port := Port
+}
+
+
+} with { encode "JSON" };