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; |
| 8 | |
| 9 | import from IPA_Emulation all; |
| 10 | import from GSUP_Emulation all; |
| 11 | import from GSUP_Types all; |
| 12 | |
| 13 | import from DIAMETER_Types all; |
| 14 | import from DIAMETER_Templates all; |
Pau Espin Pedrol | 4669b61 | 2023-10-23 17:43:14 +0200 | [diff] [blame] | 15 | import from DIAMETER_ts29_273_Templates all; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 16 | import from DIAMETER_Emulation all; |
| 17 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 18 | import from GTPv2_Types all; |
| 19 | import from GTPv2_Templates all; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 20 | import from GTPv2_Emulation all; |
| 21 | |
| 22 | modulepar { |
| 23 | /* our emulated GSUP strongswan (CEAI iface) */ |
| 24 | charstring mp_gsup_local_ip := "127.0.0.100"; |
| 25 | integer mp_gsup_local_port := 0; |
| 26 | charstring mp_gsup_remote_ip := "127.0.0.1"; |
| 27 | integer mp_gsup_remote_port := 4222; |
| 28 | |
| 29 | /* our emulated HSS */ |
| 30 | charstring mp_swx_local_ip := "127.0.0.100"; |
| 31 | integer mp_swx_local_port := 3868; |
| 32 | |
| 33 | /* our emulated PGW (Diameter S6b) */ |
| 34 | charstring mp_s6b_local_ip := "127.0.0.100"; |
| 35 | integer mp_s6b_local_port := 3869; |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 36 | charstring mp_s6b_remote_ip := "127.0.0.1"; |
| 37 | integer mp_s6b_remote_port := 3869; |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 38 | |
| 39 | /* our emulated PGW (GTPv2C S2b) */ |
| 40 | charstring mp_s2b_local_ip := "127.0.0.100"; |
| 41 | integer mp_s2b_local_port := GTP2C_PORT; |
| 42 | charstring mp_s2b_remote_ip := "127.0.0.1"; |
| 43 | integer mp_s2b_remote_port := GTP2C_PORT; |
| 44 | |
| 45 | charstring mp_diam_realm := "localdomain"; |
| 46 | } |
| 47 | |
| 48 | |
| 49 | type component MTC_CT { |
| 50 | var DIAMETER_Emulation_CT vc_SWx; |
| 51 | port DIAMETER_PT SWx_UNIT; |
| 52 | port DIAMETEREM_PROC_PT SWx_PROC; |
| 53 | |
| 54 | var DIAMETER_Emulation_CT vc_S6b; |
| 55 | port DIAMETER_PT S6b_UNIT; |
| 56 | port DIAMETEREM_PROC_PT S6b_PROC; |
| 57 | |
| 58 | var GSUP_Emulation_CT vc_GSUP; |
| 59 | var IPA_Emulation_CT vc_GSUP_IPA; |
| 60 | port IPA_CTRL_PT GSUP_IPA_EVENT; |
| 61 | |
| 62 | var GTPv2_Emulation_CT vc_GTP2; |
| 63 | port GTP2EM_PT TEID0; |
| 64 | |
| 65 | timer g_Tguard; |
| 66 | }; |
| 67 | |
| 68 | private altstep as_Tguard() runs on MTC_CT { |
| 69 | [] g_Tguard.timeout { |
| 70 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Tguard timeout"); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | type component DIAMETER_ConnHdlr_CT extends DIAMETER_ConnHdlr { |
| 75 | port DIAMETER_Conn_PT DIAMETER_CLIENT; |
| 76 | port DIAMETEREM_PROC_PT DIAMETER_PROC_CLIENT; |
| 77 | } |
| 78 | |
| 79 | function f_diam_connhldr_ct_main(hexstring imsi) runs on DIAMETER_ConnHdlr_CT { |
| 80 | var DIAMETER_ConnHdlr vc_conn_unused; |
| 81 | var PDU_DIAMETER msg; |
| 82 | var UINT32 ete_id; |
| 83 | |
| 84 | f_diameter_expect_imsi(imsi); |
| 85 | |
| 86 | |
| 87 | while (true) { |
| 88 | alt { |
| 89 | [] DIAMETER_CLIENT.receive(PDU_DIAMETER:?) -> value msg { |
| 90 | DIAMETER.send(msg); |
| 91 | } |
| 92 | [] DIAMETER.receive(PDU_DIAMETER:?) -> value msg { |
| 93 | DIAMETER_CLIENT.send(msg); |
| 94 | } |
| 95 | [] DIAMETER_PROC_CLIENT.getcall(DIAMETEREM_register_eteid:{?,?}) -> param(ete_id, vc_conn_unused) { |
| 96 | DIAMETER_PROC.call(DIAMETEREM_register_eteid:{ete_id, self}) { |
| 97 | [] DIAMETER_PROC.getreply(DIAMETEREM_register_eteid:{?,?}) {}; |
| 98 | } |
| 99 | DIAMETER_PROC_CLIENT.reply(DIAMETEREM_register_eteid:{ete_id, vc_conn_unused}); |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | type component EPDG_ConnHdlr extends DIAMETER_ConnHdlr, GSUP_ConnHdlr, GTP2_ConnHdlr { |
| 106 | var EPDG_ConnHdlrPars g_pars; |
| 107 | |
| 108 | port DIAMETER_Conn_PT SWx; |
| 109 | port DIAMETEREM_PROC_PT SWx_PROC; |
| 110 | port DIAMETER_Conn_PT S6b; |
| 111 | port DIAMETEREM_PROC_PT S6b_PROC; |
| 112 | }; |
| 113 | |
| 114 | |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 115 | type record BearerConfig { |
| 116 | /* EPS Bearer ID */ |
| 117 | uint4_t ebi optional, |
| 118 | /* TEI (Data) local side */ |
| 119 | OCT4 teid_local optional, |
| 120 | /* TEI (Data) remote side */ |
| 121 | OCT4 teid_remote optional |
| 122 | }; |
| 123 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 124 | type record EPDG_ConnHdlrPars { |
| 125 | hexstring imsi, |
Pau Espin Pedrol | 2c2e187 | 2023-10-23 18:31:03 +0200 | [diff] [blame] | 126 | charstring apn, |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 127 | charstring ue_ip, |
| 128 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 129 | /* TEI (Control) local side */ |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 130 | OCT4 teic_local, |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 131 | /* TEI (Control) remote side */ |
| 132 | OCT4 teic_remote optional, |
| 133 | |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 134 | BearerConfig bearer optional, |
| 135 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 136 | AuthVector vec optional |
| 137 | }; |
| 138 | |
| 139 | private function f_epdg_connhldr_SWx_expect_eteid(UINT32 ete_id) runs on EPDG_ConnHdlr { |
| 140 | SWx_PROC.call(DIAMETEREM_register_eteid:{ete_id, null}) { |
| 141 | [] SWx_PROC.getreply(DIAMETEREM_register_eteid:{?,?}) {}; |
| 142 | } |
| 143 | } |
| 144 | private function f_epdg_connhldr_S6b_expect_eteid(UINT32 ete_id) runs on EPDG_ConnHdlr { |
| 145 | S6b_PROC.call(DIAMETEREM_register_eteid:{ete_id, null}) { |
| 146 | [] S6b_PROC.getreply(DIAMETEREM_register_eteid:{?,?}) {}; |
| 147 | } |
| 148 | } |
| 149 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 150 | private function f_init_pars(integer imsi_suffix := 1) |
| 151 | runs on MTC_CT return EPDG_ConnHdlrPars { |
| 152 | var EPDG_ConnHdlrPars pars := { |
| 153 | imsi := f_gen_imsi(imsi_suffix), |
Pau Espin Pedrol | 2c2e187 | 2023-10-23 18:31:03 +0200 | [diff] [blame] | 154 | apn := "internet", |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 155 | ue_ip := "192.168.123.50", |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 156 | teic_local := '00000000'O, |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 157 | teic_remote := omit, |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 158 | bearer := { |
| 159 | ebi := omit, |
| 160 | teid_local := omit, |
| 161 | teid_remote := omit |
| 162 | }, |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 163 | vec := f_gen_auth_vec_3g() |
| 164 | }; |
| 165 | return pars; |
| 166 | } |
| 167 | |
| 168 | private function f_init_gsup(charstring id) runs on MTC_CT { |
| 169 | id := id & "-GSUP"; |
| 170 | var GsupOps ops := { |
| 171 | create_cb := refers(GSUP_Emulation.ExpectedCreateCallback) |
| 172 | }; |
| 173 | |
| 174 | vc_GSUP_IPA := IPA_Emulation_CT.create(id & "-IPA"); |
| 175 | vc_GSUP := GSUP_Emulation_CT.create(id); |
| 176 | |
| 177 | map(vc_GSUP_IPA:IPA_PORT, system:IPA_CODEC_PT); |
| 178 | connect(vc_GSUP:GSUP, vc_GSUP_IPA:IPA_GSUP_PORT); |
| 179 | /* we use this hack to get events like ASP_IPA_EVENT_UP */ |
| 180 | connect(vc_GSUP_IPA:IPA_CTRL_PORT, self:GSUP_IPA_EVENT); |
| 181 | |
| 182 | vc_GSUP.start(GSUP_Emulation.main(ops, id)); |
| 183 | vc_GSUP_IPA.start(IPA_Emulation.main_client(mp_gsup_remote_ip, mp_gsup_remote_port, |
| 184 | mp_gsup_local_ip, mp_gsup_local_port)); |
| 185 | |
| 186 | /* wait for incoming connection to GSUP port before proceeding */ |
| 187 | timer T := 10.0; |
| 188 | T.start; |
| 189 | alt { |
| 190 | [] GSUP_IPA_EVENT.receive(tr_ASP_IPA_EV(ASP_IPA_EVENT_UP)) { } |
| 191 | [] T.timeout { |
| 192 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "No connection to GSUP Port"); |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | private function DiameterForwardUnitdataCallback(PDU_DIAMETER msg) |
| 198 | runs on DIAMETER_Emulation_CT return template PDU_DIAMETER { |
| 199 | DIAMETER_UNIT.send(msg); |
| 200 | return omit; |
| 201 | } |
| 202 | |
| 203 | private function f_init_diameter(charstring id) runs on MTC_CT { |
| 204 | var DIAMETEROps ops := { |
| 205 | create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback), |
| 206 | unitdata_cb := refers(DiameterForwardUnitdataCallback), |
| 207 | raw := false /* handler mode (IMSI based routing) */ |
| 208 | }; |
| 209 | var DIAMETER_conn_parameters pars; |
| 210 | |
| 211 | /* SWx setup: */ |
| 212 | pars := { |
| 213 | remote_ip := "", |
| 214 | remote_sctp_port := -1, /* server mode */ |
| 215 | local_ip := mp_swx_local_ip, |
| 216 | local_sctp_port := mp_swx_local_port, |
| 217 | origin_host := "hss." & mp_diam_realm, |
| 218 | origin_realm := mp_diam_realm, |
| 219 | auth_app_id := omit, |
| 220 | vendor_app_id := c_DIAMETER_3GPP_SWx_AID |
| 221 | }; |
| 222 | vc_SWx := DIAMETER_Emulation_CT.create(id); |
| 223 | map(vc_SWx:DIAMETER, system:DIAMETER_CODEC_PT); |
| 224 | connect(vc_SWx:DIAMETER_UNIT, self:SWx_UNIT); |
| 225 | connect(vc_SWx:DIAMETER_PROC, self:SWx_PROC); |
| 226 | vc_SWx.start(DIAMETER_Emulation.main(ops, pars, id)); |
| 227 | |
| 228 | /* S6b setup: */ |
| 229 | pars := { |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 230 | remote_ip := mp_s6b_remote_ip, |
| 231 | remote_sctp_port := mp_s6b_remote_port, /* client mode */ |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 232 | local_ip := mp_s6b_local_ip, |
| 233 | local_sctp_port := mp_s6b_local_port, |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 234 | origin_host := "pgw." & mp_diam_realm, |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 235 | origin_realm := mp_diam_realm, |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 236 | auth_app_id := c_DIAMETER_3GPP_S6b_AID, |
| 237 | vendor_app_id := c_DIAMETER_3GPP_S6b_AID |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 238 | }; |
| 239 | vc_S6b := DIAMETER_Emulation_CT.create(id); |
| 240 | map(vc_S6b:DIAMETER, system:DIAMETER_CODEC_PT); |
| 241 | connect(vc_S6b:DIAMETER_UNIT, self:S6b_UNIT); |
| 242 | connect(vc_S6b:DIAMETER_PROC, self:S6b_PROC); |
| 243 | vc_S6b.start(DIAMETER_Emulation.main(ops, pars, id)); |
| 244 | |
| 245 | f_diameter_wait_capability(SWx_UNIT); |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 246 | f_diameter_wait_capability(S6b_UNIT); |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 247 | |
| 248 | /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdog ping-pongs): |
| 249 | * RFC6733 sec 5.1 |
| 250 | * RFC3539 sec 3.4.1 [5] |
| 251 | * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49 |
| 252 | */ |
| 253 | f_sleep(1.0); |
| 254 | } |
| 255 | |
| 256 | private function f_init_gtp(charstring id) runs on MTC_CT { |
| 257 | var Gtp2EmulationCfg cfg := { |
| 258 | gtpc_bind_ip := mp_s2b_local_ip, |
| 259 | gtpc_bind_port := mp_s2b_local_port, |
| 260 | gtpc_remote_ip := mp_s2b_remote_ip, |
| 261 | gtpc_remote_port := mp_s2b_remote_port, |
| 262 | sgw_role := false, |
| 263 | use_gtpu_daemon := false /* TODO: maybe use, set to true */ |
| 264 | }; |
| 265 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 266 | vc_GTP2 := GTPv2_Emulation_CT.create(id & "-GTPV2"); |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 267 | map(vc_GTP2:GTP2C, system:GTP2C); |
| 268 | connect(vc_GTP2:TEID0, self:TEID0); |
| 269 | vc_GTP2.start(GTPv2_Emulation.main(cfg)); |
| 270 | } |
| 271 | |
| 272 | private function f_init(float t_guard := 40.0) runs on MTC_CT { |
| 273 | |
| 274 | g_Tguard.start(t_guard); |
| 275 | activate(as_Tguard()); |
| 276 | |
| 277 | f_init_gsup(testcasename()); |
| 278 | f_init_diameter(testcasename()); |
| 279 | f_init_gtp(testcasename()); |
| 280 | } |
| 281 | |
| 282 | private type function void_fn(charstring id) runs on EPDG_ConnHdlr; |
| 283 | |
| 284 | private function f_init_handler(void_fn fn, charstring id, EPDG_ConnHdlrPars pars) runs on EPDG_ConnHdlr { |
| 285 | g_pars := pars; |
| 286 | |
| 287 | /* tell GSUP dispatcher to send this IMSI to us */ |
| 288 | f_create_gsup_expect(hex2str(g_pars.imsi)); |
| 289 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 290 | /* tell GTPv2 dispatcher to send this IMSI to us */ |
| 291 | f_gtp2_register_imsi(g_pars.imsi); |
| 292 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 293 | fn.apply(id); |
| 294 | } |
| 295 | |
| 296 | private function f_start_handler(void_fn fn, EPDG_ConnHdlrPars pars) |
| 297 | runs on MTC_CT return EPDG_ConnHdlr { |
| 298 | var EPDG_ConnHdlr vc_conn; |
| 299 | var charstring id := testcasename(); |
| 300 | var DIAMETER_ConnHdlr_CT vc_conn_swx, vc_conn_s6b; |
| 301 | |
| 302 | vc_conn := EPDG_ConnHdlr.create(id); |
| 303 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 304 | /* GSUP */ |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 305 | connect(vc_conn:GSUP, vc_GSUP:GSUP_CLIENT); |
| 306 | connect(vc_conn:GSUP_PROC, vc_GSUP:GSUP_PROC); |
| 307 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 308 | /* GTP2 */ |
| 309 | connect(vc_conn:GTP2, vc_GTP2:CLIENT); |
| 310 | connect(vc_conn:GTP2_PROC, vc_GTP2:CLIENT_PROC); |
| 311 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 312 | /* SWx */ |
| 313 | vc_conn_swx := DIAMETER_ConnHdlr_CT.create(id); |
| 314 | connect(vc_conn_swx:DIAMETER, vc_SWx:DIAMETER_CLIENT); |
| 315 | connect(vc_conn_swx:DIAMETER_PROC, vc_SWx:DIAMETER_PROC); |
| 316 | connect(vc_conn:SWx, vc_conn_swx:DIAMETER_CLIENT); |
| 317 | connect(vc_conn:SWx_PROC, vc_conn_swx:DIAMETER_PROC_CLIENT); |
| 318 | vc_conn_swx.start(f_diam_connhldr_ct_main(pars.imsi)); |
| 319 | |
| 320 | /* S6b */ |
| 321 | vc_conn_s6b := DIAMETER_ConnHdlr_CT.create(id); |
| 322 | connect(vc_conn_s6b:DIAMETER, vc_S6b:DIAMETER_CLIENT); |
| 323 | connect(vc_conn_s6b:DIAMETER_PROC, vc_S6b:DIAMETER_PROC); |
| 324 | connect(vc_conn:S6b, vc_conn_s6b:DIAMETER_CLIENT); |
| 325 | connect(vc_conn:S6b_PROC, vc_conn_s6b:DIAMETER_PROC_CLIENT); |
| 326 | vc_conn_s6b.start(f_diam_connhldr_ct_main(pars.imsi)); |
| 327 | |
| 328 | vc_conn.start(f_init_handler(fn, id, pars)); |
| 329 | return vc_conn; |
| 330 | } |
| 331 | |
| 332 | /* Diameter SWx MAR + MAA. */ |
| 333 | private altstep as_DIA_SWx_MA_success() runs on EPDG_ConnHdlr { |
| 334 | var PDU_DIAMETER rx_dia; |
| 335 | var template (omit) AVP avp; |
| 336 | var octetstring sess_id; |
| 337 | var template (value) GenericAVP sip_auth_data_item; |
| 338 | [] SWx.receive(tr_DIA_SWx_MAR(g_pars.imsi)) -> value rx_dia { |
| 339 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id); |
| 340 | sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id); |
| 341 | sip_auth_data_item := ts_AVP_3GPP_SIPAuthDataItem(0, |
| 342 | g_pars.vec.rand, |
| 343 | g_pars.vec.ik, |
| 344 | g_pars.vec.ck, |
| 345 | g_pars.vec.autn, |
| 346 | g_pars.vec.auts); |
| 347 | /* Send MAA to translator; expect it to show up on GSUP side */ |
| 348 | SWx.send(ts_DIA_SWx_MAA(g_pars.imsi, sip_auth_data_item, |
| 349 | sess_id := sess_id, |
| 350 | hbh_id := rx_dia.hop_by_hop_id, |
| 351 | ete_id := rx_dia.end_to_end_id)); |
| 352 | setverdict(pass); |
| 353 | } |
| 354 | [] SWx.receive(PDU_DIAMETER:?) -> value rx_dia { |
| 355 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected Diameter msg rx: ", rx_dia)); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | /* Diameter SWx SAR + SAA. */ |
| 360 | private altstep as_DIA_SWx_SA_success() runs on EPDG_ConnHdlr { |
| 361 | var PDU_DIAMETER rx_dia; |
| 362 | var template (omit) AVP avp; |
| 363 | var octetstring sess_id; |
| 364 | [] SWx.receive(tr_DIA_SWx_SAR(g_pars.imsi)) -> value rx_dia { |
| 365 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id); |
| 366 | sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id); |
| 367 | /* Send SAA to translator; expect it to show up on GSUP side */ |
| 368 | SWx.send(ts_DIA_SWx_SAA(g_pars.imsi, |
| 369 | sess_id := sess_id, |
| 370 | hbh_id := rx_dia.hop_by_hop_id, |
| 371 | ete_id := rx_dia.end_to_end_id)); |
| 372 | setverdict(pass); |
| 373 | } |
| 374 | [] SWx.receive(PDU_DIAMETER:?) -> value rx_dia { |
| 375 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected Diameter msg rx: ", rx_dia)); |
| 376 | } |
| 377 | } |
| 378 | |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 379 | /* Send AAR as PGW to AAA server, expect back AAA */ |
| 380 | private function f_S6b_AA_success() runs on EPDG_ConnHdlr { |
| 381 | var PDU_DIAMETER rx_dia; |
| 382 | var UINT32 hbh_id := f_rnd_octstring(4); |
| 383 | var UINT32 ete_id := f_rnd_octstring(4); |
| 384 | |
| 385 | /* Unlike AAR, AAA contains no IMSI. Register ete_id in DIAMETER_Emulation, |
| 386 | * so AIA is forwarded back to us in DIAMETER port instead of MTC_CT.DIAMETER_UNIT. |
| 387 | */ |
| 388 | f_epdg_connhldr_S6b_expect_eteid(ete_id); |
| 389 | |
Pau Espin Pedrol | 2c2e187 | 2023-10-23 18:31:03 +0200 | [diff] [blame] | 390 | S6b.send(ts_DIA_S6b_AAR(g_pars.imsi, |
| 391 | int2oct(DIA_TS29_373_MIP6_Feature_Vector_GTPv2_SUPPORTED, 8), |
| 392 | g_pars.apn, hbh_id := hbh_id, ete_id := ete_id)); |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 393 | alt { |
| 394 | [] S6b.receive(tr_DIA_S6b_AAA) -> value rx_dia {} |
| 395 | [] S6b.receive(PDU_DIAMETER:?) -> value rx_dia { |
| 396 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected Diameter S6b msg rx: ", rx_dia)); |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 401 | /* Diameter SWx SAR + SAA. */ |
| 402 | private altstep as_GTP2C_CreateSession_success() runs on EPDG_ConnHdlr { |
| 403 | var PDU_GTPCv2 rx_msg; |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 404 | var BearerContextIEs rx_bctx_ies; |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 405 | var template (value) FullyQualifiedTEID fteid_c_ie, fteid_u_ie; |
| 406 | var template (value) PDN_AddressAllocation paa; |
Pau Espin Pedrol | 8c74649 | 2023-10-23 20:56:09 +0200 | [diff] [blame] | 407 | var template (value) BearerContextIEs bctx_ies; |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 408 | |
| 409 | [] GTP2.receive(tr_GTP2C_CreateSessionReq(g_pars.imsi)) -> value rx_msg { |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 410 | /* Parse TEIC and Bearer EBI and TEID and store it in g_pars */ |
| 411 | g_pars.teic_remote := rx_msg.gtpcv2_pdu.createSessionRequest.fullyQualifiedTEID[0].tEID_GRE_Key; |
| 412 | rx_bctx_ies := rx_msg.gtpcv2_pdu.createSessionRequest.bearerContextGrouped[0].bearerContextIEs; |
| 413 | g_pars.bearer.ebi := rx_bctx_ies.ePS_Bearer_ID.ePS_Bearer_ID_Value; |
| 414 | g_pars.bearer.teid_remote := rx_bctx_ies.fullyQualifiedTEID[0].tEID_GRE_Key; |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 415 | |
| 416 | /* allocate + register TEID-C on local side */ |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 417 | g_pars.teic_local := f_gtp2_allocate_teid(); |
| 418 | g_pars.bearer.teid_local := g_pars.teic_local; |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 419 | |
Pau Espin Pedrol | cdd4162 | 2023-10-23 14:38:20 +0200 | [diff] [blame] | 420 | /* Upon rx of CreateSession, emulate PGW asking the AAA server. */ |
| 421 | f_S6b_AA_success(); |
| 422 | |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 423 | fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S2b_ePDG_GTPC, g_pars.teic_local, 0, |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 424 | f_inet_addr(mp_s2b_local_ip), omit); |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 425 | fteid_u_ie := ts_GTP2C_FTEID(FTEID_IF_S2bU_ePDG_GTPU, g_pars.bearer.teid_local, 2, |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 426 | f_inet_addr(mp_s2b_local_ip), omit); |
| 427 | 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] | 428 | bctx_ies := ts_GTP2C_BcContextIE(ebi := g_pars.bearer.ebi, |
Pau Espin Pedrol | 8c74649 | 2023-10-23 20:56:09 +0200 | [diff] [blame] | 429 | teid_list := { fteid_u_ie }, |
| 430 | qos := ts_GTP2C_BearerQos('09'O, 0,0,0,0), |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 431 | charging_id := ts_GTP2C_ChargingID(g_pars.teic_local)); |
Pau Espin Pedrol | 8c74649 | 2023-10-23 20:56:09 +0200 | [diff] [blame] | 432 | GTP2.send(ts_GTP2C_CreateSessionResp({ fteid_c_ie }, paa, { ts_GTP2C_BcGrouped(bctx_ies) } )); |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 433 | setverdict(pass); |
| 434 | } |
| 435 | [] GTP2.receive(PDU_GTPCv2:?) -> value rx_msg { |
| 436 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GTP2C msg rx: ", rx_msg)); |
| 437 | } |
| 438 | } |
| 439 | private function f_GTP2C_CreateSession_success() runs on EPDG_ConnHdlr { |
| 440 | f_gtp2_register_udmsg('20'O); |
| 441 | as_GTP2C_CreateSession_success(); |
| 442 | } |
| 443 | |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 444 | /* Expect DeleteBearerResponse */ |
| 445 | private altstep as_GTP2C_DeleteBearer_success() runs on EPDG_ConnHdlr { |
| 446 | var PDU_GTPCv2 rx_msg; |
| 447 | var template (value) FullyQualifiedTEID fteid_c_ie, fteid_u_ie; |
| 448 | var template (value) PDN_AddressAllocation paa; |
| 449 | |
| 450 | [] GTP2.receive(tr_GTP2C_DeleteBearerResp(g_pars.teic_local)) -> value rx_msg { |
| 451 | setverdict(pass); |
| 452 | } |
| 453 | [] GTP2.receive(PDU_GTPCv2:?) -> value rx_msg { |
| 454 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GTP2C msg rx: ", rx_msg)); |
| 455 | } |
| 456 | } |
| 457 | private function f_GTP2C_DeleteBearer_success() runs on EPDG_ConnHdlr { |
| 458 | var integer proc_trans_id := 3; |
| 459 | GTP2.send(ts_GTP2C_DeleteBearerReq(g_pars.teic_remote, proc_trans_id, g_pars.bearer.ebi, Access_changed_from_Non_3GPP_to_3GPP)); |
| 460 | as_GTP2C_DeleteBearer_success(); |
| 461 | } |
| 462 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 463 | /* GSUP AuthInfo Req + Resp, triggers SWx MAR + MAA. */ |
| 464 | private function f_GSUP_AI_success() runs on EPDG_ConnHdlr { |
| 465 | var GSUP_PDU rx_gsup; |
| 466 | var template (present) GSUP_IE auth_tuple_ie := tr_GSUP_IE_AuthTuple3G(g_pars.vec.rand, |
| 467 | g_pars.vec.ik, |
| 468 | g_pars.vec.ck, |
| 469 | g_pars.vec.autn, |
| 470 | g_pars.vec.rand & g_pars.vec.auts); |
| 471 | |
| 472 | GSUP.send(ts_GSUP_SAI_REQ(g_pars.imsi)); |
| 473 | as_DIA_SWx_MA_success(); |
| 474 | /* Expect a positive response back to the translator; expect AIA */ |
| 475 | alt { |
| 476 | [] GSUP.receive(tr_GSUP_SAI_RES(g_pars.imsi, auth_tuple_ie)); |
| 477 | [] GSUP.receive(GSUP_PDU:?) -> value rx_gsup { |
| 478 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GSUP msg rx: ", rx_gsup)); |
| 479 | } |
| 480 | } |
| 481 | setverdict(pass); |
| 482 | } |
| 483 | |
| 484 | /* GSUP LU Req + Resp, triggers SWx SAR + SAA (Server Assignment). */ |
| 485 | private function f_GSUP_LU_success() runs on EPDG_ConnHdlr { |
| 486 | var GSUP_PDU rx_gsup; |
| 487 | var template octetstring destination_name := *; |
| 488 | GSUP.send(ts_GSUP_UL_REQ(g_pars.imsi)); |
| 489 | as_DIA_SWx_SA_success(); |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 490 | /* Expect a positive response back to the translator */ |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 491 | alt { |
| 492 | [] GSUP.receive(tr_GSUP_UL_RES(g_pars.imsi, destination_name)); |
| 493 | [] GSUP.receive(GSUP_PDU:?) -> value rx_gsup { |
| 494 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GSUP msg rx: ", rx_gsup)); |
| 495 | } |
| 496 | } |
| 497 | setverdict(pass); |
| 498 | } |
| 499 | |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 500 | /* GSUP TunnelEPDG Tunnel Req + Resp, triggers S2b CreateSession Req + Response. */ |
| 501 | private function f_GSUP_EPDGTunnel_success() runs on EPDG_ConnHdlr { |
| 502 | var GSUP_PDU rx_gsup; |
| 503 | GSUP.send(ts_GSUP_EPDGTunnel_REQ(g_pars.imsi)); |
| 504 | f_GTP2C_CreateSession_success(); |
| 505 | /* Expect a positive response back to the translator; */ |
| 506 | alt { |
| 507 | [] GSUP.receive(tr_GSUP_EPDGTunnel_RES(g_pars.imsi)); |
| 508 | [] GSUP.receive(GSUP_PDU:?) -> value rx_gsup { |
| 509 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected GSUP msg rx: ", rx_gsup)); |
| 510 | } |
| 511 | } |
| 512 | setverdict(pass); |
| 513 | } |
| 514 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 515 | private function f_TC_authinfo_normal(charstring id) runs on EPDG_ConnHdlr { |
| 516 | f_GSUP_AI_success(); |
| 517 | f_GSUP_LU_success(); |
Pau Espin Pedrol | d19fdf5 | 2023-10-19 16:58:24 +0200 | [diff] [blame] | 518 | f_GSUP_EPDGTunnel_success(); |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | testcase TC_authinfo_normal() runs on MTC_CT { |
| 522 | var EPDG_ConnHdlrPars pars := f_init_pars(); |
| 523 | var EPDG_ConnHdlr vc_conn; |
| 524 | f_init(); |
| 525 | vc_conn := f_start_handler(refers(f_TC_authinfo_normal), pars); |
| 526 | vc_conn.done; |
| 527 | setverdict(pass); |
| 528 | } |
| 529 | |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 530 | private function f_TC_ho_wifi_to_lte(charstring id) runs on EPDG_ConnHdlr { |
| 531 | f_TC_authinfo_normal(id); |
| 532 | /* Whenever UE goes back to 3GPP, PGW will notify ePDG with a Delete Bearer Request |
| 533 | * cause="Access changed from non-3gpp to 3gpp" */ |
| 534 | f_GTP2C_DeleteBearer_success(); |
| 535 | } |
| 536 | |
| 537 | testcase TC_ho_wifi_to_lte() runs on MTC_CT { |
| 538 | var EPDG_ConnHdlrPars pars := f_init_pars(); |
| 539 | var EPDG_ConnHdlr vc_conn; |
| 540 | f_init(); |
| 541 | vc_conn := f_start_handler(refers(f_TC_ho_wifi_to_lte), pars); |
| 542 | vc_conn.done; |
| 543 | setverdict(pass); |
| 544 | } |
| 545 | |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 546 | control { |
| 547 | execute ( TC_authinfo_normal() ); |
Pau Espin Pedrol | d4a2008 | 2023-10-23 19:59:24 +0200 | [diff] [blame] | 548 | execute ( TC_ho_wifi_to_lte() ); |
Pau Espin Pedrol | 965ac64 | 2023-10-16 18:12:45 +0200 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | } |