Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 1 | /* dual-faced port sitting on top of IPL4_asp UDP to encode/decode GTP |
| 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 | |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 12 | module GTP_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; |
| 16 | import from GTPU_Types all; |
Pau Espin Pedrol | 67f2354 | 2022-02-21 15:56:03 +0100 | [diff] [blame] | 17 | import from Misc_Helpers all; |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 18 | |
Pau Espin Pedrol | 3ede4f6 | 2022-02-14 18:55:56 +0100 | [diff] [blame] | 19 | modulepar { |
| 20 | SystemUnderTest mp_pl_SystemUnderTest := SGSN; |
| 21 | } |
| 22 | |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 23 | /* identifies a remote peer (sender or receiver) */ |
| 24 | type record GtpPeer { |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame] | 25 | ConnectionId connId, |
| 26 | HostName remName, |
| 27 | PortNumber remPort |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | /* Decoded GTP1C (Control Plane), used in send and receive direction */ |
| 31 | type record Gtp1cUnitdata { |
| 32 | GtpPeer peer, |
| 33 | PDU_GTPC gtpc |
| 34 | } |
| 35 | |
| 36 | /* Decoded GTP1U (User Plane), used in send and receive direction */ |
| 37 | type record Gtp1uUnitdata { |
| 38 | GtpPeer peer, |
| 39 | PDU_GTPU gtpu |
| 40 | } |
| 41 | |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame] | 42 | /* Translation port on top of IPL4asp; ASP_Event passed through transparently */ |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 43 | type port GTPC_PT message { |
| 44 | out Gtp1cUnitdata; |
| 45 | in Gtp1cUnitdata, |
Harald Welte | 04d74cd | 2017-11-19 09:29:51 +0100 | [diff] [blame] | 46 | ASP_ConnId_ReadyToRelease, |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame] | 47 | ASP_Event; |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 48 | } with { extension "user IPL4asp_PT |
| 49 | out(Gtp1cUnitdata -> ASP_SendTo: function(f_enc_Gtp1cUD)) |
| 50 | in(ASP_RecvFrom -> Gtp1cUnitdata: function(f_dec_Gtp1cUD); |
Harald Welte | 04d74cd | 2017-11-19 09:29:51 +0100 | [diff] [blame] | 51 | ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple; |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 52 | ASP_Event -> ASP_Event: simple)" } |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 53 | |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 54 | 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] | 55 | out_ud.connId := in_ud.peer.connId; |
| 56 | out_ud.remName := in_ud.peer.remName; |
| 57 | out_ud.remPort := in_ud.peer.remPort; |
| 58 | out_ud.proto := { udp := {} }; |
| 59 | out_ud.msg := enc_PDU_GTPC(in_ud.gtpc); |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 60 | } with { extension "prototype(fast)" }; |
| 61 | |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 62 | 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] | 63 | out_ud.peer.connId := in_ud.connId; |
| 64 | out_ud.peer.remName := in_ud.remName; |
| 65 | out_ud.peer.remPort := in_ud.remPort; |
Pau Espin Pedrol | 3ede4f6 | 2022-02-14 18:55:56 +0100 | [diff] [blame] | 66 | 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] | 67 | if (lengthof(in_ud.msg) != out_ud.gtpc.lengthf + 8) { |
| 68 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 69 | log2str("Rx GTPv1-C with field length ", out_ud.gtpc.lengthf, " + 8 != exp ", lengthof(in_ud.msg))); |
| 70 | } |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 71 | } with { extension "prototype(fast)" }; |
| 72 | |
| 73 | |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 74 | /* dual-faced port on top of IPL4asp; ASP_Event passed through transparently */ |
| 75 | type port GTPU_PT message { |
| 76 | out Gtp1uUnitdata; |
| 77 | in Gtp1uUnitdata, |
Harald Welte | 04d74cd | 2017-11-19 09:29:51 +0100 | [diff] [blame] | 78 | ASP_ConnId_ReadyToRelease, |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame] | 79 | ASP_Event; |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 80 | } with { extension "user IPL4asp_PT |
| 81 | out(Gtp1uUnitdata -> ASP_SendTo: function(f_enc_Gtp1uUD)) |
| 82 | in(ASP_RecvFrom -> Gtp1uUnitdata: function(f_dec_Gtp1uUD); |
Harald Welte | 04d74cd | 2017-11-19 09:29:51 +0100 | [diff] [blame] | 83 | ASP_ConnId_ReadyToRelease -> ASP_ConnId_ReadyToRelease: simple; |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 84 | ASP_Event -> ASP_Event: simple)" } |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 85 | |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 86 | function f_enc_Gtp1uUD(in Gtp1uUnitdata in_ud, out ASP_SendTo out_ud) { |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame] | 87 | out_ud.connId := in_ud.peer.connId; |
| 88 | out_ud.remName := in_ud.peer.remName; |
| 89 | out_ud.remPort := in_ud.peer.remPort; |
| 90 | out_ud.proto := { udp := {} }; |
| 91 | out_ud.msg := enc_PDU_GTPU(in_ud.gtpu); |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 92 | } with { extension "prototype(fast)" }; |
| 93 | |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 94 | function f_dec_Gtp1uUD(in ASP_RecvFrom in_ud, out Gtp1uUnitdata out_ud) { |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame] | 95 | out_ud.peer.connId := in_ud.connId; |
| 96 | out_ud.peer.remName := in_ud.remName; |
| 97 | out_ud.peer.remPort := in_ud.remPort; |
| 98 | out_ud.gtpu := dec_PDU_GTPU(in_ud.msg); |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 99 | } with { extension "prototype(fast)" }; |
Harald Welte | d418fc6 | 2017-08-04 00:34:42 +0200 | [diff] [blame] | 100 | |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 101 | } |