/* dual-faced port sitting on top of IPL4_asp UDP to encode/decode GTPv2C
 * (C) 2019 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
 */


module GTPv2_CodecPort {
	import from IPL4asp_PortType all;
	import from IPL4asp_Types all;
	import from GTPv2_Types all;

	/* identifies a remote peer (sender or receiver) */
	type record Gtp2cPeer {
		ConnectionId	connId,
		HostName	remName,
		IPL4asp_Types.PortNumber	remPort
	}

	/* Decoded GTP2C (Control Plane), used in send and receive direction */
	type record Gtp2cUnitdata {
		Gtp2cPeer	peer,
		PDU_GTPCv2	gtpc
	}

 	/* Translation port on top of IPL4asp; ASP_Event passed through transparently */
	type port GTPv2C_PT message {
		out	Gtp2cUnitdata;
		in	Gtp2cUnitdata,
			ASP_ConnId_ReadyToRelease,
			ASP_Event;
	} with { extension "user IPL4asp_PT
		out(Gtp2cUnitdata -> ASP_SendTo: function(f_enc_Gtp2cUD))
		in(ASP_RecvFrom -> Gtp2cUnitdata: function(f_dec_Gtp2cUD);
		   ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
		   ASP_Event -> ASP_Event: simple)" }

	private function f_enc_Gtp2cUD(in Gtp2cUnitdata in_ud, out ASP_SendTo out_ud) {
		out_ud.connId := in_ud.peer.connId;
		out_ud.remName := in_ud.peer.remName;
		out_ud.remPort := in_ud.peer.remPort;
		out_ud.proto := { udp := {} };
		out_ud.msg := enc_PDU_GTPCv2(in_ud.gtpc);
	} with { extension "prototype(fast)" };

	private function f_dec_Gtp2cUD(in ASP_RecvFrom in_ud, out Gtp2cUnitdata out_ud) {
		out_ud.peer.connId := in_ud.connId;
		out_ud.peer.remName := in_ud.remName;
		out_ud.peer.remPort := in_ud.remPort;
		out_ud.gtpc := dec_PDU_GTPCv2(in_ud.msg);
	} with { extension "prototype(fast)" };

}
