Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 1 | module PGW_Tests { |
| 2 | |
Pau Espin Pedrol | e343a88 | 2022-05-18 18:51:11 +0200 | [diff] [blame] | 3 | import from TCCEncoding_Functions all; |
| 4 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 5 | import from General_Types all; |
| 6 | import from Osmocom_Types all; |
| 7 | import from Native_Functions all; |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 8 | import from Misc_Helpers all; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 9 | |
| 10 | import from GTPv2_Types all; |
| 11 | import from GTPv2_Templates all; |
| 12 | import from GTPv2_Emulation all; |
| 13 | |
| 14 | import from UECUPS_Types all; |
| 15 | |
| 16 | import from DNS_Helpers all; |
| 17 | |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 18 | |
| 19 | import from DIAMETER_Types all; |
| 20 | import from DIAMETER_Templates all; |
Pau Espin Pedrol | 867b130 | 2024-01-24 16:14:28 +0100 | [diff] [blame] | 21 | import from DIAMETER_ts29_212_Templates all; |
Pau Espin Pedrol | 117a94f | 2023-12-21 16:10:12 +0100 | [diff] [blame] | 22 | import from DIAMETER_ts29_272_Templates all; |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 23 | import from DIAMETER_ts29_273_Templates all; |
Pau Espin Pedrol | 867b130 | 2024-01-24 16:14:28 +0100 | [diff] [blame] | 24 | import from DIAMETER_ts32_299_Templates all; |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 25 | import from DIAMETER_Emulation all; |
| 26 | |
| 27 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 28 | modulepar { |
Vadim Yanitskiy | 589972f | 2022-01-20 19:38:16 +0600 | [diff] [blame] | 29 | charstring mp_pgw_hostname := "127.0.0.4"; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 30 | charstring mp_local_hostname_c := "127.0.0.1"; |
| 31 | charstring mp_local_hostname_u := "127.0.0.1"; |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 32 | |
Vadim Yanitskiy | 284c68e | 2022-02-02 22:30:37 +0600 | [diff] [blame] | 33 | charstring mp_run_prog_log_path := "/tmp"; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 34 | charstring mp_run_prog_as_user := "laforge"; |
| 35 | charstring mp_ping_hostname := "10.45.0.1"; |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 36 | |
Vadim Yanitskiy | 589972f | 2022-01-20 19:38:16 +0600 | [diff] [blame] | 37 | charstring mp_pcrf_local_ip := "127.0.0.9"; |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 38 | integer mp_pcrf_local_port := 3868; |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 39 | |
| 40 | charstring mp_ocs_local_ip := "127.0.0.9"; |
| 41 | integer mp_ocs_local_port := 3869; |
Pau Espin Pedrol | e343a88 | 2022-05-18 18:51:11 +0200 | [diff] [blame] | 42 | |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 43 | charstring mp_aaa_local_ip := "127.0.0.9"; |
| 44 | integer mp_aaa_local_port := 3870; |
| 45 | |
Pau Espin Pedrol | e343a88 | 2022-05-18 18:51:11 +0200 | [diff] [blame] | 46 | charstring mp_diam_realm := "localdomain"; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /* main component, we typically have one per testcase */ |
Pau Espin Pedrol | bddba3a | 2024-01-09 12:17:01 +0100 | [diff] [blame] | 50 | type component PGW_Test_CT extends GTP2_ConnHdlr { |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 51 | var GTPv2_Emulation_CT vc_GTP2; |
| 52 | port GTP2EM_PT TEID0; |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 53 | |
| 54 | /* emulated PCRF */ |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 55 | var DIAMETER_Emulation_CT vc_Gx; |
| 56 | port DIAMETER_PT Gx_UNIT; |
| 57 | port DIAMETEREM_PROC_PT Gx_PROC; |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 58 | /* emulated OCS */ |
| 59 | var DIAMETER_Emulation_CT vc_Gy; |
| 60 | port DIAMETER_PT Gy_UNIT; |
| 61 | port DIAMETEREM_PROC_PT Gy_PROC; |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 62 | /* emulated AAA-Server */ |
| 63 | var DIAMETER_Emulation_CT vc_S6b; |
| 64 | port DIAMETER_PT S6b_UNIT; |
| 65 | port DIAMETEREM_PROC_PT S6b_PROC; |
Pau Espin Pedrol | 08880f1 | 2022-04-07 19:05:15 +0200 | [diff] [blame] | 66 | /* global test case guard timer (actual timeout value is set in f_init()) */ |
| 67 | timer T_guard; |
| 68 | } |
| 69 | |
| 70 | /* global altstep for global guard timer; */ |
| 71 | altstep as_Tguard() runs on PGW_Test_CT { |
| 72 | [] T_guard.timeout { |
| 73 | setverdict(fail, "Timeout of T_guard"); |
| 74 | mtc.stop; |
| 75 | } |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 76 | } |
| 77 | |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 78 | type component DIAMETER_ConnHdlr_CT extends DIAMETER_ConnHdlr { |
| 79 | port DIAMETER_Conn_PT DIAMETER_CLIENT; |
| 80 | } |
| 81 | |
| 82 | function f_diam_connhldr_ct_main(hexstring imsi) runs on DIAMETER_ConnHdlr_CT { |
| 83 | var PDU_DIAMETER msg; |
| 84 | |
| 85 | if (DIAMETER_PROC.checkstate("Connected")) { |
Pau Espin Pedrol | db017f4 | 2023-08-25 19:22:25 +0200 | [diff] [blame] | 86 | f_diameter_expect_imsi(imsi); |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | while (true) { |
| 90 | alt { |
| 91 | [] DIAMETER_CLIENT.receive(PDU_DIAMETER:?) -> value msg { |
| 92 | DIAMETER.send(msg); |
| 93 | } |
| 94 | [] DIAMETER.receive(PDU_DIAMETER:?) -> value msg { |
| 95 | DIAMETER_CLIENT.send(msg); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 102 | /* per-session component; we typically have 1..N per testcase */ |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 103 | type component PGW_Session_CT extends GTP2_ConnHdlr { |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 104 | var SessionPars g_pars; |
| 105 | |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 106 | port DIAMETER_Conn_PT Gx; |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 107 | port DIAMETER_Conn_PT Gy; |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 108 | port DIAMETER_Conn_PT S6b; |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 109 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 110 | /* GTP-U IPv4 address remote sie */ |
| 111 | var OCT4 g_gtpu4_remote; |
| 112 | var OCT16 g_gtpu6_remote; |
| 113 | |
| 114 | /* Address allocation */ |
| 115 | var OCT4 g_ip4_addr; |
| 116 | var OCT16 g_ip6_addr; |
| 117 | var integer g_ip6_plen; |
Pau Espin Pedrol | 2fde1ef | 2022-05-20 18:53:09 +0200 | [diff] [blame] | 118 | |
| 119 | /* Store last received Gy message */ |
| 120 | var PDU_DIAMETER g_rx_gy; |
Pau Espin Pedrol | 967d871 | 2023-02-28 16:09:32 +0100 | [diff] [blame] | 121 | |
| 122 | /* number of programs started, used as identifier. */ |
| 123 | var integer g_start_prog_count := 0; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 126 | type record BearerConfig { |
| 127 | /* EPS Bearer ID */ |
| 128 | uint4_t ebi optional, |
| 129 | /* TEI (Data) local side */ |
| 130 | OCT4 teid_local optional, |
| 131 | /* TEI (Data) remote side */ |
| 132 | OCT4 teid_remote optional |
| 133 | }; |
| 134 | |
Pau Espin Pedrol | 06fba9c | 2024-03-18 20:12:12 +0100 | [diff] [blame] | 135 | type record SessionParsGy { |
| 136 | /* In seconds. 0 => disabled, !0 => grant over CC-Time period */ |
| 137 | integer validity_time, |
| 138 | |
| 139 | /* Result-Code to use when sending Gy CCA, usually DIAMETER_SUCCESS */ |
| 140 | DIAMETER_Resultcode cca_res_code |
| 141 | }; |
| 142 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 143 | /* configuration data for a given Session */ |
| 144 | type record SessionPars { |
| 145 | hexstring imsi, |
Pau Espin Pedrol | e343a88 | 2022-05-18 18:51:11 +0200 | [diff] [blame] | 146 | hexstring msisdn optional, |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 147 | // serving network |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 148 | GTP2C_RAT_Type rat_type, |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 149 | // flags? |
| 150 | charstring apn, |
| 151 | /* Apn subscribed or non-subscribed */ |
| 152 | boolean selection_mode, |
| 153 | BIT3 pdn_type, |
| 154 | /* PAA */ |
| 155 | /* Max APN Restriction */ |
| 156 | /* APN-AMBR */ |
| 157 | octetstring pco optional, |
| 158 | octetstring epco optional, |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 159 | |
| 160 | /* TEI (Control) local side */ |
| 161 | OCT4 teic_local, |
| 162 | /* TEI (Control) remote side */ |
| 163 | OCT4 teic_remote optional, |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 164 | /* Bearer Contexts to be created */ |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 165 | BearerConfig bearer optional, |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 166 | |
| 167 | charstring tun_dev_name, |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 168 | charstring tun_netns_name optional, |
| 169 | |
Pau Espin Pedrol | 06fba9c | 2024-03-18 20:12:12 +0100 | [diff] [blame] | 170 | SessionParsGy gy |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | template (value) SessionPars |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 174 | t_SessionPars(hexstring imsi, |
| 175 | charstring tundev, |
| 176 | template (omit) hexstring msisdn := '1234'H, |
| 177 | GTP2C_RAT_Type rat_type := GTP2C_RAT_EUTRAN, |
| 178 | charstring apn := "internet", |
| 179 | boolean selection_mode := false, |
| 180 | BIT3 pdn_type := '001'B) := { |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 181 | imsi := imsi, |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 182 | msisdn := msisdn, |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 183 | rat_type := rat_type, |
| 184 | apn := apn, |
| 185 | selection_mode := selection_mode, |
| 186 | pdn_type := pdn_type, |
| 187 | pco := omit, |
| 188 | epco := omit, |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 189 | teic_local := '00000000'O, |
| 190 | teic_remote := omit, |
| 191 | bearer := { |
| 192 | ebi := 5, |
| 193 | teid_local := omit, |
| 194 | teid_remote := omit |
| 195 | }, |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 196 | tun_dev_name := tundev, |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 197 | tun_netns_name := tundev, |
Pau Espin Pedrol | 06fba9c | 2024-03-18 20:12:12 +0100 | [diff] [blame] | 198 | gy := { |
| 199 | validity_time := 0, |
| 200 | cca_res_code := DIAMETER_SUCCESS |
| 201 | } |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 202 | } |
| 203 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 204 | |
| 205 | type function void_fn() runs on PGW_Session_CT; |
| 206 | |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 207 | friend function DiameterForwardUnitdataCallback(PDU_DIAMETER msg) |
| 208 | runs on DIAMETER_Emulation_CT return template PDU_DIAMETER { |
| 209 | DIAMETER_UNIT.send(msg); |
| 210 | return omit; |
| 211 | } |
| 212 | |
| 213 | friend function f_init_diameter(charstring id) runs on PGW_Test_CT { |
| 214 | var DIAMETEROps ops := { |
| 215 | create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback), |
Vadim Yanitskiy | b46f01e | 2021-12-06 03:23:13 +0300 | [diff] [blame] | 216 | unitdata_cb := refers(DiameterForwardUnitdataCallback), |
| 217 | raw := false /* handler mode (IMSI based routing) */ |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 218 | }; |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 219 | var DIAMETER_conn_parameters pars; |
| 220 | |
| 221 | /* Gx setup: */ |
| 222 | pars := { |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 223 | remote_ip := mp_pgw_hostname, |
| 224 | remote_sctp_port := -1, |
| 225 | local_ip := mp_pcrf_local_ip, |
| 226 | local_sctp_port := mp_pcrf_local_port, |
Pau Espin Pedrol | e343a88 | 2022-05-18 18:51:11 +0200 | [diff] [blame] | 227 | origin_host := "pcrf." & mp_diam_realm, |
| 228 | origin_realm := mp_diam_realm, |
Pau Espin Pedrol | 33b4749 | 2022-03-08 17:43:01 +0100 | [diff] [blame] | 229 | auth_app_id := omit, |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 230 | vendor_app_id := c_DIAMETER_3GPP_Gx_AID |
| 231 | }; |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 232 | vc_Gx := DIAMETER_Emulation_CT.create(id); |
| 233 | map(vc_Gx:DIAMETER, system:DIAMETER_CODEC_PT); |
| 234 | connect(vc_Gx:DIAMETER_UNIT, self:Gx_UNIT); |
| 235 | connect(vc_Gx:DIAMETER_PROC, self:Gx_PROC); |
| 236 | vc_Gx.start(DIAMETER_Emulation.main(ops, pars, id)); |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 237 | |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 238 | /* Gy setup: */ |
| 239 | pars := { |
| 240 | remote_ip := mp_pgw_hostname, |
| 241 | remote_sctp_port := -1, |
| 242 | local_ip := mp_ocs_local_ip, |
| 243 | local_sctp_port := mp_ocs_local_port, |
Pau Espin Pedrol | e343a88 | 2022-05-18 18:51:11 +0200 | [diff] [blame] | 244 | origin_host := "ocs." & mp_diam_realm, |
| 245 | origin_realm := mp_diam_realm, |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 246 | auth_app_id := c_DIAMETER_CREDIT_CONTROL_AID, |
| 247 | vendor_app_id := omit |
| 248 | }; |
| 249 | vc_Gy := DIAMETER_Emulation_CT.create(id); |
| 250 | map(vc_Gy:DIAMETER, system:DIAMETER_CODEC_PT); |
| 251 | connect(vc_Gy:DIAMETER_UNIT, self:Gy_UNIT); |
| 252 | connect(vc_Gy:DIAMETER_PROC, self:Gy_PROC); |
| 253 | vc_Gy.start(DIAMETER_Emulation.main(ops, pars, id)); |
| 254 | |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 255 | /* S6b setup: */ |
| 256 | pars := { |
| 257 | remote_ip := mp_pgw_hostname, |
| 258 | remote_sctp_port := -1, |
| 259 | local_ip := mp_aaa_local_ip, |
| 260 | local_sctp_port := mp_aaa_local_port, |
| 261 | origin_host := "aaa." & mp_diam_realm, |
| 262 | origin_realm := mp_diam_realm, |
| 263 | auth_app_id := c_DIAMETER_3GPP_S6b_AID, |
| 264 | vendor_app_id := c_DIAMETER_3GPP_S6b_AID |
| 265 | }; |
| 266 | vc_S6b := DIAMETER_Emulation_CT.create(id); |
| 267 | map(vc_S6b:DIAMETER, system:DIAMETER_CODEC_PT); |
| 268 | connect(vc_S6b:DIAMETER_UNIT, self:S6b_UNIT); |
| 269 | connect(vc_S6b:DIAMETER_PROC, self:S6b_PROC); |
| 270 | vc_S6b.start(DIAMETER_Emulation.main(ops, pars, id)); |
| 271 | |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 272 | f_diameter_wait_capability(Gx_UNIT); |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 273 | f_diameter_wait_capability(Gy_UNIT); |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 274 | f_diameter_wait_capability(S6b_UNIT); |
Pau Espin Pedrol | bb5f45f | 2022-04-11 12:36:55 +0200 | [diff] [blame] | 275 | /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdong ping-pongs): |
| 276 | * RFC6733 sec 5.1 |
| 277 | * RFC3539 sec 3.4.1 [5] |
| 278 | * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49 |
| 279 | */ |
| 280 | f_sleep(1.0); |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 281 | } |
| 282 | |
Pau Espin Pedrol | 08880f1 | 2022-04-07 19:05:15 +0200 | [diff] [blame] | 283 | private function f_init(float guard_timeout := 60.0) runs on PGW_Test_CT { |
| 284 | T_guard.start(guard_timeout); |
| 285 | activate(as_Tguard()); |
| 286 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 287 | var Gtp2EmulationCfg cfg := { |
| 288 | gtpc_bind_ip := mp_local_hostname_c, |
| 289 | gtpc_bind_port := GTP2C_PORT, |
| 290 | gtpc_remote_ip := mp_pgw_hostname, |
| 291 | gtpc_remote_port := GTP2C_PORT, |
Pau Espin Pedrol | 297333a | 2024-03-05 11:25:50 +0100 | [diff] [blame] | 292 | gtpu_bind_ip := omit, /* using gtpu daemon */ |
| 293 | gtpu_bind_port := omit, /* using gtpu daemon */ |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 294 | sgw_role := true, |
| 295 | use_gtpu_daemon := true |
| 296 | }; |
| 297 | |
| 298 | vc_GTP2 := GTPv2_Emulation_CT.create("GTP2_EM"); |
| 299 | map(vc_GTP2:GTP2C, system:GTP2C); |
| 300 | connect(vc_GTP2:TEID0, self:TEID0); |
Pau Espin Pedrol | bddba3a | 2024-01-09 12:17:01 +0100 | [diff] [blame] | 301 | connect(vc_GTP2:CLIENT, self:GTP2); |
| 302 | connect(vc_GTP2:CLIENT_PROC, self:GTP2_PROC); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 303 | vc_GTP2.start(GTPv2_Emulation.main(cfg)); |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 304 | |
| 305 | if (mp_pcrf_local_ip != "") { |
| 306 | f_init_diameter(testcasename()); |
| 307 | } |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 308 | } |
| 309 | |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 310 | function f_start_handler(void_fn fn, template (omit) SessionPars pars_tmpl := omit) |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 311 | runs on PGW_Test_CT return PGW_Session_CT { |
| 312 | var charstring id := testcasename(); |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 313 | var DIAMETER_ConnHdlr_CT vc_conn_gx, vc_conn_gy, vc_conn_s6b; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 314 | var PGW_Session_CT vc_conn; |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 315 | var SessionPars pars; |
| 316 | |
| 317 | if (isvalue(pars_tmpl)) { |
| 318 | pars := valueof(pars_tmpl); |
| 319 | } else { |
| 320 | /*TODO: set default values */ |
| 321 | } |
| 322 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 323 | vc_conn := PGW_Session_CT.create(id); |
| 324 | connect(vc_conn:GTP2, vc_GTP2:CLIENT); |
| 325 | connect(vc_conn:GTP2_PROC, vc_GTP2:CLIENT_PROC); |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 326 | |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 327 | if (isbound(vc_Gx)) { |
| 328 | vc_conn_gx := DIAMETER_ConnHdlr_CT.create(id); |
| 329 | connect(vc_conn_gx:DIAMETER, vc_Gx:DIAMETER_CLIENT); |
| 330 | connect(vc_conn_gx:DIAMETER_PROC, vc_Gx:DIAMETER_PROC); |
| 331 | connect(vc_conn:Gx, vc_conn_gx:DIAMETER_CLIENT); |
| 332 | vc_conn_gx.start(f_diam_connhldr_ct_main(pars.imsi)); |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 333 | } |
| 334 | |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 335 | if (isbound(vc_Gy)) { |
| 336 | vc_conn_gy := DIAMETER_ConnHdlr_CT.create(id); |
| 337 | connect(vc_conn_gy:DIAMETER, vc_Gy:DIAMETER_CLIENT); |
| 338 | connect(vc_conn_gy:DIAMETER_PROC, vc_Gy:DIAMETER_PROC); |
| 339 | connect(vc_conn:Gy, vc_conn_gy:DIAMETER_CLIENT); |
| 340 | vc_conn_gy.start(f_diam_connhldr_ct_main(pars.imsi)); |
| 341 | } |
| 342 | |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 343 | if (isbound(vc_S6b)) { |
| 344 | vc_conn_s6b := DIAMETER_ConnHdlr_CT.create(id); |
| 345 | connect(vc_conn_s6b:DIAMETER, vc_S6b:DIAMETER_CLIENT); |
| 346 | connect(vc_conn_s6b:DIAMETER_PROC, vc_S6b:DIAMETER_PROC); |
| 347 | connect(vc_conn:S6b, vc_conn_s6b:DIAMETER_CLIENT); |
| 348 | vc_conn_s6b.start(f_diam_connhldr_ct_main(pars.imsi)); |
| 349 | } |
| 350 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 351 | vc_conn.start(f_handler_init(fn, pars)); |
| 352 | return vc_conn; |
| 353 | } |
| 354 | |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 355 | private function f_handler_init(void_fn fn, SessionPars pars) |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 356 | runs on PGW_Session_CT { |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 357 | g_pars := valueof(pars); |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 358 | /* allocate + register TEID-C on local side */ |
| 359 | g_pars.teic_local := f_gtp2_allocate_teid(); |
| 360 | g_pars.bearer.teid_local := g_pars.teic_local; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 361 | fn.apply(); |
| 362 | } |
| 363 | |
Harald Welte | fe595e4 | 2020-04-21 22:56:47 +0200 | [diff] [blame] | 364 | private function f_concat_pad(integer tot_len, hexstring prefix, integer suffix) return hexstring { |
| 365 | var integer suffix_len := tot_len - lengthof(prefix); |
| 366 | var charstring suffix_ch := int2str(suffix); |
| 367 | var integer pad_len := suffix_len - lengthof(suffix_ch); |
| 368 | |
| 369 | return prefix & int2hex(0, pad_len) & str2hex(suffix_ch); |
| 370 | } |
| 371 | |
| 372 | function f_gen_imei(integer suffix) return hexstring { |
| 373 | return f_concat_pad(14, '49999'H, suffix); |
| 374 | } |
| 375 | |
| 376 | function f_gen_imsi(integer suffix) return hexstring { |
| 377 | return f_concat_pad(15, '26242'H, suffix); |
| 378 | } |
| 379 | |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 380 | /* S6b emulation (AAA-Server) */ |
| 381 | private altstep as_DIA_S6b_AAR() runs on PGW_Session_CT { |
| 382 | var PDU_DIAMETER rx_dia; |
| 383 | [] S6b.receive(tr_DIA_S6b_AAR()) -> value rx_dia { |
| 384 | var template (omit) AVP avp; |
| 385 | var octetstring sess_id; |
| 386 | |
| 387 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id); |
| 388 | sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id); |
| 389 | |
| 390 | S6b.send(ts_DIA_S6b_AAA(sess_id, "aaa." & mp_diam_realm, |
| 391 | mp_diam_realm, mp_diam_realm, |
| 392 | rx_dia.hop_by_hop_id, rx_dia.end_to_end_id)); |
| 393 | setverdict(pass); |
| 394 | } |
| 395 | [] S6b.receive(PDU_DIAMETER:?) -> value rx_dia { |
| 396 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 397 | log2str("Received unexpected DIAMETER ", rx_dia)); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | /* Gx emulation (PCRF)*/ |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 402 | private altstep as_DIA_Gx_CCR(DCC_NONE_CC_Request_Type req_type) runs on PGW_Session_CT { |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 403 | var PDU_DIAMETER rx_dia; |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 404 | [] Gx.receive(tr_DIA_Gx_CCR(req_type := req_type)) -> value rx_dia { |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 405 | var template (omit) AVP avp; |
| 406 | var octetstring sess_id; |
| 407 | var AVP_Unsigned32 req_num; |
| 408 | |
| 409 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id); |
| 410 | sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id); |
| 411 | |
| 412 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number); |
| 413 | req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number); |
| 414 | |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 415 | Gx.send(ts_DIA_Gx_CCA(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id, |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 416 | req_type, req_num)); |
| 417 | } |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 418 | [] Gx.receive(PDU_DIAMETER:?) -> value rx_dia { |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 419 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 420 | log2str("Received unexpected DIAMETER ", rx_dia)); |
| 421 | } |
| 422 | } |
| 423 | |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 424 | /* Gy emulation (OCS) */ |
Pau Espin Pedrol | e343a88 | 2022-05-18 18:51:11 +0200 | [diff] [blame] | 425 | function f_tr_DIA_Gy_CCR(DCC_NONE_CC_Request_Type req_type) |
| 426 | runs on PGW_Session_CT return template (present) PDU_DIAMETER |
| 427 | { |
| 428 | var template (present) PDU_DIAMETER tpl; |
| 429 | var charstring smf_origin_host := "smf." & mp_diam_realm; |
| 430 | var template (present) octetstring imsi := ?; |
| 431 | var template (present) octetstring msisdn := ?; |
| 432 | var template (present) octetstring rat_type := ?; |
| 433 | var template (present) OCT4 charging_char := ?; |
| 434 | var template (present) OCT1 nsapi := ?; |
| 435 | imsi := char2oct(f_dec_TBCD(imsi_hex2oct(g_pars.imsi))); |
| 436 | //msisdn := char2oct(f_dec_TBCD(substr(ctx_val.msisdn, 1, lengthof(ctx_val.msisdn) -1))); |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 437 | rat_type := int2oct(enum2int(g_pars.rat_type), 1); |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 438 | charging_char := char2oct(oct2str('0000'O)); // f_s5s8_create_session() uses hardcoded chg_car := '0000'O |
| 439 | nsapi := int2oct(g_pars.bearer.ebi, 1); |
Pau Espin Pedrol | e343a88 | 2022-05-18 18:51:11 +0200 | [diff] [blame] | 440 | select (req_type) { |
| 441 | case (INITIAL_REQUEST) { |
| 442 | tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control, |
| 443 | avps := superset( |
| 444 | tr_AVP_SessionId, |
| 445 | tr_AVP_OriginHost(smf_origin_host), |
| 446 | tr_AVP_OriginRealm(mp_diam_realm), |
| 447 | tr_AVP_DestinationRealm(mp_diam_realm), |
| 448 | tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)), |
| 449 | tr_AVP_ServiceContextId, |
| 450 | tr_AVP_CcReqType(req_type), |
| 451 | tr_AVP_CcReqNum(?), |
| 452 | tr_AVP_EventTimestamp(?), |
| 453 | tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}), |
| 454 | tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}), |
| 455 | tr_AVP_RequestedAction(DIRECT_DEBITING), |
| 456 | tr_AVP_3GPP_AoCRequestType, |
| 457 | tr_AVP_MultipleServicesIndicator, |
| 458 | tr_AVP_Multiple_Services_Credit_Control(content := superset( |
| 459 | tr_AVP_Requested_Service_Unit, |
Pau Espin Pedrol | 6477d73 | 2022-06-03 12:04:40 +0200 | [diff] [blame] | 460 | tr_AVP_PCC_3GPP_QoS_Information, |
Pau Espin Pedrol | e343a88 | 2022-05-18 18:51:11 +0200 | [diff] [blame] | 461 | tr_AVP_GI_3GPP_RatType(rat_type) |
| 462 | )), |
| 463 | tr_AVP_3GPP_ServiceInformation(content := superset( |
| 464 | tr_AVP_3GPP_PSInformation(content := superset( |
| 465 | tr_AVP_3GPP_ChargingId, |
| 466 | tr_AVP_3GPP_PDPType((IPv4,IPv6,IPv4v6)), |
| 467 | tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)), |
| 468 | tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(mp_pcrf_local_ip))), |
| 469 | tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(mp_pgw_hostname))), |
| 470 | tr_AVP_3GPP_CalledStationId, |
| 471 | tr_AVP_3GPP_SelectionMode, |
| 472 | tr_AVP_3GPP_ChargingCharacteristics(charging_char), |
| 473 | tr_AVP_3GPP_SGSNMCCMNC, |
| 474 | tr_AVP_3GPP_NSAPI(nsapi), |
| 475 | /*We don't yet send MS_Tz in CreateSessionReq: |
| 476 | tr_AVP_3GPP_MS_TimeZone,*/ |
| 477 | tr_AVP_3GPP_ULI/*, |
| 478 | We don't yet send IMEI in CreateSessionReq: |
| 479 | tr_AVP_UserEquipmentInfo({ |
| 480 | tr_AVP_UserEquipmentInfoType(IMEISV), |
| 481 | tr_AVP_UserEquipmentInfoValue(imeisv) |
| 482 | })*/ |
| 483 | )) |
| 484 | )) |
| 485 | )); |
| 486 | } |
| 487 | case (UPDATE_REQUEST) { |
| 488 | tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control, |
| 489 | avps := superset( |
| 490 | tr_AVP_SessionId, |
| 491 | tr_AVP_OriginHost(smf_origin_host), |
| 492 | tr_AVP_OriginRealm(mp_diam_realm), |
| 493 | tr_AVP_DestinationRealm(mp_diam_realm), |
| 494 | tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)), |
| 495 | tr_AVP_ServiceContextId, |
| 496 | tr_AVP_CcReqType(req_type), |
| 497 | tr_AVP_CcReqNum(?), |
| 498 | tr_AVP_DestinationHost(?), |
| 499 | tr_AVP_EventTimestamp(?), |
| 500 | tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}), |
| 501 | tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}), |
| 502 | tr_AVP_RequestedAction(DIRECT_DEBITING), |
| 503 | tr_AVP_3GPP_AoCRequestType, |
Pau Espin Pedrol | e343a88 | 2022-05-18 18:51:11 +0200 | [diff] [blame] | 504 | tr_AVP_Multiple_Services_Credit_Control(content := superset( |
| 505 | tr_AVP_Requested_Service_Unit, |
| 506 | tr_AVP_Used_Service_Unit, |
Pau Espin Pedrol | cba0f6d | 2022-05-24 13:49:46 +0200 | [diff] [blame] | 507 | /* tr_AVP_3GPP_Reporting_Reason, can be sometimes inside UsedServiceUnit */ |
Pau Espin Pedrol | 6477d73 | 2022-06-03 12:04:40 +0200 | [diff] [blame] | 508 | tr_AVP_PCC_3GPP_QoS_Information, |
Pau Espin Pedrol | e343a88 | 2022-05-18 18:51:11 +0200 | [diff] [blame] | 509 | tr_AVP_GI_3GPP_RatType(rat_type) |
| 510 | )), |
| 511 | tr_AVP_3GPP_ServiceInformation(content := superset( |
| 512 | tr_AVP_3GPP_PSInformation(content := superset( |
| 513 | tr_AVP_3GPP_ChargingId, |
| 514 | /* tr_AVP_3GPP_PDPType, Only in INIT */ |
| 515 | tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)), |
| 516 | tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(mp_pcrf_local_ip))), |
| 517 | tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(mp_pgw_hostname))), |
| 518 | tr_AVP_3GPP_CalledStationId, |
| 519 | tr_AVP_3GPP_SelectionMode, |
| 520 | tr_AVP_3GPP_ChargingCharacteristics(charging_char), |
| 521 | tr_AVP_3GPP_SGSNMCCMNC, |
| 522 | tr_AVP_3GPP_NSAPI(nsapi), |
| 523 | /*We don't yet send MS_Tz in CreateSessionReq: |
| 524 | tr_AVP_3GPP_MS_TimeZone,*/ |
| 525 | tr_AVP_3GPP_ULI/*, |
| 526 | We don't yet send IMEI in CreateSessionReq: |
| 527 | tr_AVP_UserEquipmentInfo({ |
| 528 | tr_AVP_UserEquipmentInfoType(IMEISV), |
| 529 | tr_AVP_UserEquipmentInfoValue(imeisv) |
| 530 | })*/ |
| 531 | )) |
| 532 | )) |
| 533 | )); |
| 534 | } |
| 535 | case (TERMINATION_REQUEST) { |
| 536 | tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control, |
| 537 | avps := superset( |
| 538 | tr_AVP_SessionId, |
| 539 | tr_AVP_OriginHost(smf_origin_host), |
| 540 | tr_AVP_OriginRealm(mp_diam_realm), |
| 541 | tr_AVP_DestinationRealm(mp_diam_realm), |
| 542 | tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)), |
| 543 | tr_AVP_ServiceContextId, |
| 544 | tr_AVP_CcReqType(req_type), |
| 545 | tr_AVP_CcReqNum(?), |
| 546 | tr_AVP_DestinationHost(?), |
| 547 | tr_AVP_EventTimestamp(?), |
| 548 | tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}), |
| 549 | tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}), |
| 550 | tr_AVP_TerminationCause(?), |
| 551 | tr_AVP_RequestedAction(DIRECT_DEBITING), |
| 552 | tr_AVP_3GPP_AoCRequestType, |
Pau Espin Pedrol | e343a88 | 2022-05-18 18:51:11 +0200 | [diff] [blame] | 553 | tr_AVP_Multiple_Services_Credit_Control(content := superset( |
| 554 | /* tr_AVP_Requested_Service_Unit, Only in INIT and UPDATE */ |
| 555 | tr_AVP_Used_Service_Unit, |
Pau Espin Pedrol | cba0f6d | 2022-05-24 13:49:46 +0200 | [diff] [blame] | 556 | tr_AVP_3GPP_Reporting_Reason(FINAL), |
Pau Espin Pedrol | 6477d73 | 2022-06-03 12:04:40 +0200 | [diff] [blame] | 557 | tr_AVP_PCC_3GPP_QoS_Information, |
Pau Espin Pedrol | e343a88 | 2022-05-18 18:51:11 +0200 | [diff] [blame] | 558 | tr_AVP_GI_3GPP_RatType(rat_type) |
| 559 | )), |
| 560 | tr_AVP_3GPP_ServiceInformation(content := superset( |
| 561 | tr_AVP_3GPP_PSInformation(content := superset( |
| 562 | tr_AVP_3GPP_ChargingId, |
| 563 | /* tr_AVP_3GPP_PDPType, Only in INIT */ |
| 564 | tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)), |
| 565 | tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(mp_pcrf_local_ip))), |
| 566 | tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(mp_pgw_hostname))), |
| 567 | tr_AVP_3GPP_CalledStationId, |
| 568 | tr_AVP_3GPP_SelectionMode, |
| 569 | tr_AVP_3GPP_ChargingCharacteristics(charging_char), |
| 570 | tr_AVP_3GPP_SGSNMCCMNC, |
| 571 | tr_AVP_3GPP_NSAPI(nsapi), |
| 572 | /*We don't yet send MS_Tz in CreateSessionReq: |
| 573 | tr_AVP_3GPP_MS_TimeZone,*/ |
| 574 | tr_AVP_3GPP_ULI/*, |
| 575 | We don't yet send IMEI in CreateSessionReq: |
| 576 | tr_AVP_UserEquipmentInfo({ |
| 577 | tr_AVP_UserEquipmentInfoType(IMEISV), |
| 578 | tr_AVP_UserEquipmentInfoValue(imeisv) |
| 579 | })*/ |
| 580 | )) |
| 581 | )) |
| 582 | )); |
| 583 | } |
| 584 | } |
| 585 | return tpl; |
| 586 | } |
| 587 | |
Pau Espin Pedrol | 06fba9c | 2024-03-18 20:12:12 +0100 | [diff] [blame] | 588 | function f_ts_DIA_Gy_CCA(PDU_DIAMETER rx_gy) |
| 589 | runs on PGW_Session_CT return template (value) PDU_DIAMETER |
| 590 | { |
| 591 | var template (value) PDU_DIAMETER tx_dia; |
| 592 | var template (omit) AVP avp; |
| 593 | var octetstring sess_id; |
| 594 | var AVP_Unsigned32 req_num; |
| 595 | var DCC_NONE_CC_Request_Type req_type; |
| 596 | var DIAMETER_Resultcode cca_res_code_success := DIAMETER_SUCCESS; |
| 597 | |
| 598 | avp := f_DIAMETER_get_avp(rx_gy, c_AVP_Code_BASE_NONE_Session_Id); |
| 599 | sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id); |
| 600 | |
| 601 | avp := f_DIAMETER_get_avp(rx_gy, c_AVP_Code_DCC_NONE_CC_Request_Type); |
| 602 | req_type := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Type); |
| 603 | |
| 604 | avp := f_DIAMETER_get_avp(rx_gy, c_AVP_Code_DCC_NONE_CC_Request_Number); |
| 605 | req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number); |
| 606 | |
| 607 | if (g_pars.gy.cca_res_code != cca_res_code_success) { |
| 608 | tx_dia := ts_DIA_Gy_CCA(rx_gy.hop_by_hop_id, rx_gy.end_to_end_id, sess_id, |
| 609 | g_pars.gy.cca_res_code, req_type, req_num); |
| 610 | } else if (g_pars.gy.validity_time > 0) { |
| 611 | tx_dia := ts_DIA_Gy_CCA_ValidityTime(rx_gy.hop_by_hop_id, rx_gy.end_to_end_id, sess_id, |
| 612 | req_type, req_num, g_pars.gy.validity_time); |
| 613 | } else { |
| 614 | tx_dia := ts_DIA_Gy_CCA(rx_gy.hop_by_hop_id, rx_gy.end_to_end_id, sess_id, |
| 615 | g_pars.gy.cca_res_code, req_type, req_num); |
| 616 | } |
| 617 | return tx_dia; |
| 618 | } |
| 619 | |
Pau Espin Pedrol | 2fde1ef | 2022-05-20 18:53:09 +0200 | [diff] [blame] | 620 | private altstep as_DIA_Gy_CCR(DCC_NONE_CC_Request_Type req_type) |
| 621 | runs on PGW_Session_CT { |
| 622 | [] Gy.receive(f_tr_DIA_Gy_CCR(req_type := req_type)) -> value g_rx_gy { |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 623 | var template (value) PDU_DIAMETER tx_dia; |
Pau Espin Pedrol | 06fba9c | 2024-03-18 20:12:12 +0100 | [diff] [blame] | 624 | tx_dia := f_ts_DIA_Gy_CCA(g_rx_gy); |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 625 | Gy.send(tx_dia); |
| 626 | } |
Pau Espin Pedrol | 2fde1ef | 2022-05-20 18:53:09 +0200 | [diff] [blame] | 627 | [] Gy.receive(PDU_DIAMETER:?) -> value g_rx_gy { |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 628 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
Pau Espin Pedrol | 2fde1ef | 2022-05-20 18:53:09 +0200 | [diff] [blame] | 629 | log2str("Received unexpected DIAMETER Gy", g_rx_gy)); |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 630 | } |
| 631 | } |
| 632 | |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 633 | /* GTPv2C */ |
| 634 | private function is_s2b_iface() runs on PGW_Session_CT return boolean { |
| 635 | return (g_pars.rat_type == GTP2C_RAT_WLAN or g_pars.rat_type == GTP2C_RAT_Virtual); |
| 636 | } |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 637 | |
| 638 | /* find TEID of given interface type (and optionally instance) */ |
| 639 | private function f_find_teid(FullyQualifiedTEID_List list, |
| 640 | template (present) integer if_type, |
| 641 | template (present) BIT4 instance := ?) |
| 642 | return template (omit) FullyQualifiedTEID |
| 643 | { |
| 644 | var integer i; |
| 645 | for (i := 0; i < lengthof(list); i := i+1) { |
| 646 | if (match(list[i].interfaceType, if_type) and |
| 647 | match(list[i].instance, instance)) { |
| 648 | return list[i]; |
| 649 | } |
| 650 | } |
| 651 | return omit; |
| 652 | } |
| 653 | |
| 654 | /* process one to-be-created bearer context */ |
| 655 | private function process_bctx_create(BearerContextGrouped bctx) runs on PGW_Session_CT |
| 656 | { |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 657 | g_pars.bearer.ebi := bctx.bearerContextIEs.ePS_Bearer_ID.ePS_Bearer_ID_Value; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 658 | /* FIXME: Cause */ |
| 659 | |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 660 | var integer exp_fteid_if_type; |
| 661 | var BIT4 exp_fteid_instance; |
| 662 | if (is_s2b_iface()) { |
| 663 | exp_fteid_if_type := 33; |
| 664 | exp_fteid_instance := '0100'B; |
| 665 | } else { |
| 666 | exp_fteid_if_type := 5; |
| 667 | exp_fteid_instance := '0010'B; |
| 668 | } |
| 669 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 670 | /* find F-TEID of the P-GW U side */ |
| 671 | var FullyQualifiedTEID rx_fteid; |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 672 | rx_fteid := valueof(f_find_teid(bctx.bearerContextIEs.fullyQualifiedTEID, |
| 673 | exp_fteid_if_type, exp_fteid_instance)); |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 674 | g_pars.bearer.teid_remote := rx_fteid.tEID_GRE_Key; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 675 | if (rx_fteid.v4_Flag == '1'B) { |
| 676 | g_gtpu4_remote := rx_fteid.iPv4_Address; |
| 677 | } |
| 678 | if (rx_fteid.v6_Flag == '1'B) { |
| 679 | g_gtpu6_remote := rx_fteid.iPv6_Address; |
| 680 | } |
| 681 | |
| 682 | var UECUPS_CreateTun uecups_create := { |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 683 | tx_teid := oct2int(g_pars.bearer.teid_remote), |
| 684 | rx_teid := oct2int(g_pars.bearer.teid_local), |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 685 | user_addr_type := IPV4, |
| 686 | user_addr := '00000000'O, |
| 687 | local_gtp_ep := valueof(ts_UECUPS_SockAddr(f_inet_addr(mp_local_hostname_u))), |
| 688 | remote_gtp_ep := valueof(ts_UECUPS_SockAddr(g_gtpu4_remote)), |
| 689 | tun_dev_name := g_pars.tun_dev_name, |
| 690 | tun_netns_name := g_pars.tun_netns_name |
| 691 | }; |
| 692 | |
| 693 | /* create tunnel in daemon */ |
| 694 | if (isbound(g_ip4_addr)) { |
| 695 | uecups_create.user_addr := g_ip4_addr; |
| 696 | f_gtp2_create_tunnel(uecups_create); |
| 697 | } |
| 698 | if (isbound(g_ip6_addr)) { |
| 699 | uecups_create.user_addr_type := IPV6; |
| 700 | uecups_create.user_addr := g_ip6_addr; |
| 701 | f_gtp2_create_tunnel(uecups_create); |
| 702 | } |
| 703 | } |
| 704 | |
| 705 | /* create a session on the PGW */ |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 706 | private function f_create_session(template (value) FullyQualifiedTEID fteid_c_ie, |
| 707 | template (value) FullyQualifiedTEID fteid_u_ie, |
Pau Espin Pedrol | 4ecc808 | 2024-02-26 15:28:12 +0100 | [diff] [blame] | 708 | template (omit) UserLocationInfo uli_ie := omit, |
| 709 | template (omit) APCO apco := omit, |
| 710 | template APCO exp_apco := *) runs on PGW_Session_CT { |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 711 | var PDU_GTPCv2 rx; |
| 712 | |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 713 | /* Defaults used for s5/s8: */ |
| 714 | var boolean do_s6b := false; |
| 715 | var template APN_Restriction apn_restriction := ?; |
| 716 | /* Change behavior when on S2b: */ |
| 717 | if (is_s2b_iface()) { |
| 718 | do_s6b := true; |
| 719 | apn_restriction := omit; |
| 720 | } |
| 721 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 722 | var template (value) PDU_GTPCv2 g2c := |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 723 | ts_GTP2C_CreateSessionReq(imsi := g_pars.imsi, |
| 724 | msisdn := g_pars.msisdn, |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 725 | rat_type := enum2int(g_pars.rat_type), |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 726 | sender_fteid := fteid_c_ie, |
| 727 | apn := f_enc_dns_hostname(g_pars.apn), |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 728 | pdn_type := g_pars.pdn_type, |
| 729 | teid_list := { fteid_u_ie }, |
| 730 | chg_car := '0000'O, |
| 731 | bearer_id := g_pars.bearer.ebi, |
Pau Espin Pedrol | 4ecc808 | 2024-02-26 15:28:12 +0100 | [diff] [blame] | 732 | uli := uli_ie, |
| 733 | apco := apco); |
Vadim Yanitskiy | bada3c9 | 2022-01-20 18:59:07 +0600 | [diff] [blame] | 734 | g2c.gtpcv2_pdu.createSessionRequest.servingNetwork := ts_GTP2C_ServingNetwork('001'H, '01F'H); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 735 | |
| 736 | GTP2.send(g2c); |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 737 | if (do_s6b and S6b.checkstate("Connected")) { |
| 738 | as_DIA_S6b_AAR(); |
| 739 | } |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 740 | if (Gx.checkstate("Connected")) { |
| 741 | as_DIA_Gx_CCR(INITIAL_REQUEST); |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 742 | } |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 743 | /* FIXME: When on S2b interface, SMF is not using the Gy interface, unknown reason. */ |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 744 | if (Gy.checkstate("Connected")) { |
| 745 | as_DIA_Gy_CCR(INITIAL_REQUEST); |
| 746 | } |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 747 | alt { |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 748 | [] GTP2.receive(tr_GTP2C_CreateSessionResp(d_teid := g_pars.teic_local, |
| 749 | cause := Request_accepted, |
Pau Espin Pedrol | 4ecc808 | 2024-02-26 15:28:12 +0100 | [diff] [blame] | 750 | apn_restriction := apn_restriction, |
| 751 | exp_apco := exp_apco)) -> value rx { |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 752 | /* extract TEIDs */ |
| 753 | var CreateSessionResponse resp := rx.gtpcv2_pdu.createSessionResponse; |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 754 | g_pars.teic_remote := resp.fullyQualifiedTEID[0].tEID_GRE_Key; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 755 | |
| 756 | /* extract allocated address[es] */ |
| 757 | var PDN_Address_and_Prefix paa := resp.pDN_AddressAllocation.pDN_Address_and_Prefix; |
| 758 | if (ischosen(paa.iPv4_Address)) { |
| 759 | g_ip4_addr := paa.iPv4_Address; |
| 760 | } else if (ischosen(paa.iPv6_Address)) { |
| 761 | g_ip6_addr := paa.iPv6_Address.iPv6_Address; |
| 762 | g_ip6_plen := paa.iPv6_Address.prefixLength; |
| 763 | } else if (ischosen(paa.iPv4_IPv6)) { |
| 764 | g_ip4_addr := paa.iPv4_IPv6.iPv4_Address; |
| 765 | g_ip6_addr := paa.iPv4_IPv6.iPv6_Address; |
| 766 | g_ip6_plen := paa.iPv4_IPv6.prefixLength; |
| 767 | } |
| 768 | var integer i; |
| 769 | for (i := 0; i < lengthof(resp.bearerContextGrouped); i := i+1) { |
| 770 | var BearerContextGrouped bctx := resp.bearerContextGrouped[i]; |
| 771 | select (bctx.instance) { |
| 772 | case ('0000'B) { // created |
| 773 | process_bctx_create(bctx); |
| 774 | } |
| 775 | case ('0001'B) { // removed |
Pau Espin Pedrol | f97f6e2 | 2023-02-28 14:13:42 +0100 | [diff] [blame] | 776 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 777 | "We don't expect removed bearer contexts yet"); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 778 | } |
| 779 | } |
| 780 | } |
| 781 | } |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 782 | [] GTP2.receive(tr_GTP2C_CreateSessionResp(d_teid:=g_pars.teic_local, cause:=?)) -> value rx { |
Pau Espin Pedrol | f97f6e2 | 2023-02-28 14:13:42 +0100 | [diff] [blame] | 783 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 784 | log2str("Unexpected CreateSessionResp(cause=", |
| 785 | rx.gtpcv2_pdu.createSessionResponse.cause.causeValue, ")")); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 786 | } |
| 787 | [] GTP2.receive { |
Pau Espin Pedrol | f97f6e2 | 2023-02-28 14:13:42 +0100 | [diff] [blame] | 788 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 789 | "Unexpected GTPv2 while waiting for CreateSessionResp"); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | |
| 793 | } |
| 794 | |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 795 | /* create a session on the PGW on a S5/S8 interface (from SGW )*/ |
| 796 | private function f_s5s8_create_session() runs on PGW_Session_CT { |
| 797 | var template (value) FullyQualifiedTEID fteid_c_ie, fteid_u_ie; |
| 798 | var template (value) UserLocationInfo uli_ie; |
| 799 | |
| 800 | fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_SGW_GTPC, g_pars.teic_local, 0, |
| 801 | f_inet_addr(mp_local_hostname_c), omit); |
| 802 | fteid_u_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_SGW_GTPU, g_pars.bearer.teid_local, 2, |
| 803 | f_inet_addr(mp_local_hostname_u), omit); |
| 804 | |
| 805 | |
| 806 | /* open5gs up to 1.2.3 won't accept it without ULI, despite not mandatory */ |
| 807 | var template (value) TAI tai := { '0'H, '0'H, '1'H, 'F'H, '0'H, '1'H, '0001'O }; |
| 808 | var template (value) ECGI ecgi := { '0'H, '0'H, '1'H, 'F'H, '0'H, '1'H, '0'H, 23 }; |
| 809 | uli_ie := ts_GTP2C_UserLocInfo(tai := tai, ecgi := ecgi); |
| 810 | |
| 811 | f_create_session(fteid_c_ie, fteid_u_ie, uli_ie); |
| 812 | |
| 813 | } |
| 814 | |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 815 | /* create a session on the PGW on a S2b interface (from ePDG)*/ |
Pau Espin Pedrol | 4ecc808 | 2024-02-26 15:28:12 +0100 | [diff] [blame] | 816 | private function f_s2b_create_session(template (omit) APCO apco := omit, |
| 817 | template APCO exp_apco := *) runs on PGW_Session_CT { |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 818 | var template (value) FullyQualifiedTEID fteid_c_ie, fteid_u_ie; |
| 819 | var template (value) UserLocationInfo uli_ie; |
| 820 | |
| 821 | fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S2b_ePDG_GTPC, g_pars.teic_local, 0, |
| 822 | f_inet_addr(mp_local_hostname_c), omit); |
| 823 | fteid_u_ie := ts_GTP2C_FTEID(FTEID_IF_S2bU_ePDG_GTPU, g_pars.bearer.teid_local, 5, |
| 824 | f_inet_addr(mp_local_hostname_u), omit); |
Pau Espin Pedrol | 4ecc808 | 2024-02-26 15:28:12 +0100 | [diff] [blame] | 825 | |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 826 | var template (value) TAI tai := { '0'H, '0'H, '1'H, 'F'H, '0'H, '1'H, '0001'O }; |
| 827 | var template (value) ECGI ecgi := { '0'H, '0'H, '1'H, 'F'H, '0'H, '1'H, '0'H, 23 }; |
| 828 | uli_ie := ts_GTP2C_UserLocInfo(tai := tai, ecgi := ecgi); |
| 829 | |
Pau Espin Pedrol | 4ecc808 | 2024-02-26 15:28:12 +0100 | [diff] [blame] | 830 | f_create_session(fteid_c_ie, fteid_u_ie, uli_ie := uli_ie, apco := apco, exp_apco := exp_apco); |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 831 | |
| 832 | } |
| 833 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 834 | /* delete the session from the PGW */ |
Pau Espin Pedrol | 1344e47 | 2023-10-23 19:54:29 +0200 | [diff] [blame] | 835 | private function f_delete_session(template (omit) GTP2C_Cause tx_cause := omit, |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 836 | template (present) OCT4 exp_teid, |
Pau Espin Pedrol | 1344e47 | 2023-10-23 19:54:29 +0200 | [diff] [blame] | 837 | template (present) GTP2C_Cause exp_cause, |
Pau Espin Pedrol | 5b0327b | 2022-04-11 13:02:36 +0200 | [diff] [blame] | 838 | boolean expect_diameter := true) runs on PGW_Session_CT { |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 839 | var template (value) FullyQualifiedTEID fteid_c_ie |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 840 | fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_SGW_GTPC, g_pars.teic_local, 0, |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 841 | f_inet_addr(mp_local_hostname_c), omit); |
| 842 | var template PDU_GTPCv2 g2c := |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 843 | ts_GTP2C_DeleteSessionReq(d_teid := g_pars.teic_remote, cause := tx_cause, |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 844 | sender_fteid := fteid_c_ie, |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 845 | teid_list := {}, bearer_id := g_pars.bearer.ebi); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 846 | |
| 847 | GTP2.send(g2c); |
Pau Espin Pedrol | 8b3123f | 2022-04-20 17:17:05 +0200 | [diff] [blame] | 848 | if (Gx.checkstate("Connected") and expect_diameter) { |
| 849 | as_DIA_Gx_CCR(TERMINATION_REQUEST); |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 850 | } |
Pau Espin Pedrol | 251d064 | 2022-04-20 18:16:45 +0200 | [diff] [blame] | 851 | if (Gy.checkstate("Connected") and expect_diameter) { |
| 852 | as_DIA_Gy_CCR(TERMINATION_REQUEST); |
| 853 | } |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 854 | alt { |
| 855 | [] GTP2.receive(tr_GTP2C_DeleteSessionResp(d_teid := exp_teid, cause := exp_cause)) { |
| 856 | setverdict(pass); |
| 857 | } |
| 858 | [] GTP2.receive(tr_GTP2C_DeleteSessionResp(?, ?)) { |
Pau Espin Pedrol | f97f6e2 | 2023-02-28 14:13:42 +0100 | [diff] [blame] | 859 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 860 | "Unexpected DeleteSessionResp"); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 861 | } |
| 862 | [] GTP2.receive { |
Pau Espin Pedrol | f97f6e2 | 2023-02-28 14:13:42 +0100 | [diff] [blame] | 863 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 864 | "Unexpected GTPv2 while waiting for DeleteSessionResp"); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 865 | } |
| 866 | } |
| 867 | |
| 868 | /* destroy tunnel in daemon */ |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 869 | if (isbound(g_pars.bearer.teid_local)) { |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 870 | var UECUPS_DestroyTun uecups_destroy := { |
| 871 | local_gtp_ep := valueof(ts_UECUPS_SockAddr(f_inet_addr(mp_local_hostname_u))), |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 872 | rx_teid := oct2int(g_pars.bearer.teid_local) |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 873 | }; |
| 874 | /* FIXME: what about IPv4/IPv6 differentiation? */ |
| 875 | f_gtp2_destroy_tunnel(uecups_destroy); |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | /* start a program on the user plane side; return its PID */ |
Vadim Yanitskiy | 284c68e | 2022-02-02 22:30:37 +0600 | [diff] [blame] | 880 | private function f_start_prog(charstring command, boolean redirect_output := true) |
| 881 | runs on PGW_Session_CT return integer |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 882 | { |
| 883 | var UECUPS_StartProgram sprog := { |
| 884 | command := command, |
| 885 | environment := {}, |
| 886 | run_as_user := mp_run_prog_as_user, |
| 887 | tun_netns_name := g_pars.tun_netns_name |
| 888 | }; |
Pau Espin Pedrol | 967d871 | 2023-02-28 16:09:32 +0100 | [diff] [blame] | 889 | g_start_prog_count := g_start_prog_count + 1; |
Vadim Yanitskiy | 284c68e | 2022-02-02 22:30:37 +0600 | [diff] [blame] | 890 | |
| 891 | /* Redirect stdout/stderr to the user-specified location */ |
| 892 | if (redirect_output) { |
Pau Espin Pedrol | 967d871 | 2023-02-28 16:09:32 +0100 | [diff] [blame] | 893 | var charstring id := testcasename() & "-" & hex2str(g_pars.imsi) & "-" & int2str(g_start_prog_count); |
| 894 | var charstring prefix := mp_run_prog_log_path & "/" & id; |
Vadim Yanitskiy | 284c68e | 2022-02-02 22:30:37 +0600 | [diff] [blame] | 895 | sprog.command := sprog.command & " 1>>" & prefix & ".prog.stdout"; |
| 896 | sprog.command := sprog.command & " 2>>" & prefix & ".prog.stderr"; |
| 897 | } |
| 898 | |
Vadim Yanitskiy | 36ab797 | 2022-02-01 20:46:05 +0600 | [diff] [blame] | 899 | log("Starting a program: ", command); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 900 | var UECUPS_StartProgramRes res := f_gtp2_start_program(sprog); |
| 901 | if (res.result != OK) { |
Pau Espin Pedrol | f97f6e2 | 2023-02-28 14:13:42 +0100 | [diff] [blame] | 902 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 903 | log2str("Unable to start program '", command, "'")); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 904 | } |
Pau Espin Pedrol | 967d871 | 2023-02-28 16:09:32 +0100 | [diff] [blame] | 905 | log("Started program '", command, "' with PID ", res.pid); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 906 | return res.pid; |
| 907 | } |
| 908 | |
| 909 | /* wait for termination of a given PID with specified exit_code */ |
| 910 | private function f_wait_term(integer pid, template (present) integer exit_code := 0, |
| 911 | float tout := 10.0) runs on PGW_Session_CT |
| 912 | { |
Vadim Yanitskiy | 36ab797 | 2022-02-01 20:46:05 +0600 | [diff] [blame] | 913 | var UECUPS_ProgramTermInd pti; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 914 | timer T := tout; |
| 915 | |
| 916 | T.start; |
| 917 | alt { |
| 918 | [] GTP2.receive(UECUPS_ProgramTermInd:{pid := pid, exit_code := exit_code}) { |
| 919 | setverdict(pass); |
| 920 | } |
Vadim Yanitskiy | 36ab797 | 2022-02-01 20:46:05 +0600 | [diff] [blame] | 921 | [] GTP2.receive(UECUPS_ProgramTermInd:?) -> value pti { |
Pau Espin Pedrol | f97f6e2 | 2023-02-28 14:13:42 +0100 | [diff] [blame] | 922 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 923 | log2str("Received unexpected ProgramTermInd := ", pti)); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 924 | } |
| 925 | [] T.timeout { |
Pau Espin Pedrol | f97f6e2 | 2023-02-28 14:13:42 +0100 | [diff] [blame] | 926 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
Pau Espin Pedrol | 967d871 | 2023-02-28 16:09:32 +0100 | [diff] [blame] | 927 | log2str("timeout (", tout, " seconds) waiting for user-plane program PID ", pid, " termination")); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 928 | } |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | /* execute a program and wait for result */ |
Vadim Yanitskiy | 284c68e | 2022-02-02 22:30:37 +0600 | [diff] [blame] | 933 | private function f_start_prog_wait(charstring command, |
| 934 | template integer exit_code := 0, |
| 935 | float tout := 10.0, |
| 936 | boolean redirect_output := true) |
| 937 | runs on PGW_Session_CT |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 938 | { |
Vadim Yanitskiy | 284c68e | 2022-02-02 22:30:37 +0600 | [diff] [blame] | 939 | var integer pid := f_start_prog(command, redirect_output); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 940 | f_wait_term(pid, exit_code, tout); |
| 941 | } |
| 942 | |
| 943 | /* execute ping command and wait for result */ |
| 944 | private function f_ping4(charstring host, integer interval := 1, integer count := 10) runs on PGW_Session_CT |
| 945 | { |
| 946 | var charstring ping :="ping -c " & int2str(count) & " -i " & int2str(interval); |
Pau Espin Pedrol | 55980c4 | 2023-02-28 12:40:52 +0100 | [diff] [blame] | 947 | |
| 948 | if (not isbound(g_ip4_addr)) { |
| 949 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "f_ping4(): g_ip4_addr is unset!"); |
| 950 | } |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 951 | ping := ping & " -I " & f_inet_ntoa(g_ip4_addr); |
| 952 | ping := ping & " " & host; |
Harald Welte | 8cfdc7c | 2020-04-21 22:48:34 +0200 | [diff] [blame] | 953 | f_start_prog_wait(ping, tout := int2float(5 + interval*count)); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | |
| 957 | |
| 958 | |
| 959 | /* send echo request; expect response */ |
| 960 | testcase TC_tx_echo() runs on PGW_Test_CT { |
| 961 | timer T := 5.0; |
| 962 | |
| 963 | f_init(); |
| 964 | |
Pau Espin Pedrol | bddba3a | 2024-01-09 12:17:01 +0100 | [diff] [blame] | 965 | GTP2.send(ts_GTP2C_EchoReq(0)); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 966 | T.start; |
| 967 | alt { |
Pau Espin Pedrol | bddba3a | 2024-01-09 12:17:01 +0100 | [diff] [blame] | 968 | [] GTP2.receive(tr_GTP2C_EchoResp) { |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 969 | setverdict(pass); |
| 970 | } |
| 971 | [] T.timeout { |
Pau Espin Pedrol | f97f6e2 | 2023-02-28 14:13:42 +0100 | [diff] [blame] | 972 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "timeout waiting for Echo Response"); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 973 | } |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | /* create a session, expect it to succeed */ |
| 978 | private function f_TC_createSession() runs on PGW_Session_CT { |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 979 | f_s5s8_create_session(); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 980 | setverdict(pass); |
| 981 | } |
| 982 | testcase TC_createSession() runs on PGW_Test_CT { |
| 983 | var PGW_Session_CT vc_conn; |
| 984 | var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun22")); |
| 985 | f_init(); |
| 986 | vc_conn := f_start_handler(refers(f_TC_createSession), pars); |
| 987 | vc_conn.done; |
| 988 | } |
| 989 | |
| 990 | /* create a session, then execute a ping command on the user plane */ |
| 991 | private function f_TC_createSession_ping4() runs on PGW_Session_CT { |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 992 | f_s5s8_create_session(); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 993 | f_ping4(mp_ping_hostname); |
| 994 | setverdict(pass); |
| 995 | } |
| 996 | testcase TC_createSession_ping4() runs on PGW_Test_CT { |
| 997 | var PGW_Session_CT vc_conn; |
| 998 | var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23")); |
| 999 | f_init(); |
| 1000 | vc_conn := f_start_handler(refers(f_TC_createSession_ping4), pars); |
| 1001 | vc_conn.done; |
| 1002 | } |
Harald Welte | fe595e4 | 2020-04-21 22:56:47 +0200 | [diff] [blame] | 1003 | testcase TC_createSession_ping4_256() runs on PGW_Test_CT { |
| 1004 | var PGW_Session_CT vc_conn[256]; |
| 1005 | var integer i; |
| 1006 | |
| 1007 | f_init(); |
| 1008 | |
| 1009 | for (i := 0; i < sizeof(vc_conn); i:=i+1) { |
| 1010 | var charstring tundev := "ping" & int2str(i); |
| 1011 | var SessionPars pars := valueof(t_SessionPars(f_gen_imsi(i), tundev)); |
| 1012 | vc_conn[i] := f_start_handler(refers(f_TC_createSession_ping4), pars); |
| 1013 | } |
| 1014 | |
| 1015 | for (i := 0; i < lengthof(vc_conn); i:=i+1) { |
| 1016 | vc_conn[i].done; |
| 1017 | } |
| 1018 | } |
| 1019 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 1020 | |
| 1021 | /* create a session, then delete it again */ |
| 1022 | private function f_TC_createSession_deleteSession() runs on PGW_Session_CT { |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 1023 | f_s5s8_create_session(); |
| 1024 | f_delete_session(omit, g_pars.teic_local, Request_accepted); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 1025 | setverdict(pass); |
| 1026 | } |
| 1027 | testcase TC_createSession_deleteSession() runs on PGW_Test_CT { |
| 1028 | var PGW_Session_CT vc_conn; |
| 1029 | var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23")); |
| 1030 | f_init(); |
| 1031 | vc_conn := f_start_handler(refers(f_TC_createSession_deleteSession), pars); |
| 1032 | vc_conn.done; |
| 1033 | } |
| 1034 | |
| 1035 | /* send a DeleteSessionReq for an unknown/invalid TEID */ |
| 1036 | private function f_TC_deleteSession_unknown() runs on PGW_Session_CT { |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 1037 | g_pars.teic_remote := f_rnd_octstring(4); |
Pau Espin Pedrol | 1344e47 | 2023-10-23 19:54:29 +0200 | [diff] [blame] | 1038 | f_delete_session(omit, '00000000'O, Context_Not_Found, false); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 1039 | setverdict(pass); |
| 1040 | } |
| 1041 | testcase TC_deleteSession_unknown() runs on PGW_Test_CT { |
| 1042 | var PGW_Session_CT vc_conn; |
| 1043 | var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23")); |
| 1044 | f_init(); |
| 1045 | vc_conn := f_start_handler(refers(f_TC_deleteSession_unknown), pars); |
| 1046 | vc_conn.done; |
| 1047 | } |
| 1048 | |
Pau Espin Pedrol | 431f346 | 2022-04-20 18:45:35 +0200 | [diff] [blame] | 1049 | /* Test charging over Gy interface. */ |
| 1050 | private function f_TC_gy_charging_cc_time() runs on PGW_Session_CT { |
| 1051 | var default d; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 1052 | |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 1053 | f_s5s8_create_session(); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 1054 | |
Pau Espin Pedrol | 431f346 | 2022-04-20 18:45:35 +0200 | [diff] [blame] | 1055 | /* We should receive an update even if no traffic is sent: */ |
| 1056 | as_DIA_Gy_CCR(UPDATE_REQUEST); |
Pau Espin Pedrol | 2fde1ef | 2022-05-20 18:53:09 +0200 | [diff] [blame] | 1057 | f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (3..4), 0, 0); |
Pau Espin Pedrol | 431f346 | 2022-04-20 18:45:35 +0200 | [diff] [blame] | 1058 | |
| 1059 | d := activate(as_DIA_Gy_CCR(UPDATE_REQUEST)); |
| 1060 | f_ping4(mp_ping_hostname); |
Pau Espin Pedrol | 819a3b8 | 2024-03-18 20:35:46 +0100 | [diff] [blame] | 1061 | /* Let the CCA reach the PGW */ |
Pau Espin Pedrol | 431f346 | 2022-04-20 18:45:35 +0200 | [diff] [blame] | 1062 | f_sleep(0.5); |
| 1063 | deactivate(d); |
Pau Espin Pedrol | 2fde1ef | 2022-05-20 18:53:09 +0200 | [diff] [blame] | 1064 | f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (3..4), (28..1000), (28..1000)); |
| 1065 | |
| 1066 | as_DIA_Gy_CCR(UPDATE_REQUEST); |
| 1067 | f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (3..4), ?, ?); |
Pau Espin Pedrol | 431f346 | 2022-04-20 18:45:35 +0200 | [diff] [blame] | 1068 | |
Pau Espin Pedrol | 355a133 | 2024-02-23 17:44:14 +0100 | [diff] [blame] | 1069 | f_delete_session(omit, g_pars.teic_local, Request_accepted); |
Pau Espin Pedrol | 2fde1ef | 2022-05-20 18:53:09 +0200 | [diff] [blame] | 1070 | f_validate_gy_cc_report(g_rx_gy, FINAL, (0..1), 0, 0); |
Pau Espin Pedrol | 431f346 | 2022-04-20 18:45:35 +0200 | [diff] [blame] | 1071 | setverdict(pass); |
| 1072 | } |
| 1073 | testcase TC_gy_charging_cc_time() runs on PGW_Test_CT { |
| 1074 | var PGW_Session_CT vc_conn; |
| 1075 | var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23")); |
Pau Espin Pedrol | 06fba9c | 2024-03-18 20:12:12 +0100 | [diff] [blame] | 1076 | pars.gy.validity_time := 3; /* Grant access for 3 seconds, needs to be re-validated afterwards */ |
Pau Espin Pedrol | 431f346 | 2022-04-20 18:45:35 +0200 | [diff] [blame] | 1077 | f_init(); |
| 1078 | vc_conn := f_start_handler(refers(f_TC_gy_charging_cc_time), pars); |
| 1079 | vc_conn.done; |
| 1080 | } |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 1081 | |
Pau Espin Pedrol | 0a228ea | 2024-03-18 20:53:47 +0100 | [diff] [blame] | 1082 | /* Test Gy CCR rejected with CCA Result-Code DIAMETER_AUTHORIZATION_REJECTED (5003) */ |
| 1083 | private function f_TC_gy_ccr_update_rejected() runs on PGW_Session_CT { |
| 1084 | var default d; |
| 1085 | |
| 1086 | f_s5s8_create_session(); |
| 1087 | |
| 1088 | /* We should receive an update even if no traffic is sent: */ |
| 1089 | as_DIA_Gy_CCR(UPDATE_REQUEST); |
| 1090 | |
| 1091 | /* Answer next CCR[Update] with CCA Reject: */ |
| 1092 | g_pars.gy.cca_res_code := DIAMETER_AUTHORIZATION_REJECTED; |
| 1093 | as_DIA_Gy_CCR(UPDATE_REQUEST); |
| 1094 | |
| 1095 | /* Expect PGW to tear down the connection as a result: */ |
| 1096 | as_DIA_Gx_CCR(TERMINATION_REQUEST); |
| 1097 | as_DIA_Gy_CCR(TERMINATION_REQUEST); |
| 1098 | |
| 1099 | setverdict(pass); |
| 1100 | } |
| 1101 | testcase TC_gy_ccr_update_rejected() runs on PGW_Test_CT { |
| 1102 | var PGW_Session_CT vc_conn; |
| 1103 | var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23")); |
| 1104 | pars.gy.validity_time := 3; /* Grant access for 3 seconds, needs to be re-validated afterwards */ |
| 1105 | f_init(); |
| 1106 | vc_conn := f_start_handler(refers(f_TC_gy_ccr_update_rejected), pars); |
| 1107 | vc_conn.done; |
| 1108 | } |
| 1109 | |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 1110 | /* create a session, expect it to succeed */ |
| 1111 | private function f_TC_s2b_createSession_v4_noapco() runs on PGW_Session_CT { |
Pau Espin Pedrol | 4ecc808 | 2024-02-26 15:28:12 +0100 | [diff] [blame] | 1112 | var template (omit) APCO apco := omit; |
| 1113 | var template APCO exp_apco := omit; |
| 1114 | f_s2b_create_session(apco, exp_apco); |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 1115 | setverdict(pass); |
| 1116 | } |
| 1117 | testcase TC_s2b_createSession_v4_noapco() runs on PGW_Test_CT { |
| 1118 | var PGW_Session_CT vc_conn; |
| 1119 | var SessionPars pars := valueof(t_SessionPars('001010123456789'H, |
| 1120 | "tun22", |
| 1121 | rat_type := GTP2C_RAT_WLAN)); |
| 1122 | f_init(); |
| 1123 | vc_conn := f_start_handler(refers(f_TC_s2b_createSession_v4_noapco), pars); |
| 1124 | vc_conn.done; |
| 1125 | } |
| 1126 | |
Pau Espin Pedrol | 4ecc808 | 2024-02-26 15:28:12 +0100 | [diff] [blame] | 1127 | private function f_TC_s2b_createSession_v4_apco() runs on PGW_Session_CT { |
| 1128 | var template (omit) APCO apco := ts_GTP2C_APCO('0000'B, |
| 1129 | {ts_GTP2C_PCO_P_DNS_IPv4(''O), |
| 1130 | ts_GTP2C_PCO_P_PCSCF_IPv4(''O)}); |
| 1131 | var template APCO exp_apco := tr_GTP2C_APCO('0000'B, |
| 1132 | {tr_GTP2C_PCO_P_DNS_IPv4(?), |
| 1133 | *, /* open5gs-smfd can contain several DNS servers */ |
| 1134 | tr_GTP2C_PCO_P_PCSCF_IPv4(?)}); |
| 1135 | f_s2b_create_session(apco, exp_apco); |
| 1136 | setverdict(pass); |
| 1137 | } |
| 1138 | testcase TC_s2b_createSession_v4_apco() runs on PGW_Test_CT { |
| 1139 | var PGW_Session_CT vc_conn; |
| 1140 | var SessionPars pars := valueof(t_SessionPars('001010123456789'H, |
| 1141 | "tun22", |
| 1142 | rat_type := GTP2C_RAT_WLAN)); |
| 1143 | f_init(); |
| 1144 | vc_conn := f_start_handler(refers(f_TC_s2b_createSession_v4_apco), pars); |
| 1145 | vc_conn.done; |
| 1146 | } |
| 1147 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 1148 | control { |
| 1149 | execute( TC_tx_echo() ); |
| 1150 | execute( TC_createSession() ); |
| 1151 | execute( TC_createSession_ping4() ); |
Harald Welte | fe595e4 | 2020-04-21 22:56:47 +0200 | [diff] [blame] | 1152 | execute( TC_createSession_ping4_256() ); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 1153 | execute( TC_createSession_deleteSession() ); |
| 1154 | execute( TC_deleteSession_unknown() ); |
Pau Espin Pedrol | 431f346 | 2022-04-20 18:45:35 +0200 | [diff] [blame] | 1155 | execute( TC_gy_charging_cc_time() ); |
Pau Espin Pedrol | 0a228ea | 2024-03-18 20:53:47 +0100 | [diff] [blame] | 1156 | execute( TC_gy_ccr_update_rejected() ); |
Pau Espin Pedrol | 518e24b | 2024-02-23 17:45:08 +0100 | [diff] [blame] | 1157 | execute( TC_s2b_createSession_v4_noapco() ); |
Pau Espin Pedrol | 4ecc808 | 2024-02-26 15:28:12 +0100 | [diff] [blame] | 1158 | execute( TC_s2b_createSession_v4_apco() ); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | |
| 1162 | } |