Pau Espin Pedrol | 4b090c9 | 2024-02-29 19:47:07 +0100 | [diff] [blame] | 1 | /* dual-faced port sitting on top of IPL4_asp UDP to encode/decode GTPv1C |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 2 | * (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 Pedrol | 4b090c9 | 2024-02-29 19:47:07 +0100 | [diff] [blame] | 12 | module GTPv1C_CodecPort { |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame] | 13 | import from IPL4asp_PortType all; |
| 14 | import from IPL4asp_Types all; |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 15 | import from GTPC_Types all; |
Pau Espin Pedrol | 67f2354 | 2022-02-21 15:56:03 +0100 | [diff] [blame] | 16 | import from Misc_Helpers all; |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 17 | |
Pau Espin Pedrol | 3ede4f6 | 2022-02-14 18:55:56 +0100 | [diff] [blame] | 18 | modulepar { |
| 19 | SystemUnderTest mp_pl_SystemUnderTest := SGSN; |
| 20 | } |
| 21 | |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 22 | /* identifies a remote peer (sender or receiver) */ |
Pau Espin Pedrol | 4b090c9 | 2024-02-29 19:47:07 +0100 | [diff] [blame] | 23 | type record Gtp1cPeer { |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame] | 24 | ConnectionId connId, |
| 25 | HostName remName, |
| 26 | PortNumber remPort |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | /* Decoded GTP1C (Control Plane), used in send and receive direction */ |
| 30 | type record Gtp1cUnitdata { |
Pau Espin Pedrol | 4b090c9 | 2024-02-29 19:47:07 +0100 | [diff] [blame] | 31 | Gtp1cPeer peer, |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 32 | PDU_GTPC gtpc |
| 33 | } |
| 34 | |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame] | 35 | /* Translation port on top of IPL4asp; ASP_Event passed through transparently */ |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 36 | type port GTPC_PT message { |
| 37 | out Gtp1cUnitdata; |
| 38 | in Gtp1cUnitdata, |
Harald Welte | 04d74cd | 2017-11-19 09:29:51 +0100 | [diff] [blame] | 39 | ASP_ConnId_ReadyToRelease, |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame] | 40 | ASP_Event; |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 41 | } with { extension "user IPL4asp_PT |
| 42 | out(Gtp1cUnitdata -> ASP_SendTo: function(f_enc_Gtp1cUD)) |
| 43 | in(ASP_RecvFrom -> Gtp1cUnitdata: function(f_dec_Gtp1cUD); |
Harald Welte | 04d74cd | 2017-11-19 09:29:51 +0100 | [diff] [blame] | 44 | ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple; |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 45 | ASP_Event -> ASP_Event: simple)" } |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 46 | |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 47 | private function f_enc_Gtp1cUD(in Gtp1cUnitdata in_ud, out ASP_SendTo out_ud) { |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame] | 48 | 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 Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 53 | } with { extension "prototype(fast)" }; |
| 54 | |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 55 | private function f_dec_Gtp1cUD(in ASP_RecvFrom in_ud, out Gtp1cUnitdata out_ud) { |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame] | 56 | 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 Pedrol | 3ede4f6 | 2022-02-14 18:55:56 +0100 | [diff] [blame] | 59 | out_ud.gtpc := dec_PDU_GTPC(in_ud.msg, pl_SystemUnderTest := mp_pl_SystemUnderTest); |
Pau Espin Pedrol | 67f2354 | 2022-02-21 15:56:03 +0100 | [diff] [blame] | 60 | 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 Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 64 | } with { extension "prototype(fast)" }; |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 65 | } |