blob: bf14723440241d8430dec7db51fe6da1d5f28f8d [file] [log] [blame]
Pau Espin Pedrol4b090c92024-02-29 19:47:07 +01001/* dual-faced port sitting on top of IPL4_asp UDP to encode/decode GTPv1C
Harald Welte34b5a952019-05-27 11:54:11 +02002 * (C) 2017 Harald Welte <laforge@gnumonks.org>
3 * All rights reserved.
4 *
5 * Released under the terms of GNU General Public License, Version 2 or
6 * (at your option) any later version.
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11
Pau Espin Pedrol4b090c92024-02-29 19:47:07 +010012module GTPv1C_CodecPort {
Harald Welte627c7c72017-08-03 18:17:02 +020013 import from IPL4asp_PortType all;
14 import from IPL4asp_Types all;
Harald Welte25606082017-08-03 17:00:40 +020015 import from GTPC_Types all;
Pau Espin Pedrol67f23542022-02-21 15:56:03 +010016 import from Misc_Helpers all;
Harald Welte25606082017-08-03 17:00:40 +020017
Pau Espin Pedrol3ede4f62022-02-14 18:55:56 +010018 modulepar {
19 SystemUnderTest mp_pl_SystemUnderTest := SGSN;
20 }
21
Harald Welte25606082017-08-03 17:00:40 +020022 /* identifies a remote peer (sender or receiver) */
Pau Espin Pedrol4b090c92024-02-29 19:47:07 +010023 type record Gtp1cPeer {
Harald Welte627c7c72017-08-03 18:17:02 +020024 ConnectionId connId,
25 HostName remName,
26 PortNumber remPort
Harald Welte25606082017-08-03 17:00:40 +020027 }
28
29 /* Decoded GTP1C (Control Plane), used in send and receive direction */
30 type record Gtp1cUnitdata {
Vadim Yanitskiy1e869a22024-04-06 05:33:10 +070031 Gtp1cPeer peer,
Harald Welte25606082017-08-03 17:00:40 +020032 PDU_GTPC gtpc
33 }
34
Harald Welte627c7c72017-08-03 18:17:02 +020035 /* Translation port on top of IPL4asp; ASP_Event passed through transparently */
Harald Welted418fc62017-08-04 00:34:42 +020036 type port GTPC_PT message {
37 out Gtp1cUnitdata;
38 in Gtp1cUnitdata,
Harald Welte04d74cd2017-11-19 09:29:51 +010039 ASP_ConnId_ReadyToRelease,
Harald Welte627c7c72017-08-03 18:17:02 +020040 ASP_Event;
Harald Welted418fc62017-08-04 00:34:42 +020041 } with { extension "user IPL4asp_PT
42 out(Gtp1cUnitdata -> ASP_SendTo: function(f_enc_Gtp1cUD))
43 in(ASP_RecvFrom -> Gtp1cUnitdata: function(f_dec_Gtp1cUD);
Harald Welte04d74cd2017-11-19 09:29:51 +010044 ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple;
Harald Welted418fc62017-08-04 00:34:42 +020045 ASP_Event -> ASP_Event: simple)" }
Harald Welte25606082017-08-03 17:00:40 +020046
Harald Welted418fc62017-08-04 00:34:42 +020047 private function f_enc_Gtp1cUD(in Gtp1cUnitdata in_ud, out ASP_SendTo out_ud) {
Harald Welte627c7c72017-08-03 18:17:02 +020048 out_ud.connId := in_ud.peer.connId;
49 out_ud.remName := in_ud.peer.remName;
50 out_ud.remPort := in_ud.peer.remPort;
51 out_ud.proto := { udp := {} };
52 out_ud.msg := enc_PDU_GTPC(in_ud.gtpc);
Harald Welte25606082017-08-03 17:00:40 +020053 } with { extension "prototype(fast)" };
54
Harald Welted418fc62017-08-04 00:34:42 +020055 private function f_dec_Gtp1cUD(in ASP_RecvFrom in_ud, out Gtp1cUnitdata out_ud) {
Harald Welte627c7c72017-08-03 18:17:02 +020056 out_ud.peer.connId := in_ud.connId;
57 out_ud.peer.remName := in_ud.remName;
58 out_ud.peer.remPort := in_ud.remPort;
Pau Espin Pedrol3ede4f62022-02-14 18:55:56 +010059 out_ud.gtpc := dec_PDU_GTPC(in_ud.msg, pl_SystemUnderTest := mp_pl_SystemUnderTest);
Pau Espin Pedrol67f23542022-02-21 15:56:03 +010060 if (lengthof(in_ud.msg) != out_ud.gtpc.lengthf + 8) {
61 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
62 log2str("Rx GTPv1-C with field length ", out_ud.gtpc.lengthf, " + 8 != exp ", lengthof(in_ud.msg)));
63 }
Harald Welte25606082017-08-03 17:00:40 +020064 } with { extension "prototype(fast)" };
Harald Welte25606082017-08-03 17:00:40 +020065}