Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 1 | module EPDG_Tests { |
| 2 | |
| 3 | import from Misc_Helpers all; |
| 4 | import from General_Types all; |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 5 | import from Native_Functions all; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 6 | import from Osmocom_Types all; |
| 7 | import from L3_Common all; |
Pau Espin Pedrol | c2cfd55 | 2024-02-07 17:51:55 +0100 | [diff] [blame] | 8 | import from DNS_Helpers all; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 9 | |
| 10 | import from IPA_Emulation all; |
Pau Espin Pedrol | ce1d3cb | 2024-02-21 17:40:59 +0100 | [diff] [blame] | 11 | import from PCO_Types all; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 12 | import from GSUP_Types all; |
Pau Espin Pedrol | 8f1403a | 2024-01-18 20:08:43 +0100 | [diff] [blame] | 13 | import from GSUP_Templates all; |
| 14 | import from GSUP_Emulation all; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 15 | |
| 16 | import from DIAMETER_Types all; |
| 17 | import from DIAMETER_Templates all; |
Pau Espin Pedrol | 4669b61 | 2023-10-23 17:43:14 +0200 | [diff] [blame] | 18 | import from DIAMETER_ts29_273_Templates all; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 19 | import from DIAMETER_Emulation all; |
| 20 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 21 | import from GTPv2_Types all; |
| 22 | import from GTPv2_Templates all; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 23 | import from GTPv2_Emulation all; |
| 24 | |
| 25 | modulepar { |
| 26 | /* our emulated GSUP strongswan (CEAI iface) */ |
| 27 | charstring mp_gsup_local_ip := "127.0.0.100"; |
| 28 | integer mp_gsup_local_port := 0; |
| 29 | charstring mp_gsup_remote_ip := "127.0.0.1"; |
| 30 | integer mp_gsup_remote_port := 4222; |
| 31 | |
| 32 | /* our emulated HSS */ |
| 33 | charstring mp_swx_local_ip := "127.0.0.100"; |
| 34 | integer mp_swx_local_port := 3868; |
| 35 | |
| 36 | /* our emulated PGW (Diameter S6b) */ |
| 37 | charstring mp_s6b_local_ip := "127.0.0.100"; |
| 38 | integer mp_s6b_local_port := 3869; |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 39 | charstring mp_s6b_remote_ip := "127.0.0.1"; |
| 40 | integer mp_s6b_remote_port := 3869; |
Pau Espin Pedrol | 8586b26 | 2024-02-09 18:12:21 +0100 | [diff] [blame] | 41 | /* 3GPP TS 23.003 clause 19: "nai.epc.mnc<MNC>.mcc<MCC>.3gppnetwork.org" */ |
| 42 | charstring mp_s6b_nai_realm := "nai.epc.mnc001.mcc01.3gppnetwork.org"; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 43 | |
| 44 | /* our emulated PGW (GTPv2C S2b) */ |
| 45 | charstring mp_s2b_local_ip := "127.0.0.100"; |
| 46 | integer mp_s2b_local_port := GTP2C_PORT; |
| 47 | charstring mp_s2b_remote_ip := "127.0.0.1"; |
| 48 | integer mp_s2b_remote_port := GTP2C_PORT; |
Pau Espin Pedrol | f292586 | 2024-02-22 20:12:30 +0100 | [diff] [blame] | 49 | charstring mp_s2b_dns_ipv4 := "1.2.3.4"; |
| 50 | charstring mp_s2b_dns_ipv6 := "::1"; |
| 51 | charstring mp_s2b_pcscf_ipv4 := "5.6.7.8"; |
| 52 | charstring mp_s2b_pcscf_ipv6 := "::2"; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 53 | |
| 54 | charstring mp_diam_realm := "localdomain"; |
Pau Espin Pedrol | c13a4cd | 2024-01-16 17:28:25 +0100 | [diff] [blame] | 55 | integer mp_diam_watchdog_initial_wait_sec := 6*3; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 56 | } |
| 57 | |
Pau Espin Pedrol | 285a2b6 | 2024-02-27 18:25:45 +0100 | [diff] [blame] | 58 | type port Coord_PT message |
| 59 | { |
| 60 | inout charstring; |
| 61 | } with { extension "internal" }; |
| 62 | private const charstring COORD_CMD_READY := "COORD_CMD_READY"; |
| 63 | private const charstring COORD_CMD_START := "COORD_CMD_START"; |
| 64 | private const charstring COORD_CMD_ATTACHED := "COORD_CMD_ATTACHED"; |
| 65 | private const charstring COORD_CMD_STOP := "COORD_CMD_STOP"; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 66 | |
| 67 | type component MTC_CT { |
| 68 | var DIAMETER_Emulation_CT vc_SWx; |
| 69 | port DIAMETER_PT SWx_UNIT; |
| 70 | port DIAMETEREM_PROC_PT SWx_PROC; |
| 71 | |
| 72 | var DIAMETER_Emulation_CT vc_S6b; |
| 73 | port DIAMETER_PT S6b_UNIT; |
| 74 | port DIAMETEREM_PROC_PT S6b_PROC; |
| 75 | |
| 76 | var GSUP_Emulation_CT vc_GSUP; |
| 77 | var IPA_Emulation_CT vc_GSUP_IPA; |
| 78 | port IPA_CTRL_PT GSUP_IPA_EVENT; |
| 79 | |
| 80 | var GTPv2_Emulation_CT vc_GTP2; |
| 81 | port GTP2EM_PT TEID0; |
| 82 | |
Pau Espin Pedrol | 285a2b6 | 2024-02-27 18:25:45 +0100 | [diff] [blame] | 83 | port Coord_PT COORD; |
| 84 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 85 | timer g_Tguard; |
| 86 | }; |
| 87 | |
| 88 | private altstep as_Tguard() runs on MTC_CT { |
| 89 | [] g_Tguard.timeout { |
| 90 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout"); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | type component DIAMETER_ConnHdlr_CT extends DIAMETER_ConnHdlr { |
| 95 | port DIAMETER_Conn_PT DIAMETER_CLIENT; |
| 96 | port DIAMETEREM_PROC_PT DIAMETER_PROC_CLIENT; |
| 97 | } |
| 98 | |
| 99 | function f_diam_connhldr_ct_main(hexstring imsi) runs on DIAMETER_ConnHdlr_CT { |
| 100 | var DIAMETER_ConnHdlr vc_conn_unused; |
| 101 | var PDU_DIAMETER msg; |
| 102 | var UINT32 ete_id; |
| 103 | |
| 104 | f_diameter_expect_imsi(imsi); |
| 105 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 106 | while (true) { |
| 107 | alt { |
| 108 | [] DIAMETER_CLIENT.receive(PDU_DIAMETER:?) -> value msg { |
| 109 | DIAMETER.send(msg); |
| 110 | } |
| 111 | [] DIAMETER.receive(PDU_DIAMETER:?) -> value msg { |
| 112 | DIAMETER_CLIENT.send(msg); |
| 113 | } |
| 114 | [] DIAMETER_PROC_CLIENT.getcall(DIAMETEREM_register_eteid:{?,?}) -> param(ete_id, vc_conn_unused) { |
| 115 | DIAMETER_PROC.call(DIAMETEREM_register_eteid:{ete_id, self}) { |
| 116 | [] DIAMETER_PROC.getreply(DIAMETEREM_register_eteid:{?,?}) {}; |
| 117 | } |
| 118 | DIAMETER_PROC_CLIENT.reply(DIAMETEREM_register_eteid:{ete_id, vc_conn_unused}); |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | type component EPDG_ConnHdlr extends DIAMETER_ConnHdlr, GSUP_ConnHdlr, GTP2_ConnHdlr { |
| 125 | var EPDG_ConnHdlrPars g_pars; |
| 126 | |
| 127 | port DIAMETER_Conn_PT SWx; |
| 128 | port DIAMETEREM_PROC_PT SWx_PROC; |
| 129 | port DIAMETER_Conn_PT S6b; |
| 130 | port DIAMETEREM_PROC_PT S6b_PROC; |
Pau Espin Pedrol | 285a2b6 | 2024-02-27 18:25:45 +0100 | [diff] [blame] | 131 | port Coord_PT COORD; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 132 | }; |
Pau Espin Pedrol | 285a2b6 | 2024-02-27 18:25:45 +0100 | [diff] [blame] | 133 | type record of EPDG_ConnHdlr EPDG_ConnHdlrList; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 134 | |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 135 | type record BearerConfig { |
| 136 | /* EPS Bearer ID */ |
| 137 | uint4_t ebi optional, |
| 138 | /* TEI (Data) local side */ |
| 139 | OCT4 teid_local optional, |
| 140 | /* TEI (Data) remote side */ |
| 141 | OCT4 teid_remote optional |
| 142 | }; |
| 143 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 144 | type record EPDG_ConnHdlrPars { |
| 145 | hexstring imsi, |
Pau Espin Pedrol | 2c2e187 | 2023-10-23 18:31:03 +0200 | [diff] [blame] | 146 | charstring apn, |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 147 | charstring ue_ip, |
| 148 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 149 | /* TEI (Control) local side */ |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 150 | OCT4 teic_local, |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 151 | /* TEI (Control) remote side */ |
| 152 | OCT4 teic_remote optional, |
| 153 | |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 154 | BearerConfig bearer optional, |
| 155 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 156 | AuthVector vec optional |
| 157 | }; |
| 158 | |
| 159 | private function f_epdg_connhldr_SWx_expect_eteid(UINT32 ete_id) runs on EPDG_ConnHdlr { |
| 160 | SWx_PROC.call(DIAMETEREM_register_eteid:{ete_id, null}) { |
| 161 | [] SWx_PROC.getreply(DIAMETEREM_register_eteid:{?,?}) {}; |
| 162 | } |
| 163 | } |
| 164 | private function f_epdg_connhldr_S6b_expect_eteid(UINT32 ete_id) runs on EPDG_ConnHdlr { |
| 165 | S6b_PROC.call(DIAMETEREM_register_eteid:{ete_id, null}) { |
| 166 | [] S6b_PROC.getreply(DIAMETEREM_register_eteid:{?,?}) {}; |
| 167 | } |
| 168 | } |
| 169 | |
Pau Espin Pedrol | 285a2b6 | 2024-02-27 18:25:45 +0100 | [diff] [blame] | 170 | private function f_gen_addr_in_pool(integer idx := 0) return charstring |
| 171 | { |
| 172 | /* Skip first 2 addresses reserved for TUN */ |
| 173 | var integer internal_idx := idx + 2; |
| 174 | var integer suffix := internal_idx rem (256*256); |
| 175 | var integer C := suffix / 256; |
| 176 | var integer D := suffix rem 256; |
| 177 | return "192.168." & int2str(C) & "." & int2str(D); |
| 178 | } |
| 179 | |
| 180 | private function f_init_pars(integer idx := 0) |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 181 | runs on MTC_CT return EPDG_ConnHdlrPars { |
| 182 | var EPDG_ConnHdlrPars pars := { |
Pau Espin Pedrol | 285a2b6 | 2024-02-27 18:25:45 +0100 | [diff] [blame] | 183 | imsi := f_rnd_imsi('26242'H), |
Pau Espin Pedrol | 2c2e187 | 2023-10-23 18:31:03 +0200 | [diff] [blame] | 184 | apn := "internet", |
Pau Espin Pedrol | 285a2b6 | 2024-02-27 18:25:45 +0100 | [diff] [blame] | 185 | ue_ip := f_gen_addr_in_pool(idx), |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 186 | teic_local := '00000000'O, |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 187 | teic_remote := omit, |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 188 | bearer := { |
| 189 | ebi := omit, |
| 190 | teid_local := omit, |
| 191 | teid_remote := omit |
| 192 | }, |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 193 | vec := f_gen_auth_vec_3g() |
| 194 | }; |
| 195 | return pars; |
| 196 | } |
| 197 | |
| 198 | private function f_init_gsup(charstring id) runs on MTC_CT { |
| 199 | id := id & "-GSUP"; |
| 200 | var GsupOps ops := { |
| 201 | create_cb := refers(GSUP_Emulation.ExpectedCreateCallback) |
| 202 | }; |
| 203 | |
| 204 | vc_GSUP_IPA := IPA_Emulation_CT.create(id & "-IPA"); |
| 205 | vc_GSUP := GSUP_Emulation_CT.create(id); |
| 206 | |
| 207 | map(vc_GSUP_IPA:IPA_PORT, system:IPA_CODEC_PT); |
| 208 | connect(vc_GSUP:GSUP, vc_GSUP_IPA:IPA_GSUP_PORT); |
| 209 | /* we use this hack to get events like ASP_IPA_EVENT_UP */ |
| 210 | connect(vc_GSUP_IPA:IPA_CTRL_PORT, self:GSUP_IPA_EVENT); |
| 211 | |
| 212 | vc_GSUP.start(GSUP_Emulation.main(ops, id)); |
| 213 | vc_GSUP_IPA.start(IPA_Emulation.main_client(mp_gsup_remote_ip, mp_gsup_remote_port, |
| 214 | mp_gsup_local_ip, mp_gsup_local_port)); |
| 215 | |
| 216 | /* wait for incoming connection to GSUP port before proceeding */ |
| 217 | timer T := 10.0; |
| 218 | T.start; |
| 219 | alt { |
| 220 | [] GSUP_IPA_EVENT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_UP)) { } |
| 221 | [] T.timeout { |
| 222 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No connection to GSUP Port"); |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | private function DiameterForwardUnitdataCallback(PDU_DIAMETER msg) |
| 228 | runs on DIAMETER_Emulation_CT return template PDU_DIAMETER { |
| 229 | DIAMETER_UNIT.send(msg); |
| 230 | return omit; |
| 231 | } |
| 232 | |
| 233 | private function f_init_diameter(charstring id) runs on MTC_CT { |
| 234 | var DIAMETEROps ops := { |
| 235 | create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback), |
| 236 | unitdata_cb := refers(DiameterForwardUnitdataCallback), |
| 237 | raw := false /* handler mode (IMSI based routing) */ |
| 238 | }; |
| 239 | var DIAMETER_conn_parameters pars; |
| 240 | |
| 241 | /* SWx setup: */ |
| 242 | pars := { |
| 243 | remote_ip := "", |
| 244 | remote_sctp_port := -1, /* server mode */ |
| 245 | local_ip := mp_swx_local_ip, |
| 246 | local_sctp_port := mp_swx_local_port, |
| 247 | origin_host := "hss." & mp_diam_realm, |
| 248 | origin_realm := mp_diam_realm, |
| 249 | auth_app_id := omit, |
| 250 | vendor_app_id := c_DIAMETER_3GPP_SWx_AID |
| 251 | }; |
| 252 | vc_SWx := DIAMETER_Emulation_CT.create(id); |
| 253 | map(vc_SWx:DIAMETER, system:DIAMETER_CODEC_PT); |
| 254 | connect(vc_SWx:DIAMETER_UNIT, self:SWx_UNIT); |
| 255 | connect(vc_SWx:DIAMETER_PROC, self:SWx_PROC); |
| 256 | vc_SWx.start(DIAMETER_Emulation.main(ops, pars, id)); |
| 257 | |
| 258 | /* S6b setup: */ |
| 259 | pars := { |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 260 | remote_ip := mp_s6b_remote_ip, |
| 261 | remote_sctp_port := mp_s6b_remote_port, /* client mode */ |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 262 | local_ip := mp_s6b_local_ip, |
| 263 | local_sctp_port := mp_s6b_local_port, |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 264 | origin_host := "pgw." & mp_diam_realm, |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 265 | origin_realm := mp_diam_realm, |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 266 | auth_app_id := c_DIAMETER_3GPP_S6b_AID, |
| 267 | vendor_app_id := c_DIAMETER_3GPP_S6b_AID |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 268 | }; |
| 269 | vc_S6b := DIAMETER_Emulation_CT.create(id); |
| 270 | map(vc_S6b:DIAMETER, system:DIAMETER_CODEC_PT); |
| 271 | connect(vc_S6b:DIAMETER_UNIT, self:S6b_UNIT); |
| 272 | connect(vc_S6b:DIAMETER_PROC, self:S6b_PROC); |
| 273 | vc_S6b.start(DIAMETER_Emulation.main(ops, pars, id)); |
| 274 | |
| 275 | f_diameter_wait_capability(SWx_UNIT); |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 276 | f_diameter_wait_capability(S6b_UNIT); |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 277 | |
| 278 | /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdog ping-pongs): |
| 279 | * RFC6733 sec 5.1 |
| 280 | * RFC3539 sec 3.4.1 [5] |
| 281 | * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49 |
| 282 | */ |
Pau Espin Pedrol | c13a4cd | 2024-01-16 17:28:25 +0100 | [diff] [blame] | 283 | f_sleep(int2float(mp_diam_watchdog_initial_wait_sec)); |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | private function f_init_gtp(charstring id) runs on MTC_CT { |
| 287 | var Gtp2EmulationCfg cfg := { |
| 288 | gtpc_bind_ip := mp_s2b_local_ip, |
| 289 | gtpc_bind_port := mp_s2b_local_port, |
| 290 | gtpc_remote_ip := mp_s2b_remote_ip, |
| 291 | gtpc_remote_port := mp_s2b_remote_port, |
| 292 | sgw_role := false, |
| 293 | use_gtpu_daemon := false /* TODO: maybe use, set to true */ |
| 294 | }; |
| 295 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 296 | vc_GTP2 := GTPv2_Emulation_CT.create(id & "-GTPV2"); |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 297 | map(vc_GTP2:GTP2C, system:GTP2C); |
| 298 | connect(vc_GTP2:TEID0, self:TEID0); |
| 299 | vc_GTP2.start(GTPv2_Emulation.main(cfg)); |
| 300 | } |
| 301 | |
| 302 | private function f_init(float t_guard := 40.0) runs on MTC_CT { |
| 303 | |
| 304 | g_Tguard.start(t_guard); |
| 305 | activate(as_Tguard()); |
| 306 | |
| 307 | f_init_gsup(testcasename()); |
| 308 | f_init_diameter(testcasename()); |
| 309 | f_init_gtp(testcasename()); |
| 310 | } |
| 311 | |
| 312 | private type function void_fn(charstring id) runs on EPDG_ConnHdlr; |
| 313 | |
| 314 | private function f_init_handler(void_fn fn, charstring id, EPDG_ConnHdlrPars pars) runs on EPDG_ConnHdlr { |
| 315 | g_pars := pars; |
| 316 | |
| 317 | /* tell GSUP dispatcher to send this IMSI to us */ |
| 318 | f_create_gsup_expect(hex2str(g_pars.imsi)); |
| 319 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 320 | /* tell GTPv2 dispatcher to send this IMSI to us */ |
| 321 | f_gtp2_register_imsi(g_pars.imsi); |
| 322 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 323 | fn.apply(id); |
| 324 | } |
| 325 | |
| 326 | private function f_start_handler(void_fn fn, EPDG_ConnHdlrPars pars) |
| 327 | runs on MTC_CT return EPDG_ConnHdlr { |
| 328 | var EPDG_ConnHdlr vc_conn; |
| 329 | var charstring id := testcasename(); |
| 330 | var DIAMETER_ConnHdlr_CT vc_conn_swx, vc_conn_s6b; |
| 331 | |
| 332 | vc_conn := EPDG_ConnHdlr.create(id); |
| 333 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 334 | /* GSUP */ |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 335 | connect(vc_conn:GSUP, vc_GSUP:GSUP_CLIENT); |
| 336 | connect(vc_conn:GSUP_PROC, vc_GSUP:GSUP_PROC); |
| 337 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 338 | /* GTP2 */ |
| 339 | connect(vc_conn:GTP2, vc_GTP2:CLIENT); |
| 340 | connect(vc_conn:GTP2_PROC, vc_GTP2:CLIENT_PROC); |
| 341 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 342 | /* SWx */ |
| 343 | vc_conn_swx := DIAMETER_ConnHdlr_CT.create(id); |
| 344 | connect(vc_conn_swx:DIAMETER, vc_SWx:DIAMETER_CLIENT); |
| 345 | connect(vc_conn_swx:DIAMETER_PROC, vc_SWx:DIAMETER_PROC); |
| 346 | connect(vc_conn:SWx, vc_conn_swx:DIAMETER_CLIENT); |
| 347 | connect(vc_conn:SWx_PROC, vc_conn_swx:DIAMETER_PROC_CLIENT); |
| 348 | vc_conn_swx.start(f_diam_connhldr_ct_main(pars.imsi)); |
| 349 | |
| 350 | /* S6b */ |
| 351 | vc_conn_s6b := DIAMETER_ConnHdlr_CT.create(id); |
| 352 | connect(vc_conn_s6b:DIAMETER, vc_S6b:DIAMETER_CLIENT); |
| 353 | connect(vc_conn_s6b:DIAMETER_PROC, vc_S6b:DIAMETER_PROC); |
| 354 | connect(vc_conn:S6b, vc_conn_s6b:DIAMETER_CLIENT); |
| 355 | connect(vc_conn:S6b_PROC, vc_conn_s6b:DIAMETER_PROC_CLIENT); |
| 356 | vc_conn_s6b.start(f_diam_connhldr_ct_main(pars.imsi)); |
| 357 | |
Pau Espin Pedrol | 285a2b6 | 2024-02-27 18:25:45 +0100 | [diff] [blame] | 358 | /* COORD */ |
| 359 | connect(vc_conn:COORD, self:COORD); |
| 360 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 361 | vc_conn.start(f_init_handler(fn, id, pars)); |
| 362 | return vc_conn; |
| 363 | } |
| 364 | |
Pau Espin Pedrol | 8586b26 | 2024-02-09 18:12:21 +0100 | [diff] [blame] | 365 | private function f_nai() runs on EPDG_ConnHdlr return charstring { |
| 366 | return hex2str(g_pars.imsi) & "@" & mp_s6b_nai_realm; |
| 367 | } |
| 368 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 369 | /* Diameter SWx MAR + MAA. */ |
| 370 | private altstep as_DIA_SWx_MA_success() runs on EPDG_ConnHdlr { |
| 371 | var PDU_DIAMETER rx_dia; |
| 372 | var template (omit) AVP avp; |
| 373 | var octetstring sess_id; |
| 374 | var template (value) GenericAVP sip_auth_data_item; |
| 375 | [] SWx.receive(tr_DIA_SWx_MAR(g_pars.imsi)) -> value rx_dia { |
| 376 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id); |
| 377 | sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id); |
| 378 | sip_auth_data_item := ts_AVP_3GPP_SIPAuthDataItem(0, |
| 379 | g_pars.vec.rand, |
| 380 | g_pars.vec.ik, |
| 381 | g_pars.vec.ck, |
| 382 | g_pars.vec.autn, |
| 383 | g_pars.vec.auts); |
| 384 | /* Send MAA to translator; expect it to show up on GSUP side */ |
| 385 | SWx.send(ts_DIA_SWx_MAA(g_pars.imsi, sip_auth_data_item, |
| 386 | sess_id := sess_id, |
| 387 | hbh_id := rx_dia.hop_by_hop_id, |
| 388 | ete_id := rx_dia.end_to_end_id)); |
| 389 | setverdict(pass); |
| 390 | } |
| 391 | [] SWx.receive(PDU_DIAMETER:?) -> value rx_dia { |
| 392 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected Diameter msg rx: ", rx_dia)); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /* Diameter SWx SAR + SAA. */ |
Pau Espin Pedrol | 4944a5c | 2024-01-24 17:23:01 +0100 | [diff] [blame] | 397 | private altstep as_DIA_SWx_SA_success(template (present) CxDx_3GPP_Server_Assignment_Type server_ass_type := ?) runs on EPDG_ConnHdlr { |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 398 | var PDU_DIAMETER rx_dia; |
| 399 | var template (omit) AVP avp; |
| 400 | var octetstring sess_id; |
| 401 | [] SWx.receive(tr_DIA_SWx_SAR(g_pars.imsi)) -> value rx_dia { |
| 402 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id); |
| 403 | sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id); |
| 404 | /* Send SAA to translator; expect it to show up on GSUP side */ |
| 405 | SWx.send(ts_DIA_SWx_SAA(g_pars.imsi, |
| 406 | sess_id := sess_id, |
| 407 | hbh_id := rx_dia.hop_by_hop_id, |
| 408 | ete_id := rx_dia.end_to_end_id)); |
| 409 | setverdict(pass); |
| 410 | } |
| 411 | [] SWx.receive(PDU_DIAMETER:?) -> value rx_dia { |
| 412 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected Diameter msg rx: ", rx_dia)); |
| 413 | } |
| 414 | } |
| 415 | |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 416 | /* Send AAR as PGW to AAA server, expect back AAA */ |
| 417 | private function f_S6b_AA_success() runs on EPDG_ConnHdlr { |
| 418 | var PDU_DIAMETER rx_dia; |
| 419 | var UINT32 hbh_id := f_rnd_octstring(4); |
| 420 | var UINT32 ete_id := f_rnd_octstring(4); |
| 421 | |
| 422 | /* Unlike AAR, AAA contains no IMSI. Register ete_id in DIAMETER_Emulation, |
| 423 | * so AIA is forwarded back to us in DIAMETER port instead of MTC_CT.DIAMETER_UNIT. |
| 424 | */ |
| 425 | f_epdg_connhldr_S6b_expect_eteid(ete_id); |
| 426 | |
Pau Espin Pedrol | 8586b26 | 2024-02-09 18:12:21 +0100 | [diff] [blame] | 427 | S6b.send(ts_DIA_S6b_AAR(f_nai(), |
Pau Espin Pedrol | 2c2e187 | 2023-10-23 18:31:03 +0200 | [diff] [blame] | 428 | int2oct(DIA_TS29_373_MIP6_Feature_Vector_GTPv2_SUPPORTED, 8), |
| 429 | g_pars.apn, hbh_id := hbh_id, ete_id := ete_id)); |
Pau Espin Pedrol | c119ba0 | 2024-01-29 11:55:39 +0100 | [diff] [blame] | 430 | |
| 431 | /* AAR in S6b in AAA-Server triggers Service-Assignment Request/Answer towards HSS: */ |
| 432 | as_DIA_SWx_SA_success(); |
| 433 | |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 434 | alt { |
| 435 | [] S6b.receive(tr_DIA_S6b_AAA) -> value rx_dia {} |
| 436 | [] S6b.receive(PDU_DIAMETER:?) -> value rx_dia { |
| 437 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected Diameter S6b msg rx: ", rx_dia)); |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | |
Pau Espin Pedrol | 4944a5c | 2024-01-24 17:23:01 +0100 | [diff] [blame] | 442 | /* Send STR as PGW to AAA server, expect back STA */ |
| 443 | private function f_S6b_ST_success() runs on EPDG_ConnHdlr { |
| 444 | var PDU_DIAMETER rx_dia; |
| 445 | var UINT32 hbh_id := f_rnd_octstring(4); |
| 446 | var UINT32 ete_id := f_rnd_octstring(4); |
| 447 | |
| 448 | /* Unlike STR, STA contains no IMSI. Register ete_id in DIAMETER_Emulation, |
| 449 | * so AIA is forwarded back to us in DIAMETER port instead of MTC_CT.DIAMETER_UNIT. |
| 450 | */ |
| 451 | f_epdg_connhldr_S6b_expect_eteid(ete_id); |
| 452 | |
| 453 | S6b.send(ts_DIA_S6b_STR(g_pars.imsi, DIAMETER_LOGOUT, |
| 454 | hbh_id := hbh_id, ete_id := ete_id)); |
| 455 | alt { |
| 456 | [] S6b.receive(tr_DIA_S6b_STA(DIAMETER_SUCCESS)) -> value rx_dia {} |
| 457 | [] S6b.receive(PDU_DIAMETER:?) -> value rx_dia { |
| 458 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected Diameter S6b msg rx: ", rx_dia)); |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | |
Pau Espin Pedrol | f292586 | 2024-02-22 20:12:30 +0100 | [diff] [blame] | 463 | private function f_exp_tr_GTP2C_APCO_in_CreateSessionReq() |
| 464 | runs on EPDG_ConnHdlr return template (present) APCO { |
| 465 | var template ProtocolIDs_and_ContainerIDs protos, protosV4, protosV6, protosV46; |
| 466 | protosV4 := {tr_GTP2C_PCO_P_DNS_IPv4(''O), tr_GTP2C_PCO_P_PCSCF_IPv4(''O)}; |
| 467 | protosV6 := {tr_GTP2C_PCO_P_DNS_IPv6(''O), tr_GTP2C_PCO_P_PCSCF_IPv6(''O)}; |
| 468 | protosV46 := {tr_GTP2C_PCO_P_DNS_IPv4(''O), tr_GTP2C_PCO_P_PCSCF_IPv4(''O), |
| 469 | tr_GTP2C_PCO_P_DNS_IPv6(''O), tr_GTP2C_PCO_P_PCSCF_IPv6(''O)} |
| 470 | /* TODO: pick proto based on req_type v4, v6 or v4v6 */ |
| 471 | protos := protosV4; |
| 472 | return tr_GTP2C_APCO('0000'B, protos); |
| 473 | } |
| 474 | |
| 475 | private function f_GTPv2C_gen_APCO_response(APCO apco_req) runs on EPDG_ConnHdlr return template (value) APCO { |
| 476 | var ProtocolIDs_and_ContainerIDs proto_list_resp := {}; |
| 477 | |
| 478 | for (var integer i := 0; i < lengthof(apco_req.protocolIDs_and_ContainerIDs); i := i + 1) { |
| 479 | var ProtocolID_or_ContainerID proto_req := apco_req.protocolIDs_and_ContainerIDs[i]; |
| 480 | select (proto_req.protocolID_or_ContainerID) { |
| 481 | case (PCO_P_to_OCT2(PCO_P_DNS_IPv4_ADDR)) { |
| 482 | proto_list_resp := proto_list_resp & { valueof(ts_GTP2C_PCO_P_DNS_IPv4(f_inet_addr(mp_s2b_dns_ipv4))) }; |
| 483 | } |
| 484 | case (PCO_P_to_OCT2(PCO_P_DNS_IPv6_ADDR)) { |
| 485 | proto_list_resp := proto_list_resp & { valueof(ts_GTP2C_PCO_P_DNS_IPv6(f_inet_addr(mp_s2b_dns_ipv6))) }; |
| 486 | } |
| 487 | case (PCO_P_to_OCT2(PCO_P_PCSCF_IPv4_ADDR)) { |
| 488 | proto_list_resp := proto_list_resp & { valueof(ts_GTP2C_PCO_P_PCSCF_IPv4(f_inet_addr(mp_s2b_pcscf_ipv4))) }; |
| 489 | } |
| 490 | case (PCO_P_to_OCT2(PCO_P_PCSCF_ADDR)) { |
| 491 | proto_list_resp := proto_list_resp & { valueof(ts_GTP2C_PCO_P_PCSCF_IPv6(f_inet_addr(mp_s2b_pcscf_ipv6))) }; |
| 492 | } |
| 493 | case else { |
| 494 | log("Ignoring unknown PCO Protocol ID: ", proto_req); |
| 495 | } |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | return ts_GTP2C_APCO(apco_req.instance, proto_list_resp); |
| 500 | } |
| 501 | |
Pau Espin Pedrol | 7b2cc92 | 2024-02-28 16:14:15 +0100 | [diff] [blame] | 502 | private function f_EPDG_ConnHdlr_parse_CreateSessionReq(PDU_GTPCv2 rx_msg) runs on EPDG_ConnHdlr { |
| 503 | var BearerContextIEs rx_bctx_ies; |
| 504 | |
| 505 | /* Parse TEIC and Bearer EBI and TEID and store it in g_pars */ |
| 506 | g_pars.teic_remote := rx_msg.gtpcv2_pdu.createSessionRequest.fullyQualifiedTEID[0].tEID_GRE_Key; |
| 507 | rx_bctx_ies := rx_msg.gtpcv2_pdu.createSessionRequest.bearerContextGrouped[0].bearerContextIEs; |
| 508 | g_pars.bearer.ebi := rx_bctx_ies.ePS_Bearer_ID.ePS_Bearer_ID_Value; |
| 509 | g_pars.bearer.teid_remote := rx_bctx_ies.fullyQualifiedTEID[0].tEID_GRE_Key; |
| 510 | |
| 511 | /* allocate + register TEID-C on local side */ |
| 512 | g_pars.teic_local := f_gtp2_allocate_teid(); |
| 513 | g_pars.bearer.teid_local := g_pars.teic_local; |
| 514 | } |
| 515 | |
Pau Espin Pedrol | 4944a5c | 2024-01-24 17:23:01 +0100 | [diff] [blame] | 516 | /* ePDG Creates session at the PGW. PGW sends Diameter s6b AAR + AAA. */ |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 517 | private altstep as_GTP2C_CreateSession_success() runs on EPDG_ConnHdlr { |
| 518 | var PDU_GTPCv2 rx_msg; |
| 519 | var template (value) FullyQualifiedTEID fteid_c_ie, fteid_u_ie; |
| 520 | var template (value) PDN_AddressAllocation paa; |
Pau Espin Pedrol | 8c74649 | 2023-10-23 20:56:09 +0200 | [diff] [blame] | 521 | var template (value) BearerContextIEs bctx_ies; |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 522 | |
Pau Espin Pedrol | f292586 | 2024-02-22 20:12:30 +0100 | [diff] [blame] | 523 | [] GTP2.receive(tr_GTP2C_CreateSessionReq(g_pars.imsi, apco := f_exp_tr_GTP2C_APCO_in_CreateSessionReq())) -> value rx_msg { |
Pau Espin Pedrol | 7b2cc92 | 2024-02-28 16:14:15 +0100 | [diff] [blame] | 524 | f_EPDG_ConnHdlr_parse_CreateSessionReq(rx_msg); |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 525 | |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 526 | /* Upon rx of CreateSession, emulate PGW asking the AAA server. */ |
| 527 | f_S6b_AA_success(); |
| 528 | |
Pau Espin Pedrol | 24b0859 | 2024-02-09 18:48:53 +0100 | [diff] [blame] | 529 | fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S2b_PGW_GTPC, g_pars.teic_local, 1, |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 530 | f_inet_addr(mp_s2b_local_ip), omit); |
Pau Espin Pedrol | 24b0859 | 2024-02-09 18:48:53 +0100 | [diff] [blame] | 531 | fteid_u_ie := ts_GTP2C_FTEID(FTEID_IF_S2bU_PGW_GTPU, g_pars.bearer.teid_local, 4, |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 532 | f_inet_addr(mp_s2b_local_ip), omit); |
| 533 | paa := ts_GTP2C_PdnAddrAlloc_v4(f_inet_addr(g_pars.ue_ip)); |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 534 | bctx_ies := ts_GTP2C_BcContextIE(ebi := g_pars.bearer.ebi, |
Pau Espin Pedrol | 8c74649 | 2023-10-23 20:56:09 +0200 | [diff] [blame] | 535 | teid_list := { fteid_u_ie }, |
| 536 | qos := ts_GTP2C_BearerQos('09'O, 0,0,0,0), |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 537 | charging_id := ts_GTP2C_ChargingID(g_pars.teic_local)); |
Pau Espin Pedrol | fa2b384 | 2023-12-13 18:49:19 +0100 | [diff] [blame] | 538 | GTP2.send(ts_GTP2C_CreateSessionResp(g_pars.teic_remote, rx_msg.sequenceNumber, |
Pau Espin Pedrol | 7b2cc92 | 2024-02-28 16:14:15 +0100 | [diff] [blame] | 539 | Request_accepted, |
Pau Espin Pedrol | fa2b384 | 2023-12-13 18:49:19 +0100 | [diff] [blame] | 540 | { fteid_c_ie }, paa, |
Pau Espin Pedrol | f292586 | 2024-02-22 20:12:30 +0100 | [diff] [blame] | 541 | { ts_GTP2C_BcGrouped(bctx_ies) }, |
| 542 | f_GTPv2C_gen_APCO_response(rx_msg.gtpcv2_pdu.createSessionRequest.aPCO) )); |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 543 | setverdict(pass); |
| 544 | } |
| 545 | [] GTP2.receive(PDU_GTPCv2:?) -> value rx_msg { |
| 546 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GTP2C msg rx: ", rx_msg)); |
| 547 | } |
| 548 | } |
Pau Espin Pedrol | 4944a5c | 2024-01-24 17:23:01 +0100 | [diff] [blame] | 549 | |
Pau Espin Pedrol | 7b2cc92 | 2024-02-28 16:14:15 +0100 | [diff] [blame] | 550 | /* ePDG Creates session at the PGW. PGW sends Diameter s6b AAR + AAA. */ |
| 551 | private altstep as_GTP2C_CreateSession_error(GTP2C_Cause resp_cause, boolean do_s6b_aar := false) runs on EPDG_ConnHdlr { |
| 552 | var PDU_GTPCv2 rx_msg; |
| 553 | var template (value) FullyQualifiedTEID fteid_c_ie, fteid_u_ie; |
| 554 | var template (value) PDN_AddressAllocation paa; |
| 555 | var template (value) BearerContextIEs bctx_ies; |
| 556 | |
| 557 | [] GTP2.receive(tr_GTP2C_CreateSessionReq(g_pars.imsi, apco := f_exp_tr_GTP2C_APCO_in_CreateSessionReq())) -> value rx_msg { |
| 558 | f_EPDG_ConnHdlr_parse_CreateSessionReq(rx_msg); |
| 559 | |
| 560 | /* Upon rx of CreateSession, emulate PGW asking the AAA server. */ |
| 561 | if (do_s6b_aar) { |
| 562 | f_S6b_AA_success(); |
| 563 | } |
| 564 | |
| 565 | fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S2b_PGW_GTPC, g_pars.teic_local, 1, |
| 566 | f_inet_addr(mp_s2b_local_ip), omit); |
| 567 | fteid_u_ie := ts_GTP2C_FTEID(FTEID_IF_S2bU_PGW_GTPU, g_pars.bearer.teid_local, 4, |
| 568 | f_inet_addr(mp_s2b_local_ip), omit); |
| 569 | GTP2.send(ts_GTP2C_CreateSessionResp(g_pars.teic_remote, rx_msg.sequenceNumber, |
| 570 | resp_cause)); |
| 571 | setverdict(pass); |
| 572 | } |
| 573 | [] GTP2.receive(PDU_GTPCv2:?) -> value rx_msg { |
| 574 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GTP2C msg rx: ", rx_msg)); |
| 575 | } |
| 576 | } |
| 577 | |
Pau Espin Pedrol | 4944a5c | 2024-01-24 17:23:01 +0100 | [diff] [blame] | 578 | /* ePDG Deletes session at the PGW. PGW sends Diameter s6b AAR + AAA. */ |
| 579 | private altstep as_GTP2C_DeleteSession_success() runs on EPDG_ConnHdlr { |
| 580 | var PDU_GTPCv2 rx_msg; |
| 581 | var BearerContextIEs rx_bctx_ies; |
| 582 | var template (value) FullyQualifiedTEID fteid_c_ie, fteid_u_ie; |
| 583 | var template (value) PDN_AddressAllocation paa; |
| 584 | var template (value) BearerContextIEs bctx_ies; |
| 585 | |
| 586 | [] GTP2.receive(tr_GTP2C_DeleteSessionReq(g_pars.teic_local)) -> value rx_msg { |
| 587 | /* Upon rx of DeleteSession, emulate PGW requesting the AAA server for Sesssion Termination. */ |
| 588 | f_S6b_ST_success(); |
| 589 | |
| 590 | GTP2.send(ts_GTP2C_DeleteSessionResp(g_pars.teic_remote, |
| 591 | rx_msg.sequenceNumber, |
| 592 | Request_accepted)); |
| 593 | setverdict(pass); |
| 594 | } |
| 595 | [] GTP2.receive(PDU_GTPCv2:?) -> value rx_msg { |
| 596 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GTP2C msg rx: ", rx_msg)); |
| 597 | } |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 598 | } |
| 599 | |
Pau Espin Pedrol | 14abac5 | 2024-02-05 21:05:17 +0100 | [diff] [blame] | 600 | /* Expect CreateBearerResponse */ |
| 601 | private altstep as_GTP2C_CreateBearer_success() runs on EPDG_ConnHdlr { |
| 602 | var PDU_GTPCv2 rx_msg; |
| 603 | |
| 604 | [] GTP2.receive(tr_GTP2C_CreateBearerResp(g_pars.teic_local)) -> value rx_msg { |
| 605 | setverdict(pass); |
| 606 | } |
| 607 | [] GTP2.receive(PDU_GTPCv2:?) -> value rx_msg { |
| 608 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GTP2C msg rx: ", rx_msg)); |
| 609 | } |
| 610 | } |
| 611 | private function f_GTP2C_CreateBearer_success(uint4_t dedicated_bearer_id := 6) runs on EPDG_ConnHdlr { |
| 612 | |
| 613 | var template (value) FullyQualifiedTEID fteid_u_ie := ts_GTP2C_FTEID(FTEID_IF_S2bU_ePDG_GTPU, g_pars.bearer.teid_local, dedicated_bearer_id, |
| 614 | f_inet_addr(mp_s2b_local_ip), omit); |
| 615 | var template (value) FullyQualifiedTEID_List teid_list := { fteid_u_ie }; |
| 616 | |
| 617 | var template (value) FullyQualifiedPDN_ConnectionSetID pgw_fq_csid := ts_GTP2C_FQCSID_IPv4(f_inet_addr(mp_s2b_local_ip), int2oct(dedicated_bearer_id, 2)); |
| 618 | var template (value) FullyQualifiedPDN_ConnectionSetID_List csid_list := { pgw_fq_csid }; |
| 619 | |
| 620 | var template (value) BearerContextGrouped_List bcg_list := { |
| 621 | ts_GTP2C_BcGrouped({ |
| 622 | ePS_Bearer_ID := ts_GTP2C_EpsBearerId(dedicated_bearer_id), |
| 623 | cause := omit, |
| 624 | ePS_Bearer_TFT := omit, |
| 625 | fullyQualifiedTEID := teid_list, |
| 626 | bearerLevel_QoS := ts_GTP2C_BearerQos('09'O, 0,0,0,0), |
| 627 | chargingID := ts_GTP2C_ChargingID(f_rnd_octstring(4)), |
| 628 | bearerFlags := omit, |
| 629 | transactionIdentifier := omit, |
| 630 | protocolConfigOptions := omit, |
| 631 | rAN_NASCause := omit, |
| 632 | additionalProtocolConfigOptions := omit, |
| 633 | extendedProtocolConfigOptions := omit |
| 634 | }) |
| 635 | }; |
| 636 | GTP2.send(ts_GTP2C_CreateBearerReq(g_pars.teic_remote, omit, g_pars.bearer.ebi, |
| 637 | dedicated_bearer_id, bcg_list, csid_list)); |
| 638 | as_GTP2C_CreateBearer_success(); |
| 639 | } |
| 640 | |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 641 | /* Expect DeleteBearerResponse */ |
| 642 | private altstep as_GTP2C_DeleteBearer_success() runs on EPDG_ConnHdlr { |
| 643 | var PDU_GTPCv2 rx_msg; |
| 644 | var template (value) FullyQualifiedTEID fteid_c_ie, fteid_u_ie; |
| 645 | var template (value) PDN_AddressAllocation paa; |
| 646 | |
| 647 | [] GTP2.receive(tr_GTP2C_DeleteBearerResp(g_pars.teic_local)) -> value rx_msg { |
| 648 | setverdict(pass); |
| 649 | } |
| 650 | [] GTP2.receive(PDU_GTPCv2:?) -> value rx_msg { |
| 651 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GTP2C msg rx: ", rx_msg)); |
| 652 | } |
| 653 | } |
| 654 | private function f_GTP2C_DeleteBearer_success() runs on EPDG_ConnHdlr { |
| 655 | var integer proc_trans_id := 3; |
| 656 | GTP2.send(ts_GTP2C_DeleteBearerReq(g_pars.teic_remote, proc_trans_id, g_pars.bearer.ebi, Access_changed_from_Non_3GPP_to_3GPP)); |
Pau Espin Pedrol | cbe6eba | 2024-02-06 12:53:14 +0100 | [diff] [blame] | 657 | as_GSUP_CancelLocation_success(); |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 658 | as_GTP2C_DeleteBearer_success(); |
| 659 | } |
| 660 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 661 | /* GSUP AuthInfo Req + Resp, triggers SWx MAR + MAA. */ |
| 662 | private function f_GSUP_AI_success() runs on EPDG_ConnHdlr { |
| 663 | var GSUP_PDU rx_gsup; |
Pau Espin Pedrol | c2cfd55 | 2024-02-07 17:51:55 +0100 | [diff] [blame] | 664 | var template (present) GSUP_IE auth_tuple_ie; |
| 665 | var template (value) GSUP_IEs pdp_info; |
| 666 | auth_tuple_ie := tr_GSUP_IE_AuthTuple3G(g_pars.vec.rand, |
| 667 | g_pars.vec.ik, |
| 668 | g_pars.vec.ck, |
| 669 | g_pars.vec.autn, |
| 670 | g_pars.vec.rand & g_pars.vec.auts); |
| 671 | pdp_info := { ts_GSUP_IE_PDP_CONTEXT_ID('00'O), |
| 672 | ts_GSUP_IE_PDP_ADDRESS(ts_EuaIPv4Dyn), |
| 673 | ts_GSUP_IE_APN(f_enc_dns_hostname(g_pars.apn)) }; |
| 674 | GSUP.send(ts_GSUP_SAI_REQ_PDP_INFO(g_pars.imsi, pdp_info)); |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 675 | as_DIA_SWx_MA_success(); |
| 676 | /* Expect a positive response back to the translator; expect AIA */ |
| 677 | alt { |
| 678 | [] GSUP.receive(tr_GSUP_SAI_RES(g_pars.imsi, auth_tuple_ie)); |
| 679 | [] GSUP.receive(GSUP_PDU:?) -> value rx_gsup { |
| 680 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GSUP msg rx: ", rx_gsup)); |
| 681 | } |
| 682 | } |
| 683 | setverdict(pass); |
| 684 | } |
| 685 | |
| 686 | /* GSUP LU Req + Resp, triggers SWx SAR + SAA (Server Assignment). */ |
| 687 | private function f_GSUP_LU_success() runs on EPDG_ConnHdlr { |
| 688 | var GSUP_PDU rx_gsup; |
| 689 | var template octetstring destination_name := *; |
| 690 | GSUP.send(ts_GSUP_UL_REQ(g_pars.imsi)); |
Pau Espin Pedrol | 4944a5c | 2024-01-24 17:23:01 +0100 | [diff] [blame] | 691 | as_DIA_SWx_SA_success(REGISTRATION); |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 692 | /* Expect a positive response back to the translator */ |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 693 | alt { |
| 694 | [] GSUP.receive(tr_GSUP_UL_RES(g_pars.imsi, destination_name)); |
| 695 | [] GSUP.receive(GSUP_PDU:?) -> value rx_gsup { |
| 696 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GSUP msg rx: ", rx_gsup)); |
| 697 | } |
| 698 | } |
| 699 | setverdict(pass); |
| 700 | } |
| 701 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 702 | /* GSUP TunnelEPDG Tunnel Req + Resp, triggers S2b CreateSession Req + Response. */ |
| 703 | private function f_GSUP_EPDGTunnel_success() runs on EPDG_ConnHdlr { |
| 704 | var GSUP_PDU rx_gsup; |
Pau Espin Pedrol | ce1d3cb | 2024-02-21 17:40:59 +0100 | [diff] [blame] | 705 | var template (value) PCO_DATA pco := ts_PCO({ ts_PCO_P_DNS_IPv4, ts_PCO_P_PCSCF_IPv4 }); |
| 706 | GSUP.send(ts_GSUP_EPDGTunnel_REQ(g_pars.imsi, pco)); |
Pau Espin Pedrol | 4944a5c | 2024-01-24 17:23:01 +0100 | [diff] [blame] | 707 | as_GTP2C_CreateSession_success(); |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 708 | /* Expect a positive response back to the translator; */ |
Pau Espin Pedrol | f292586 | 2024-02-22 20:12:30 +0100 | [diff] [blame] | 709 | var template (present) GSUP_IEs exp_pdp_info := { |
Pau Espin Pedrol | a6b0c1c | 2024-01-22 20:02:06 +0100 | [diff] [blame] | 710 | tr_GSUP_IE_PDP_CONTEXT_ID(?), |
Pau Espin Pedrol | 78598b5 | 2024-02-14 19:21:42 +0100 | [diff] [blame] | 711 | tr_GSUP_IE_PDP_ADDRESS(tr_GSUP_PDP_Address_IPv4(f_inet_addr(g_pars.ue_ip))), |
| 712 | tr_GSUP_IE_APN(f_enc_dns_hostname(g_pars.apn)), |
Pau Espin Pedrol | a6b0c1c | 2024-01-22 20:02:06 +0100 | [diff] [blame] | 713 | tr_GSUP_IE_PDP_QOS(?), |
| 714 | tr_GSUP_IE_Charging_Characteristics(?) |
| 715 | }; |
Pau Espin Pedrol | f292586 | 2024-02-22 20:12:30 +0100 | [diff] [blame] | 716 | var template (present) PCO_DATA exp_pco := tr_PCO({ |
| 717 | tr_PCO_P_DNS_IPv4(f_inet_addr(mp_s2b_dns_ipv4)), |
| 718 | tr_PCO_P_PCSCF_IPv4(f_inet_addr(mp_s2b_pcscf_ipv4)) |
| 719 | }); |
| 720 | /* TODO: check for v6 and v4v6 types ^ */ |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 721 | alt { |
Pau Espin Pedrol | f292586 | 2024-02-22 20:12:30 +0100 | [diff] [blame] | 722 | [] GSUP.receive(tr_GSUP_EPDGTunnel_RES(g_pars.imsi, exp_pdp_info)); |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 723 | [] GSUP.receive(GSUP_PDU:?) -> value rx_gsup { |
| 724 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GSUP msg rx: ", rx_gsup)); |
| 725 | } |
| 726 | } |
| 727 | setverdict(pass); |
| 728 | } |
| 729 | |
Pau Espin Pedrol | 7b2cc92 | 2024-02-28 16:14:15 +0100 | [diff] [blame] | 730 | /* GSUP TunnelEPDG Tunnel Req + Resp, triggers S2b CreateSession Req + Response (rejected). */ |
| 731 | private function f_GSUP_EPDGTunnel_error() runs on EPDG_ConnHdlr { |
| 732 | var GSUP_PDU rx_gsup; |
| 733 | var template (value) PCO_DATA pco := ts_PCO({ ts_PCO_P_DNS_IPv4, ts_PCO_P_PCSCF_IPv4 }); |
| 734 | GSUP.send(ts_GSUP_EPDGTunnel_REQ(g_pars.imsi, pco)); |
| 735 | as_GTP2C_CreateSession_error(APN_access_denied__no_subscription); |
| 736 | alt { |
| 737 | [] GSUP.receive(tr_GSUP_EPDGTunnel_ERR(g_pars.imsi)); |
| 738 | [] GSUP.receive(GSUP_PDU:?) -> value rx_gsup { |
| 739 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GSUP msg rx: ", rx_gsup)); |
| 740 | } |
| 741 | } |
| 742 | setverdict(pass); |
| 743 | } |
| 744 | |
Pau Espin Pedrol | 4944a5c | 2024-01-24 17:23:01 +0100 | [diff] [blame] | 745 | /* GSUP Purge MS Req + Resp, triggers S2b DeleteSession Req + Response. */ |
| 746 | private function f_GSUP_PurgeMS_success() runs on EPDG_ConnHdlr { |
| 747 | var GSUP_PDU rx_gsup; |
| 748 | GSUP.send(ts_GSUP_PURGE_MS_REQ(g_pars.imsi, OSMO_GSUP_CN_DOMAIN_PS)); |
| 749 | as_GTP2C_DeleteSession_success(); |
| 750 | /* ePDG internally sends STR to its AAA-Server. Since all sessions |
| 751 | become inactive, AAA-Server sends SAR(USER_DEREGISTRATION) to HSS: */ |
| 752 | |
| 753 | /* Expect a positive response back to the translator; */ |
| 754 | as_DIA_SWx_SA_success(USER_DEREGISTRATION); |
| 755 | alt { |
| 756 | [] GSUP.receive(tr_GSUP_PURGE_MS_RES(g_pars.imsi)); |
| 757 | [] GSUP.receive(GSUP_PDU:?) -> value rx_gsup { |
| 758 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GSUP msg rx: ", rx_gsup)); |
| 759 | } |
| 760 | } |
| 761 | setverdict(pass); |
| 762 | } |
| 763 | |
Pau Espin Pedrol | cbe6eba | 2024-02-06 12:53:14 +0100 | [diff] [blame] | 764 | /* Expect CancelLocationReq */ |
| 765 | private altstep as_GSUP_CancelLocation_success() runs on EPDG_ConnHdlr { |
| 766 | var GSUP_PDU rx_gsup; |
| 767 | |
| 768 | [] GSUP.receive(tr_GSUP_CL_REQ(g_pars.imsi)) -> value rx_gsup { |
| 769 | GSUP.send(ts_GSUP_CL_RES(g_pars.imsi)); |
| 770 | } |
| 771 | [] GSUP.receive(GSUP_PDU:?) -> value rx_gsup { |
| 772 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GSUP msg rx: ", rx_gsup)); |
| 773 | } |
| 774 | } |
| 775 | |
Pau Espin Pedrol | af8ba58 | 2024-02-05 21:05:10 +0100 | [diff] [blame] | 776 | private function f_initial_attach() runs on EPDG_ConnHdlr { |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 777 | f_GSUP_AI_success(); |
| 778 | f_GSUP_LU_success(); |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 779 | f_GSUP_EPDGTunnel_success(); |
Pau Espin Pedrol | af8ba58 | 2024-02-05 21:05:10 +0100 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | private function f_TC_authinfo_normal(charstring id) runs on EPDG_ConnHdlr { |
| 783 | f_initial_attach(); |
Pau Espin Pedrol | 4944a5c | 2024-01-24 17:23:01 +0100 | [diff] [blame] | 784 | f_GSUP_PurgeMS_success(); |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 785 | } |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 786 | testcase TC_authinfo_normal() runs on MTC_CT { |
| 787 | var EPDG_ConnHdlrPars pars := f_init_pars(); |
| 788 | var EPDG_ConnHdlr vc_conn; |
| 789 | f_init(); |
| 790 | vc_conn := f_start_handler(refers(f_TC_authinfo_normal), pars); |
| 791 | vc_conn.done; |
| 792 | setverdict(pass); |
| 793 | } |
| 794 | |
Pau Espin Pedrol | 14abac5 | 2024-02-05 21:05:17 +0100 | [diff] [blame] | 795 | private function f_TC_ho_lte_to_wifi(charstring id) runs on EPDG_ConnHdlr { |
| 796 | f_initial_attach(); |
| 797 | /* Whenever UE comes from 3GPP, PGW may activate a dedicated S2b bearer |
| 798 | * and notify ePDG with a Create Bearer Request */ |
| 799 | f_GTP2C_CreateBearer_success(); |
| 800 | f_GSUP_PurgeMS_success(); |
| 801 | } |
Pau Espin Pedrol | 14abac5 | 2024-02-05 21:05:17 +0100 | [diff] [blame] | 802 | testcase TC_ho_lte_to_wifi() runs on MTC_CT { |
| 803 | var EPDG_ConnHdlrPars pars := f_init_pars(); |
| 804 | var EPDG_ConnHdlr vc_conn; |
| 805 | f_init(); |
| 806 | vc_conn := f_start_handler(refers(f_TC_ho_lte_to_wifi), pars); |
| 807 | vc_conn.done; |
| 808 | setverdict(pass); |
| 809 | } |
| 810 | |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 811 | private function f_TC_ho_wifi_to_lte(charstring id) runs on EPDG_ConnHdlr { |
Pau Espin Pedrol | af8ba58 | 2024-02-05 21:05:10 +0100 | [diff] [blame] | 812 | f_initial_attach(); |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 813 | /* Whenever UE goes back to 3GPP, PGW will notify ePDG with a Delete Bearer Request |
| 814 | * cause="Access changed from non-3gpp to 3gpp" */ |
| 815 | f_GTP2C_DeleteBearer_success(); |
| 816 | } |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 817 | testcase TC_ho_wifi_to_lte() runs on MTC_CT { |
| 818 | var EPDG_ConnHdlrPars pars := f_init_pars(); |
| 819 | var EPDG_ConnHdlr vc_conn; |
| 820 | f_init(); |
| 821 | vc_conn := f_start_handler(refers(f_TC_ho_wifi_to_lte), pars); |
| 822 | vc_conn.done; |
| 823 | setverdict(pass); |
| 824 | } |
| 825 | |
Pau Espin Pedrol | 7b2cc92 | 2024-02-28 16:14:15 +0100 | [diff] [blame] | 826 | private function f_TC_s2b_CreateSession_rejected(charstring id) runs on EPDG_ConnHdlr { |
| 827 | f_GSUP_AI_success(); |
| 828 | f_GSUP_LU_success(); |
| 829 | f_GSUP_EPDGTunnel_error(); |
| 830 | } |
| 831 | testcase TC_s2b_CreateSession_rejected() runs on MTC_CT { |
| 832 | var EPDG_ConnHdlrPars pars := f_init_pars(); |
| 833 | var EPDG_ConnHdlr vc_conn; |
| 834 | f_init(); |
| 835 | vc_conn := f_start_handler(refers(f_TC_s2b_CreateSession_rejected), pars); |
| 836 | vc_conn.done; |
| 837 | setverdict(pass); |
| 838 | } |
| 839 | |
Pau Espin Pedrol | 285a2b6 | 2024-02-27 18:25:45 +0100 | [diff] [blame] | 840 | private function f_TC_concurrent_ues(charstring id) runs on EPDG_ConnHdlr { |
| 841 | COORD.send(COORD_CMD_READY); |
| 842 | COORD.receive(COORD_CMD_START); |
| 843 | f_initial_attach(); |
| 844 | COORD.send(COORD_CMD_ATTACHED); |
| 845 | COORD.receive(COORD_CMD_STOP); |
| 846 | f_GSUP_PurgeMS_success(); |
| 847 | } |
| 848 | private function f_TC_concurrent_ues_MTC(integer num_ues) runs on MTC_CT { |
| 849 | var EPDG_ConnHdlrList vc_conn_list := {}; |
| 850 | var EPDG_ConnHdlr vc_conn; |
| 851 | f_init(t_guard := 100.0); |
| 852 | |
| 853 | for (var integer i := 0; i < num_ues; i := i + 1) { |
| 854 | var EPDG_ConnHdlrPars pars := f_init_pars(i); |
| 855 | vc_conn := f_start_handler(refers(f_TC_concurrent_ues), pars); |
| 856 | vc_conn_list := vc_conn_list & { vc_conn }; |
| 857 | } |
| 858 | |
| 859 | for (var integer i := 0; i < num_ues; i := i + 1) { |
| 860 | COORD.receive(COORD_CMD_READY) from vc_conn_list[i]; |
| 861 | } |
| 862 | |
| 863 | for (var integer i := 0; i < num_ues; i := i + 1) { |
| 864 | COORD.send(COORD_CMD_START) to vc_conn_list[i]; |
| 865 | f_sleep(0.1); |
| 866 | } |
| 867 | |
| 868 | for (var integer i := 0; i < num_ues; i := i + 1) { |
| 869 | COORD.receive(COORD_CMD_ATTACHED) from vc_conn_list[i]; |
| 870 | } |
| 871 | |
| 872 | log("All attached!"); |
| 873 | f_sleep(1.0); |
| 874 | |
| 875 | for (var integer i := 0; i < num_ues; i := i + 1) { |
| 876 | COORD.send(COORD_CMD_STOP) to vc_conn_list[i]; |
| 877 | } |
| 878 | |
| 879 | for (var integer i := 0; i < num_ues; i := i + 1) { |
| 880 | vc_conn_list[i].done; |
| 881 | } |
| 882 | |
| 883 | setverdict(pass); |
| 884 | } |
| 885 | testcase TC_concurrent_ues2() runs on MTC_CT { |
| 886 | f_TC_concurrent_ues_MTC(2) |
| 887 | } |
| 888 | testcase TC_concurrent_ues100() runs on MTC_CT { |
| 889 | f_TC_concurrent_ues_MTC(100) |
| 890 | } |
| 891 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 892 | control { |
| 893 | execute ( TC_authinfo_normal() ); |
Pau Espin Pedrol | 14abac5 | 2024-02-05 21:05:17 +0100 | [diff] [blame] | 894 | execute ( TC_ho_lte_to_wifi() ); |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 895 | execute ( TC_ho_wifi_to_lte() ); |
Pau Espin Pedrol | 7b2cc92 | 2024-02-28 16:14:15 +0100 | [diff] [blame] | 896 | execute ( TC_s2b_CreateSession_rejected() ); |
Pau Espin Pedrol | 285a2b6 | 2024-02-27 18:25:45 +0100 | [diff] [blame] | 897 | execute ( TC_concurrent_ues2() ); |
| 898 | execute ( TC_concurrent_ues100() ); |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | } |