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