Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame^] | 1 | /* Translation Port sitting on top of IPL4_asp UDP to encode/decode GTP */ |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 2 | /* (C) 2017 by Harald Welte <laforge@gnumonks.org */ |
| 3 | module GTP_CodecPort { |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame^] | 4 | import from IPL4asp_PortType all; |
| 5 | import from IPL4asp_Types all; |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 6 | import from GTPC_Types all; |
| 7 | import from GTPU_Types all; |
| 8 | |
| 9 | /* identifies a remote peer (sender or receiver) */ |
| 10 | type record GtpPeer { |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame^] | 11 | ConnectionId connId, |
| 12 | HostName remName, |
| 13 | PortNumber remPort |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 14 | } |
| 15 | |
| 16 | /* Decoded GTP1C (Control Plane), used in send and receive direction */ |
| 17 | type record Gtp1cUnitdata { |
| 18 | GtpPeer peer, |
| 19 | PDU_GTPC gtpc |
| 20 | } |
| 21 | |
| 22 | /* Decoded GTP1U (User Plane), used in send and receive direction */ |
| 23 | type record Gtp1uUnitdata { |
| 24 | GtpPeer peer, |
| 25 | PDU_GTPU gtpu |
| 26 | } |
| 27 | |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame^] | 28 | /* Translation port on top of IPL4asp; ASP_Event passed through transparently */ |
| 29 | type port GTPC_PT message map to IPL4asp_PT { |
| 30 | out Gtp1cUnitdata to ASP_SendTo with f_enc_Gtp1cUD(); |
| 31 | in Gtp1cUnitdata from ASP_RecvFrom with f_dec_Gtp1cUD(), |
| 32 | ASP_Event; |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 33 | /* we can declare variables here and use them from all functions with "port" label */ |
| 34 | } |
| 35 | |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame^] | 36 | function f_enc_Gtp1cUD(in Gtp1cUnitdata in_ud, out ASP_SendTo out_ud) port GTPC_PT { |
| 37 | out_ud.connId := in_ud.peer.connId; |
| 38 | out_ud.remName := in_ud.peer.remName; |
| 39 | out_ud.remPort := in_ud.peer.remPort; |
| 40 | out_ud.proto := { udp := {} }; |
| 41 | out_ud.msg := enc_PDU_GTPC(in_ud.gtpc); |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 42 | port.setstate(0); |
| 43 | } with { extension "prototype(fast)" }; |
| 44 | |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame^] | 45 | function f_dec_Gtp1cUD(in ASP_RecvFrom in_ud, out Gtp1cUnitdata out_ud) port GTPC_PT { |
| 46 | out_ud.peer.connId := in_ud.connId; |
| 47 | out_ud.peer.remName := in_ud.remName; |
| 48 | out_ud.peer.remPort := in_ud.remPort; |
| 49 | out_ud.gtpc := dec_PDU_GTPC(in_ud.msg); |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 50 | port.setstate(0); |
| 51 | } with { extension "prototype(fast)" }; |
| 52 | |
| 53 | |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame^] | 54 | /* Translation port on top of IPL4asp; ASP_Event passed through transparently */ |
| 55 | type port GTPU_PT message map to IPL4asp_PT { |
| 56 | out Gtp1uUnitdata to ASP_SendTo with f_enc_Gtp1uUD(); |
| 57 | in Gtp1uUnitdata from ASP_RecvFrom with f_dec_Gtp1uUD(), |
| 58 | ASP_Event; |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 59 | /* we can declare variables here and use them from all functions with "port" label */ |
| 60 | } |
| 61 | |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame^] | 62 | function f_enc_Gtp1uUD(in Gtp1uUnitdata in_ud, out ASP_SendTo out_ud) port GTPU_PT { |
| 63 | out_ud.connId := in_ud.peer.connId; |
| 64 | out_ud.remName := in_ud.peer.remName; |
| 65 | out_ud.remPort := in_ud.peer.remPort; |
| 66 | out_ud.proto := { udp := {} }; |
| 67 | out_ud.msg := enc_PDU_GTPU(in_ud.gtpu); |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 68 | port.setstate(0); |
| 69 | } with { extension "prototype(fast)" }; |
| 70 | |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame^] | 71 | function f_dec_Gtp1uUD(in ASP_RecvFrom in_ud, out Gtp1uUnitdata out_ud) port GTPU_PT { |
| 72 | out_ud.peer.connId := in_ud.connId; |
| 73 | out_ud.peer.remName := in_ud.remName; |
| 74 | out_ud.peer.remPort := in_ud.remPort; |
| 75 | out_ud.gtpu := dec_PDU_GTPU(in_ud.msg); |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 76 | port.setstate(0); |
| 77 | } with { extension "prototype(fast)" }; |
Harald Welte | 627c7c7 | 2017-08-03 18:17:02 +0200 | [diff] [blame^] | 78 | /* |
| 79 | function f_GTPC_listen(inout GTPC_PT portRef, in HostName locName, |
| 80 | in PortNumber locPort) return Result { |
| 81 | return f_IPL4_listen(portRef, locName, locPort, { udp := {} }); |
| 82 | } |
| 83 | */ |
Harald Welte | 2560608 | 2017-08-03 17:00:40 +0200 | [diff] [blame] | 84 | } |