Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 1 | module PGW_Tests { |
| 2 | |
| 3 | import from General_Types all; |
| 4 | import from Osmocom_Types all; |
| 5 | import from Native_Functions all; |
| 6 | |
| 7 | import from GTPv2_Types all; |
| 8 | import from GTPv2_Templates all; |
| 9 | import from GTPv2_Emulation all; |
| 10 | |
| 11 | import from UECUPS_Types all; |
| 12 | |
| 13 | import from DNS_Helpers all; |
| 14 | |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 15 | |
| 16 | import from DIAMETER_Types all; |
| 17 | import from DIAMETER_Templates all; |
| 18 | import from DIAMETER_Emulation all; |
| 19 | |
| 20 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 21 | modulepar { |
Vadim Yanitskiy | 589972f | 2022-01-20 19:38:16 +0600 | [diff] [blame] | 22 | charstring mp_pgw_hostname := "127.0.0.4"; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 23 | charstring mp_local_hostname_c := "127.0.0.1"; |
| 24 | charstring mp_local_hostname_u := "127.0.0.1"; |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 25 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 26 | charstring mp_run_prog_as_user := "laforge"; |
| 27 | charstring mp_ping_hostname := "10.45.0.1"; |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 28 | |
Vadim Yanitskiy | 589972f | 2022-01-20 19:38:16 +0600 | [diff] [blame] | 29 | charstring mp_pcrf_local_ip := "127.0.0.9"; |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 30 | integer mp_pcrf_local_port := 3868; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | /* main component, we typically have one per testcase */ |
| 34 | type component PGW_Test_CT { |
| 35 | var GTPv2_Emulation_CT vc_GTP2; |
| 36 | port GTP2EM_PT TEID0; |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 37 | |
| 38 | /* emulated PCRF */ |
| 39 | var DIAMETER_Emulation_CT vc_DIAMETER; |
| 40 | port DIAMETER_PT DIAMETER_UNIT; |
| 41 | port DIAMETEREM_PROC_PT DIAMETER_PROC; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /* per-session component; we typically have 1..N per testcase */ |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 45 | type component PGW_Session_CT extends GTP2_ConnHdlr, DIAMETER_ConnHdlr { |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 46 | var SessionPars g_pars; |
| 47 | |
| 48 | /* TEI (Data) local side */ |
| 49 | var OCT4 g_teid; |
| 50 | /* TEI (Control) local side */ |
| 51 | var OCT4 g_teic; |
| 52 | /* TEI (Data) remote side */ |
| 53 | var OCT4 g_teid_remote; |
| 54 | /* TEI (Control) remote side */ |
| 55 | var OCT4 g_teic_remote; |
| 56 | /* GTP-U IPv4 address remote sie */ |
| 57 | var OCT4 g_gtpu4_remote; |
| 58 | var OCT16 g_gtpu6_remote; |
| 59 | |
| 60 | /* Address allocation */ |
| 61 | var OCT4 g_ip4_addr; |
| 62 | var OCT16 g_ip6_addr; |
| 63 | var integer g_ip6_plen; |
| 64 | } |
| 65 | |
| 66 | /* configuration data for a given Session */ |
| 67 | type record SessionPars { |
| 68 | hexstring imsi, |
| 69 | octetstring msisdn optional, |
| 70 | // serving network |
| 71 | integer rat_type, |
| 72 | // flags? |
| 73 | charstring apn, |
| 74 | /* Apn subscribed or non-subscribed */ |
| 75 | boolean selection_mode, |
| 76 | BIT3 pdn_type, |
| 77 | /* PAA */ |
| 78 | /* Max APN Restriction */ |
| 79 | /* APN-AMBR */ |
| 80 | octetstring pco optional, |
| 81 | octetstring epco optional, |
| 82 | /* Bearer Contexts to be created */ |
| 83 | |
| 84 | charstring tun_dev_name, |
| 85 | charstring tun_netns_name optional |
| 86 | } |
| 87 | |
| 88 | template (value) SessionPars |
| 89 | t_SessionPars(hexstring imsi, charstring tundev, integer rat_type := 6, charstring apn := "internet", |
| 90 | boolean selection_mode := false, BIT3 pdn_type := '001'B) := { |
| 91 | imsi := imsi, |
| 92 | msisdn := omit, |
| 93 | rat_type := rat_type, |
| 94 | apn := apn, |
| 95 | selection_mode := selection_mode, |
| 96 | pdn_type := pdn_type, |
| 97 | pco := omit, |
| 98 | epco := omit, |
| 99 | tun_dev_name := tundev, |
| 100 | tun_netns_name := tundev |
| 101 | } |
| 102 | |
| 103 | type record BearerConfig { |
| 104 | integer eps_bearer_id |
| 105 | } |
| 106 | |
| 107 | type function void_fn() runs on PGW_Session_CT; |
| 108 | |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 109 | friend function DiameterForwardUnitdataCallback(PDU_DIAMETER msg) |
| 110 | runs on DIAMETER_Emulation_CT return template PDU_DIAMETER { |
| 111 | DIAMETER_UNIT.send(msg); |
| 112 | return omit; |
| 113 | } |
| 114 | |
| 115 | friend function f_init_diameter(charstring id) runs on PGW_Test_CT { |
| 116 | var DIAMETEROps ops := { |
| 117 | create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback), |
Vadim Yanitskiy | b46f01e | 2021-12-06 03:23:13 +0300 | [diff] [blame] | 118 | unitdata_cb := refers(DiameterForwardUnitdataCallback), |
| 119 | raw := false /* handler mode (IMSI based routing) */ |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 120 | }; |
| 121 | var DIAMETER_conn_parameters pars := { |
| 122 | remote_ip := mp_pgw_hostname, |
| 123 | remote_sctp_port := -1, |
| 124 | local_ip := mp_pcrf_local_ip, |
| 125 | local_sctp_port := mp_pcrf_local_port, |
| 126 | origin_host := "pcrf.localdomain", |
| 127 | origin_realm := "localdomain", |
| 128 | vendor_app_id := c_DIAMETER_3GPP_Gx_AID |
| 129 | }; |
| 130 | vc_DIAMETER := DIAMETER_Emulation_CT.create(id); |
| 131 | map(vc_DIAMETER:DIAMETER, system:DIAMETER_CODEC_PT); |
| 132 | connect(vc_DIAMETER:DIAMETER_UNIT, self:DIAMETER_UNIT); |
| 133 | connect(vc_DIAMETER:DIAMETER_PROC, self:DIAMETER_PROC); |
| 134 | vc_DIAMETER.start(DIAMETER_Emulation.main(ops, pars, id)); |
| 135 | |
| 136 | f_diameter_wait_capability(DIAMETER_UNIT); |
| 137 | } |
| 138 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 139 | private function f_init() runs on PGW_Test_CT { |
| 140 | var Gtp2EmulationCfg cfg := { |
| 141 | gtpc_bind_ip := mp_local_hostname_c, |
| 142 | gtpc_bind_port := GTP2C_PORT, |
| 143 | gtpc_remote_ip := mp_pgw_hostname, |
| 144 | gtpc_remote_port := GTP2C_PORT, |
| 145 | sgw_role := true, |
| 146 | use_gtpu_daemon := true |
| 147 | }; |
| 148 | |
| 149 | vc_GTP2 := GTPv2_Emulation_CT.create("GTP2_EM"); |
| 150 | map(vc_GTP2:GTP2C, system:GTP2C); |
| 151 | connect(vc_GTP2:TEID0, self:TEID0); |
| 152 | vc_GTP2.start(GTPv2_Emulation.main(cfg)); |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 153 | |
| 154 | if (mp_pcrf_local_ip != "") { |
| 155 | f_init_diameter(testcasename()); |
| 156 | } |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | function f_start_handler(void_fn fn, template (omit) SessionPars pars := omit) |
| 160 | runs on PGW_Test_CT return PGW_Session_CT { |
| 161 | var charstring id := testcasename(); |
| 162 | var PGW_Session_CT vc_conn; |
| 163 | vc_conn := PGW_Session_CT.create(id); |
| 164 | connect(vc_conn:GTP2, vc_GTP2:CLIENT); |
| 165 | connect(vc_conn:GTP2_PROC, vc_GTP2:CLIENT_PROC); |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 166 | |
| 167 | if (isbound(vc_DIAMETER)) { |
| 168 | connect(vc_conn:DIAMETER, vc_DIAMETER:DIAMETER_CLIENT); |
| 169 | connect(vc_conn:DIAMETER_PROC, vc_DIAMETER:DIAMETER_PROC); |
| 170 | } |
| 171 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 172 | vc_conn.start(f_handler_init(fn, pars)); |
| 173 | return vc_conn; |
| 174 | } |
| 175 | |
| 176 | private function f_handler_init(void_fn fn, template (omit) SessionPars pars := omit) |
| 177 | runs on PGW_Session_CT { |
| 178 | if (isvalue(pars)) { |
| 179 | g_pars := valueof(pars); |
| 180 | } |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 181 | if (DIAMETER_PROC.checkstate("Connected")) { |
| 182 | f_diameter_expect(g_pars.imsi); |
| 183 | } |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 184 | fn.apply(); |
| 185 | } |
| 186 | |
Harald Welte | fe595e4 | 2020-04-21 22:56:47 +0200 | [diff] [blame] | 187 | private function f_concat_pad(integer tot_len, hexstring prefix, integer suffix) return hexstring { |
| 188 | var integer suffix_len := tot_len - lengthof(prefix); |
| 189 | var charstring suffix_ch := int2str(suffix); |
| 190 | var integer pad_len := suffix_len - lengthof(suffix_ch); |
| 191 | |
| 192 | return prefix & int2hex(0, pad_len) & str2hex(suffix_ch); |
| 193 | } |
| 194 | |
| 195 | function f_gen_imei(integer suffix) return hexstring { |
| 196 | return f_concat_pad(14, '49999'H, suffix); |
| 197 | } |
| 198 | |
| 199 | function f_gen_imsi(integer suffix) return hexstring { |
| 200 | return f_concat_pad(15, '26242'H, suffix); |
| 201 | } |
| 202 | |
| 203 | function f_gen_msisdn(integer suffix) return hexstring { |
| 204 | return f_concat_pad(12, '49123'H, suffix); |
| 205 | } |
| 206 | |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 207 | private altstep as_DIA_CCR(DCC_NONE_CC_Request_Type req_type) runs on PGW_Session_CT { |
| 208 | var PDU_DIAMETER rx_dia; |
| 209 | [] DIAMETER.receive(tr_DIA_CCR(req_type := req_type)) -> value rx_dia { |
| 210 | var template (omit) AVP avp; |
| 211 | var octetstring sess_id; |
| 212 | var AVP_Unsigned32 req_num; |
| 213 | |
| 214 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id); |
| 215 | sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id); |
| 216 | |
| 217 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number); |
| 218 | req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number); |
| 219 | |
| 220 | DIAMETER.send(ts_DIA_CCA(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id, |
| 221 | req_type, req_num)); |
| 222 | } |
| 223 | [] DIAMETER.receive(PDU_DIAMETER:?) -> value rx_dia { |
| 224 | setverdict(fail, "Received unexpected DIAMETER ", rx_dia); |
| 225 | self.stop; |
| 226 | } |
| 227 | } |
| 228 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 229 | |
| 230 | /* find TEID of given interface type (and optionally instance) */ |
| 231 | private function f_find_teid(FullyQualifiedTEID_List list, |
| 232 | template (present) integer if_type, |
| 233 | template (present) BIT4 instance := ?) |
| 234 | return template (omit) FullyQualifiedTEID |
| 235 | { |
| 236 | var integer i; |
| 237 | for (i := 0; i < lengthof(list); i := i+1) { |
| 238 | if (match(list[i].interfaceType, if_type) and |
| 239 | match(list[i].instance, instance)) { |
| 240 | return list[i]; |
| 241 | } |
| 242 | } |
| 243 | return omit; |
| 244 | } |
| 245 | |
| 246 | /* process one to-be-created bearer context */ |
| 247 | private function process_bctx_create(BearerContextGrouped bctx) runs on PGW_Session_CT |
| 248 | { |
| 249 | /* FIXME: EPS Bearer ID */ |
| 250 | /* FIXME: Cause */ |
| 251 | |
| 252 | /* find F-TEID of the P-GW U side */ |
| 253 | var FullyQualifiedTEID rx_fteid; |
| 254 | rx_fteid := valueof(f_find_teid(bctx.bearerContextIEs.fullyQualifiedTEID, 5, '0010'B)); |
| 255 | g_teid_remote := rx_fteid.tEID_GRE_Key; |
| 256 | if (rx_fteid.v4_Flag == '1'B) { |
| 257 | g_gtpu4_remote := rx_fteid.iPv4_Address; |
| 258 | } |
| 259 | if (rx_fteid.v6_Flag == '1'B) { |
| 260 | g_gtpu6_remote := rx_fteid.iPv6_Address; |
| 261 | } |
| 262 | |
| 263 | var UECUPS_CreateTun uecups_create := { |
| 264 | tx_teid := oct2int(g_teid_remote), |
| 265 | rx_teid := oct2int(g_teid), |
| 266 | user_addr_type := IPV4, |
| 267 | user_addr := '00000000'O, |
| 268 | local_gtp_ep := valueof(ts_UECUPS_SockAddr(f_inet_addr(mp_local_hostname_u))), |
| 269 | remote_gtp_ep := valueof(ts_UECUPS_SockAddr(g_gtpu4_remote)), |
| 270 | tun_dev_name := g_pars.tun_dev_name, |
| 271 | tun_netns_name := g_pars.tun_netns_name |
| 272 | }; |
| 273 | |
| 274 | /* create tunnel in daemon */ |
| 275 | if (isbound(g_ip4_addr)) { |
| 276 | uecups_create.user_addr := g_ip4_addr; |
| 277 | f_gtp2_create_tunnel(uecups_create); |
| 278 | } |
| 279 | if (isbound(g_ip6_addr)) { |
| 280 | uecups_create.user_addr_type := IPV6; |
| 281 | uecups_create.user_addr := g_ip6_addr; |
| 282 | f_gtp2_create_tunnel(uecups_create); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | /* create a session on the PGW */ |
| 287 | private function f_create_session() runs on PGW_Session_CT { |
| 288 | var PDU_GTPCv2 rx; |
| 289 | |
| 290 | /* allocate + register TEID-C on local side */ |
| 291 | g_teic := f_gtp2_allocate_teid(); |
| 292 | g_teid := g_teic; |
| 293 | |
| 294 | var template (value) FullyQualifiedTEID fteid_c_ie, fteid_u_ie; |
| 295 | fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_SGW_GTPC, g_teic, 0, |
| 296 | f_inet_addr(mp_local_hostname_c), omit); |
| 297 | fteid_u_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_SGW_GTPU, g_teid, 2, |
| 298 | f_inet_addr(mp_local_hostname_u), omit); |
| 299 | var template (value) PDU_GTPCv2 g2c := |
| 300 | ts_GTP2C_CreateSessionReq(imsi := g_pars.imsi, msisdn := omit, rat_type := 6, |
| 301 | sender_fteid := fteid_c_ie, |
| 302 | apn := f_enc_dns_hostname(g_pars.apn), |
| 303 | pdn_type := g_pars.pdn_type, teid_list := { fteid_u_ie }, |
| 304 | chg_car := '0000'O, bearer_id := 1); |
| 305 | /* open5gs up to 1.2.3 won't accept it without ULI, despite not mandatory */ |
| 306 | var template (value) TAI tai := { '0'H, '0'H, '1'H, 'F'H, '0'H, '1'H, '0001'O }; |
| 307 | var template (value) ECGI ecgi := { '0'H, '0'H, '1'H, 'F'H, '0'H, '1'H, '0'H, 23 }; |
| 308 | g2c.gtpcv2_pdu.createSessionRequest.userLocationInfo := ts_GTP2C_UserLocInfo(tai := tai, ecgi := ecgi); |
Vadim Yanitskiy | bada3c9 | 2022-01-20 18:59:07 +0600 | [diff] [blame] | 309 | g2c.gtpcv2_pdu.createSessionRequest.servingNetwork := ts_GTP2C_ServingNetwork('001'H, '01F'H); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 310 | |
| 311 | GTP2.send(g2c); |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 312 | if (DIAMETER_PROC.checkstate("Connected")) { |
| 313 | as_DIA_CCR(INITIAL_REQUEST); |
| 314 | } |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 315 | alt { |
| 316 | [] GTP2.receive(tr_GTP2C_CreateSessionResp(d_teid:=g_teic, cause:='10'O)) -> value rx { |
| 317 | /* extract TEIDs */ |
| 318 | var CreateSessionResponse resp := rx.gtpcv2_pdu.createSessionResponse; |
| 319 | g_teic_remote := resp.fullyQualifiedTEID[0].tEID_GRE_Key; |
| 320 | |
| 321 | /* extract allocated address[es] */ |
| 322 | var PDN_Address_and_Prefix paa := resp.pDN_AddressAllocation.pDN_Address_and_Prefix; |
| 323 | if (ischosen(paa.iPv4_Address)) { |
| 324 | g_ip4_addr := paa.iPv4_Address; |
| 325 | } else if (ischosen(paa.iPv6_Address)) { |
| 326 | g_ip6_addr := paa.iPv6_Address.iPv6_Address; |
| 327 | g_ip6_plen := paa.iPv6_Address.prefixLength; |
| 328 | } else if (ischosen(paa.iPv4_IPv6)) { |
| 329 | g_ip4_addr := paa.iPv4_IPv6.iPv4_Address; |
| 330 | g_ip6_addr := paa.iPv4_IPv6.iPv6_Address; |
| 331 | g_ip6_plen := paa.iPv4_IPv6.prefixLength; |
| 332 | } |
| 333 | var integer i; |
| 334 | for (i := 0; i < lengthof(resp.bearerContextGrouped); i := i+1) { |
| 335 | var BearerContextGrouped bctx := resp.bearerContextGrouped[i]; |
| 336 | select (bctx.instance) { |
| 337 | case ('0000'B) { // created |
| 338 | process_bctx_create(bctx); |
| 339 | } |
| 340 | case ('0001'B) { // removed |
| 341 | setverdict(fail, "We don't expect removed bearer contexts yet"); |
| 342 | } |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | [] GTP2.receive(tr_GTP2C_CreateSessionResp(d_teid:=g_teic, cause:=?)) -> value rx { |
| 347 | setverdict(fail, "Unexpected CreateSessionResp(cause=", |
| 348 | rx.gtpcv2_pdu.createSessionResponse.cause.causeValue, ")"); |
| 349 | } |
| 350 | [] GTP2.receive { |
| 351 | setverdict(fail, "Unexpected GTPv2 while waiting for CreateSessionResp"); |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | } |
| 356 | |
| 357 | /* delete the session from the PGW */ |
| 358 | private function f_delete_session(template (omit) OCT1 tx_cause := omit, |
| 359 | template (present) OCT4 exp_teid, |
| 360 | template (present) OCT1 exp_cause) runs on PGW_Session_CT { |
| 361 | var template (value) FullyQualifiedTEID fteid_c_ie |
| 362 | fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_SGW_GTPC, g_teic, 0, |
| 363 | f_inet_addr(mp_local_hostname_c), omit); |
| 364 | var template PDU_GTPCv2 g2c := |
| 365 | ts_GTP2C_DeleteSessionReq(d_teid := g_teic_remote, cause := tx_cause, |
| 366 | sender_fteid := fteid_c_ie, |
| 367 | teid_list := {}, bearer_id := 1); |
| 368 | |
| 369 | GTP2.send(g2c); |
Harald Welte | f400151 | 2020-04-26 21:48:34 +0200 | [diff] [blame] | 370 | if (DIAMETER_PROC.checkstate("Connected")) { |
| 371 | as_DIA_CCR(TERMINATION_REQUEST); |
| 372 | } |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 373 | alt { |
| 374 | [] GTP2.receive(tr_GTP2C_DeleteSessionResp(d_teid := exp_teid, cause := exp_cause)) { |
| 375 | setverdict(pass); |
| 376 | } |
| 377 | [] GTP2.receive(tr_GTP2C_DeleteSessionResp(?, ?)) { |
| 378 | setverdict(fail, "Unexpected DeleteSessionResp"); |
| 379 | } |
| 380 | [] GTP2.receive { |
| 381 | setverdict(fail, "Unexpected GTPv2 while waiting for DeleteSessionResp"); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | /* destroy tunnel in daemon */ |
| 386 | if (isbound(g_teid)) { |
| 387 | var UECUPS_DestroyTun uecups_destroy := { |
| 388 | local_gtp_ep := valueof(ts_UECUPS_SockAddr(f_inet_addr(mp_local_hostname_u))), |
| 389 | rx_teid := oct2int(g_teid) |
| 390 | }; |
| 391 | /* FIXME: what about IPv4/IPv6 differentiation? */ |
| 392 | f_gtp2_destroy_tunnel(uecups_destroy); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /* start a program on the user plane side; return its PID */ |
| 397 | private function f_start_prog(charstring command) runs on PGW_Session_CT return integer |
| 398 | { |
| 399 | var UECUPS_StartProgram sprog := { |
| 400 | command := command, |
| 401 | environment := {}, |
| 402 | run_as_user := mp_run_prog_as_user, |
| 403 | tun_netns_name := g_pars.tun_netns_name |
| 404 | }; |
Vadim Yanitskiy | 36ab797 | 2022-02-01 20:46:05 +0600 | [diff] [blame] | 405 | log("Starting a program: ", command); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 406 | var UECUPS_StartProgramRes res := f_gtp2_start_program(sprog); |
| 407 | if (res.result != OK) { |
| 408 | setverdict(fail, "Unable to start program '", command, "'"); |
| 409 | } |
| 410 | return res.pid; |
| 411 | } |
| 412 | |
| 413 | /* wait for termination of a given PID with specified exit_code */ |
| 414 | private function f_wait_term(integer pid, template (present) integer exit_code := 0, |
| 415 | float tout := 10.0) runs on PGW_Session_CT |
| 416 | { |
Vadim Yanitskiy | 36ab797 | 2022-02-01 20:46:05 +0600 | [diff] [blame] | 417 | var UECUPS_ProgramTermInd pti; |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 418 | timer T := tout; |
| 419 | |
| 420 | T.start; |
| 421 | alt { |
| 422 | [] GTP2.receive(UECUPS_ProgramTermInd:{pid := pid, exit_code := exit_code}) { |
| 423 | setverdict(pass); |
| 424 | } |
Vadim Yanitskiy | 36ab797 | 2022-02-01 20:46:05 +0600 | [diff] [blame] | 425 | [] GTP2.receive(UECUPS_ProgramTermInd:?) -> value pti { |
| 426 | setverdict(fail, "Received unexpected ProgramTermInd := ", pti); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 427 | } |
| 428 | [] T.timeout { |
| 429 | setverdict(fail, "timeout waiting for user-plane program termination"); |
| 430 | } |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | /* execute a program and wait for result */ |
| 435 | private function f_start_prog_wait(charstring command, template integer exit_code := 0, float tout := 10.0) runs on PGW_Session_CT |
| 436 | { |
| 437 | var integer pid := f_start_prog(command); |
| 438 | f_wait_term(pid, exit_code, tout); |
| 439 | } |
| 440 | |
| 441 | /* execute ping command and wait for result */ |
| 442 | private function f_ping4(charstring host, integer interval := 1, integer count := 10) runs on PGW_Session_CT |
| 443 | { |
| 444 | var charstring ping :="ping -c " & int2str(count) & " -i " & int2str(interval); |
| 445 | ping := ping & " -I " & f_inet_ntoa(g_ip4_addr); |
| 446 | ping := ping & " " & host; |
Harald Welte | 8cfdc7c | 2020-04-21 22:48:34 +0200 | [diff] [blame] | 447 | f_start_prog_wait(ping, tout := int2float(5 + interval*count)); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | |
| 451 | |
| 452 | |
| 453 | /* send echo request; expect response */ |
| 454 | testcase TC_tx_echo() runs on PGW_Test_CT { |
| 455 | timer T := 5.0; |
| 456 | |
| 457 | f_init(); |
| 458 | |
| 459 | TEID0.send(ts_GTP2C_EchoReq(0)); |
| 460 | T.start; |
| 461 | alt { |
| 462 | [] TEID0.receive(tr_GTP2C_EchoResp) { |
| 463 | setverdict(pass); |
| 464 | } |
| 465 | [] T.timeout { |
| 466 | setverdict(fail, "timeout waiting for Echo Response"); |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | /* create a session, expect it to succeed */ |
| 472 | private function f_TC_createSession() runs on PGW_Session_CT { |
| 473 | f_create_session(); |
| 474 | setverdict(pass); |
| 475 | } |
| 476 | testcase TC_createSession() runs on PGW_Test_CT { |
| 477 | var PGW_Session_CT vc_conn; |
| 478 | var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun22")); |
| 479 | f_init(); |
| 480 | vc_conn := f_start_handler(refers(f_TC_createSession), pars); |
| 481 | vc_conn.done; |
| 482 | } |
| 483 | |
| 484 | /* create a session, then execute a ping command on the user plane */ |
| 485 | private function f_TC_createSession_ping4() runs on PGW_Session_CT { |
| 486 | f_create_session(); |
| 487 | f_ping4(mp_ping_hostname); |
| 488 | setverdict(pass); |
| 489 | } |
| 490 | testcase TC_createSession_ping4() runs on PGW_Test_CT { |
| 491 | var PGW_Session_CT vc_conn; |
| 492 | var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23")); |
| 493 | f_init(); |
| 494 | vc_conn := f_start_handler(refers(f_TC_createSession_ping4), pars); |
| 495 | vc_conn.done; |
| 496 | } |
Harald Welte | fe595e4 | 2020-04-21 22:56:47 +0200 | [diff] [blame] | 497 | testcase TC_createSession_ping4_256() runs on PGW_Test_CT { |
| 498 | var PGW_Session_CT vc_conn[256]; |
| 499 | var integer i; |
| 500 | |
| 501 | f_init(); |
| 502 | |
| 503 | for (i := 0; i < sizeof(vc_conn); i:=i+1) { |
| 504 | var charstring tundev := "ping" & int2str(i); |
| 505 | var SessionPars pars := valueof(t_SessionPars(f_gen_imsi(i), tundev)); |
| 506 | vc_conn[i] := f_start_handler(refers(f_TC_createSession_ping4), pars); |
| 507 | } |
| 508 | |
| 509 | for (i := 0; i < lengthof(vc_conn); i:=i+1) { |
| 510 | vc_conn[i].done; |
| 511 | } |
| 512 | } |
| 513 | |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 514 | |
| 515 | /* create a session, then delete it again */ |
| 516 | private function f_TC_createSession_deleteSession() runs on PGW_Session_CT { |
| 517 | f_create_session(); |
| 518 | f_delete_session(omit, g_teic, '10'O); |
| 519 | setverdict(pass); |
| 520 | } |
| 521 | testcase TC_createSession_deleteSession() runs on PGW_Test_CT { |
| 522 | var PGW_Session_CT vc_conn; |
| 523 | var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23")); |
| 524 | f_init(); |
| 525 | vc_conn := f_start_handler(refers(f_TC_createSession_deleteSession), pars); |
| 526 | vc_conn.done; |
| 527 | } |
| 528 | |
| 529 | /* send a DeleteSessionReq for an unknown/invalid TEID */ |
| 530 | private function f_TC_deleteSession_unknown() runs on PGW_Session_CT { |
| 531 | g_teic := f_gtp2_allocate_teid(); |
| 532 | g_teic_remote := f_rnd_octstring(4); |
| 533 | f_delete_session(omit, '00000000'O, '40'O /* Context Unknown */); |
| 534 | setverdict(pass); |
| 535 | } |
| 536 | testcase TC_deleteSession_unknown() runs on PGW_Test_CT { |
| 537 | var PGW_Session_CT vc_conn; |
| 538 | var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23")); |
| 539 | f_init(); |
| 540 | vc_conn := f_start_handler(refers(f_TC_deleteSession_unknown), pars); |
| 541 | vc_conn.done; |
| 542 | } |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | control { |
| 548 | execute( TC_tx_echo() ); |
| 549 | execute( TC_createSession() ); |
| 550 | execute( TC_createSession_ping4() ); |
Harald Welte | fe595e4 | 2020-04-21 22:56:47 +0200 | [diff] [blame] | 551 | execute( TC_createSession_ping4_256() ); |
Harald Welte | 4526da9 | 2020-03-05 23:08:10 +0100 | [diff] [blame] | 552 | execute( TC_createSession_deleteSession() ); |
| 553 | execute( TC_deleteSession_unknown() ); |
| 554 | } |
| 555 | |
| 556 | |
| 557 | } |