blob: 16bea5743c7cadd52a02e45c6fc2eb7a7b3a0e16 [file] [log] [blame]
Harald Welte4526da92020-03-05 23:08:10 +01001module PGW_Tests {
2
3import from General_Types all;
4import from Osmocom_Types all;
5import from Native_Functions all;
6
7import from GTPv2_Types all;
8import from GTPv2_Templates all;
9import from GTPv2_Emulation all;
10
11import from UECUPS_Types all;
12
13import from DNS_Helpers all;
14
Harald Weltef4001512020-04-26 21:48:34 +020015
16import from DIAMETER_Types all;
17import from DIAMETER_Templates all;
18import from DIAMETER_Emulation all;
19
20
Harald Welte4526da92020-03-05 23:08:10 +010021modulepar {
Vadim Yanitskiy589972f2022-01-20 19:38:16 +060022 charstring mp_pgw_hostname := "127.0.0.4";
Harald Welte4526da92020-03-05 23:08:10 +010023 charstring mp_local_hostname_c := "127.0.0.1";
24 charstring mp_local_hostname_u := "127.0.0.1";
Harald Weltef4001512020-04-26 21:48:34 +020025
Vadim Yanitskiy284c68e2022-02-02 22:30:37 +060026 charstring mp_run_prog_log_path := "/tmp";
Harald Welte4526da92020-03-05 23:08:10 +010027 charstring mp_run_prog_as_user := "laforge";
28 charstring mp_ping_hostname := "10.45.0.1";
Harald Weltef4001512020-04-26 21:48:34 +020029
Vadim Yanitskiy589972f2022-01-20 19:38:16 +060030 charstring mp_pcrf_local_ip := "127.0.0.9";
Harald Weltef4001512020-04-26 21:48:34 +020031 integer mp_pcrf_local_port := 3868;
Harald Welte4526da92020-03-05 23:08:10 +010032}
33
34/* main component, we typically have one per testcase */
35type component PGW_Test_CT {
36 var GTPv2_Emulation_CT vc_GTP2;
37 port GTP2EM_PT TEID0;
Harald Weltef4001512020-04-26 21:48:34 +020038
39 /* emulated PCRF */
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +020040 var DIAMETER_Emulation_CT vc_Gx;
41 port DIAMETER_PT Gx_UNIT;
42 port DIAMETEREM_PROC_PT Gx_PROC;
Pau Espin Pedrol08880f12022-04-07 19:05:15 +020043 /* global test case guard timer (actual timeout value is set in f_init()) */
44 timer T_guard;
45}
46
47/* global altstep for global guard timer; */
48altstep as_Tguard() runs on PGW_Test_CT {
49 [] T_guard.timeout {
50 setverdict(fail, "Timeout of T_guard");
51 mtc.stop;
52 }
Harald Welte4526da92020-03-05 23:08:10 +010053}
54
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +020055type component DIAMETER_ConnHdlr_CT extends DIAMETER_ConnHdlr {
56 port DIAMETER_Conn_PT DIAMETER_CLIENT;
57}
58
59function f_diam_connhldr_ct_main(hexstring imsi) runs on DIAMETER_ConnHdlr_CT {
60 var PDU_DIAMETER msg;
61
62 if (DIAMETER_PROC.checkstate("Connected")) {
63 f_diameter_expect(imsi);
64 }
65
66 while (true) {
67 alt {
68 [] DIAMETER_CLIENT.receive(PDU_DIAMETER:?) -> value msg {
69 DIAMETER.send(msg);
70 }
71 [] DIAMETER.receive(PDU_DIAMETER:?) -> value msg {
72 DIAMETER_CLIENT.send(msg);
73 }
74 }
75 }
76}
77
78
Harald Welte4526da92020-03-05 23:08:10 +010079/* per-session component; we typically have 1..N per testcase */
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +020080type component PGW_Session_CT extends GTP2_ConnHdlr {
Harald Welte4526da92020-03-05 23:08:10 +010081 var SessionPars g_pars;
82
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +020083 port DIAMETER_Conn_PT Gx;
84
Harald Welte4526da92020-03-05 23:08:10 +010085 /* TEI (Data) local side */
86 var OCT4 g_teid;
87 /* TEI (Control) local side */
88 var OCT4 g_teic;
89 /* TEI (Data) remote side */
90 var OCT4 g_teid_remote;
91 /* TEI (Control) remote side */
92 var OCT4 g_teic_remote;
93 /* GTP-U IPv4 address remote sie */
94 var OCT4 g_gtpu4_remote;
95 var OCT16 g_gtpu6_remote;
96
97 /* Address allocation */
98 var OCT4 g_ip4_addr;
99 var OCT16 g_ip6_addr;
100 var integer g_ip6_plen;
101}
102
103/* configuration data for a given Session */
104type record SessionPars {
105 hexstring imsi,
106 octetstring msisdn optional,
107 // serving network
108 integer rat_type,
109 // flags?
110 charstring apn,
111 /* Apn subscribed or non-subscribed */
112 boolean selection_mode,
113 BIT3 pdn_type,
114 /* PAA */
115 /* Max APN Restriction */
116 /* APN-AMBR */
117 octetstring pco optional,
118 octetstring epco optional,
119 /* Bearer Contexts to be created */
120
121 charstring tun_dev_name,
122 charstring tun_netns_name optional
123}
124
125template (value) SessionPars
126t_SessionPars(hexstring imsi, charstring tundev, integer rat_type := 6, charstring apn := "internet",
127 boolean selection_mode := false, BIT3 pdn_type := '001'B) := {
128 imsi := imsi,
129 msisdn := omit,
130 rat_type := rat_type,
131 apn := apn,
132 selection_mode := selection_mode,
133 pdn_type := pdn_type,
134 pco := omit,
135 epco := omit,
136 tun_dev_name := tundev,
137 tun_netns_name := tundev
138}
139
140type record BearerConfig {
141 integer eps_bearer_id
142}
143
144type function void_fn() runs on PGW_Session_CT;
145
Harald Weltef4001512020-04-26 21:48:34 +0200146friend function DiameterForwardUnitdataCallback(PDU_DIAMETER msg)
147runs on DIAMETER_Emulation_CT return template PDU_DIAMETER {
148 DIAMETER_UNIT.send(msg);
149 return omit;
150}
151
152friend function f_init_diameter(charstring id) runs on PGW_Test_CT {
153 var DIAMETEROps ops := {
154 create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback),
Vadim Yanitskiyb46f01e2021-12-06 03:23:13 +0300155 unitdata_cb := refers(DiameterForwardUnitdataCallback),
156 raw := false /* handler mode (IMSI based routing) */
Harald Weltef4001512020-04-26 21:48:34 +0200157 };
158 var DIAMETER_conn_parameters pars := {
159 remote_ip := mp_pgw_hostname,
160 remote_sctp_port := -1,
161 local_ip := mp_pcrf_local_ip,
162 local_sctp_port := mp_pcrf_local_port,
163 origin_host := "pcrf.localdomain",
164 origin_realm := "localdomain",
Pau Espin Pedrol33b47492022-03-08 17:43:01 +0100165 auth_app_id := omit,
Harald Weltef4001512020-04-26 21:48:34 +0200166 vendor_app_id := c_DIAMETER_3GPP_Gx_AID
167 };
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200168 vc_Gx := DIAMETER_Emulation_CT.create(id);
169 map(vc_Gx:DIAMETER, system:DIAMETER_CODEC_PT);
170 connect(vc_Gx:DIAMETER_UNIT, self:Gx_UNIT);
171 connect(vc_Gx:DIAMETER_PROC, self:Gx_PROC);
172 vc_Gx.start(DIAMETER_Emulation.main(ops, pars, id));
Harald Weltef4001512020-04-26 21:48:34 +0200173
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200174 f_diameter_wait_capability(Gx_UNIT);
Pau Espin Pedrolbb5f45f2022-04-11 12:36:55 +0200175 /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdong ping-pongs):
176 * RFC6733 sec 5.1
177 * RFC3539 sec 3.4.1 [5]
178 * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49
179 */
180 f_sleep(1.0);
Harald Weltef4001512020-04-26 21:48:34 +0200181}
182
Pau Espin Pedrol08880f12022-04-07 19:05:15 +0200183private function f_init(float guard_timeout := 60.0) runs on PGW_Test_CT {
184 T_guard.start(guard_timeout);
185 activate(as_Tguard());
186
Harald Welte4526da92020-03-05 23:08:10 +0100187 var Gtp2EmulationCfg cfg := {
188 gtpc_bind_ip := mp_local_hostname_c,
189 gtpc_bind_port := GTP2C_PORT,
190 gtpc_remote_ip := mp_pgw_hostname,
191 gtpc_remote_port := GTP2C_PORT,
192 sgw_role := true,
193 use_gtpu_daemon := true
194 };
195
196 vc_GTP2 := GTPv2_Emulation_CT.create("GTP2_EM");
197 map(vc_GTP2:GTP2C, system:GTP2C);
198 connect(vc_GTP2:TEID0, self:TEID0);
199 vc_GTP2.start(GTPv2_Emulation.main(cfg));
Harald Weltef4001512020-04-26 21:48:34 +0200200
201 if (mp_pcrf_local_ip != "") {
202 f_init_diameter(testcasename());
203 }
Harald Welte4526da92020-03-05 23:08:10 +0100204}
205
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200206function f_start_handler(void_fn fn, template (omit) SessionPars pars_tmpl := omit)
Harald Welte4526da92020-03-05 23:08:10 +0100207runs on PGW_Test_CT return PGW_Session_CT {
208 var charstring id := testcasename();
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200209 var DIAMETER_ConnHdlr_CT vc_conn_gx;
Harald Welte4526da92020-03-05 23:08:10 +0100210 var PGW_Session_CT vc_conn;
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200211 var SessionPars pars;
212
213 if (isvalue(pars_tmpl)) {
214 pars := valueof(pars_tmpl);
215 } else {
216 /*TODO: set default values */
217 }
218
Harald Welte4526da92020-03-05 23:08:10 +0100219 vc_conn := PGW_Session_CT.create(id);
220 connect(vc_conn:GTP2, vc_GTP2:CLIENT);
221 connect(vc_conn:GTP2_PROC, vc_GTP2:CLIENT_PROC);
Harald Weltef4001512020-04-26 21:48:34 +0200222
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200223 if (isbound(vc_Gx)) {
224 vc_conn_gx := DIAMETER_ConnHdlr_CT.create(id);
225 connect(vc_conn_gx:DIAMETER, vc_Gx:DIAMETER_CLIENT);
226 connect(vc_conn_gx:DIAMETER_PROC, vc_Gx:DIAMETER_PROC);
227 connect(vc_conn:Gx, vc_conn_gx:DIAMETER_CLIENT);
228 vc_conn_gx.start(f_diam_connhldr_ct_main(pars.imsi));
Harald Weltef4001512020-04-26 21:48:34 +0200229 }
230
Harald Welte4526da92020-03-05 23:08:10 +0100231 vc_conn.start(f_handler_init(fn, pars));
232 return vc_conn;
233}
234
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200235private function f_handler_init(void_fn fn, SessionPars pars)
Harald Welte4526da92020-03-05 23:08:10 +0100236runs on PGW_Session_CT {
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200237 g_pars := valueof(pars);
Harald Welte4526da92020-03-05 23:08:10 +0100238 fn.apply();
239}
240
Harald Weltefe595e42020-04-21 22:56:47 +0200241private function f_concat_pad(integer tot_len, hexstring prefix, integer suffix) return hexstring {
242 var integer suffix_len := tot_len - lengthof(prefix);
243 var charstring suffix_ch := int2str(suffix);
244 var integer pad_len := suffix_len - lengthof(suffix_ch);
245
246 return prefix & int2hex(0, pad_len) & str2hex(suffix_ch);
247}
248
249function f_gen_imei(integer suffix) return hexstring {
250 return f_concat_pad(14, '49999'H, suffix);
251}
252
253function f_gen_imsi(integer suffix) return hexstring {
254 return f_concat_pad(15, '26242'H, suffix);
255}
256
257function f_gen_msisdn(integer suffix) return hexstring {
258 return f_concat_pad(12, '49123'H, suffix);
259}
260
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200261private altstep as_DIA_Gx_CCR(DCC_NONE_CC_Request_Type req_type) runs on PGW_Session_CT {
Harald Weltef4001512020-04-26 21:48:34 +0200262 var PDU_DIAMETER rx_dia;
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200263 [] Gx.receive(tr_DIA_Gx_CCR(req_type := req_type)) -> value rx_dia {
Harald Weltef4001512020-04-26 21:48:34 +0200264 var template (omit) AVP avp;
265 var octetstring sess_id;
266 var AVP_Unsigned32 req_num;
267
268 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
269 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
270
271 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
272 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
273
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200274 Gx.send(ts_DIA_Gx_CCA(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id,
Harald Weltef4001512020-04-26 21:48:34 +0200275 req_type, req_num));
276 }
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200277 [] Gx.receive(PDU_DIAMETER:?) -> value rx_dia {
Harald Weltef4001512020-04-26 21:48:34 +0200278 setverdict(fail, "Received unexpected DIAMETER ", rx_dia);
279 self.stop;
280 }
281}
282
Harald Welte4526da92020-03-05 23:08:10 +0100283
284/* find TEID of given interface type (and optionally instance) */
285private function f_find_teid(FullyQualifiedTEID_List list,
286 template (present) integer if_type,
287 template (present) BIT4 instance := ?)
288return template (omit) FullyQualifiedTEID
289{
290 var integer i;
291 for (i := 0; i < lengthof(list); i := i+1) {
292 if (match(list[i].interfaceType, if_type) and
293 match(list[i].instance, instance)) {
294 return list[i];
295 }
296 }
297 return omit;
298}
299
300/* process one to-be-created bearer context */
301private function process_bctx_create(BearerContextGrouped bctx) runs on PGW_Session_CT
302{
303 /* FIXME: EPS Bearer ID */
304 /* FIXME: Cause */
305
306 /* find F-TEID of the P-GW U side */
307 var FullyQualifiedTEID rx_fteid;
308 rx_fteid := valueof(f_find_teid(bctx.bearerContextIEs.fullyQualifiedTEID, 5, '0010'B));
309 g_teid_remote := rx_fteid.tEID_GRE_Key;
310 if (rx_fteid.v4_Flag == '1'B) {
311 g_gtpu4_remote := rx_fteid.iPv4_Address;
312 }
313 if (rx_fteid.v6_Flag == '1'B) {
314 g_gtpu6_remote := rx_fteid.iPv6_Address;
315 }
316
317 var UECUPS_CreateTun uecups_create := {
318 tx_teid := oct2int(g_teid_remote),
319 rx_teid := oct2int(g_teid),
320 user_addr_type := IPV4,
321 user_addr := '00000000'O,
322 local_gtp_ep := valueof(ts_UECUPS_SockAddr(f_inet_addr(mp_local_hostname_u))),
323 remote_gtp_ep := valueof(ts_UECUPS_SockAddr(g_gtpu4_remote)),
324 tun_dev_name := g_pars.tun_dev_name,
325 tun_netns_name := g_pars.tun_netns_name
326 };
327
328 /* create tunnel in daemon */
329 if (isbound(g_ip4_addr)) {
330 uecups_create.user_addr := g_ip4_addr;
331 f_gtp2_create_tunnel(uecups_create);
332 }
333 if (isbound(g_ip6_addr)) {
334 uecups_create.user_addr_type := IPV6;
335 uecups_create.user_addr := g_ip6_addr;
336 f_gtp2_create_tunnel(uecups_create);
337 }
338}
339
340/* create a session on the PGW */
341private function f_create_session() runs on PGW_Session_CT {
342 var PDU_GTPCv2 rx;
343
344 /* allocate + register TEID-C on local side */
345 g_teic := f_gtp2_allocate_teid();
346 g_teid := g_teic;
347
348 var template (value) FullyQualifiedTEID fteid_c_ie, fteid_u_ie;
349 fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_SGW_GTPC, g_teic, 0,
350 f_inet_addr(mp_local_hostname_c), omit);
351 fteid_u_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_SGW_GTPU, g_teid, 2,
352 f_inet_addr(mp_local_hostname_u), omit);
353 var template (value) PDU_GTPCv2 g2c :=
354 ts_GTP2C_CreateSessionReq(imsi := g_pars.imsi, msisdn := omit, rat_type := 6,
355 sender_fteid := fteid_c_ie,
356 apn := f_enc_dns_hostname(g_pars.apn),
357 pdn_type := g_pars.pdn_type, teid_list := { fteid_u_ie },
358 chg_car := '0000'O, bearer_id := 1);
359 /* open5gs up to 1.2.3 won't accept it without ULI, despite not mandatory */
360 var template (value) TAI tai := { '0'H, '0'H, '1'H, 'F'H, '0'H, '1'H, '0001'O };
361 var template (value) ECGI ecgi := { '0'H, '0'H, '1'H, 'F'H, '0'H, '1'H, '0'H, 23 };
362 g2c.gtpcv2_pdu.createSessionRequest.userLocationInfo := ts_GTP2C_UserLocInfo(tai := tai, ecgi := ecgi);
Vadim Yanitskiybada3c92022-01-20 18:59:07 +0600363 g2c.gtpcv2_pdu.createSessionRequest.servingNetwork := ts_GTP2C_ServingNetwork('001'H, '01F'H);
Harald Welte4526da92020-03-05 23:08:10 +0100364
365 GTP2.send(g2c);
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200366 if (Gx.checkstate("Connected")) {
367 as_DIA_Gx_CCR(INITIAL_REQUEST);
Harald Weltef4001512020-04-26 21:48:34 +0200368 }
Harald Welte4526da92020-03-05 23:08:10 +0100369 alt {
370 [] GTP2.receive(tr_GTP2C_CreateSessionResp(d_teid:=g_teic, cause:='10'O)) -> value rx {
371 /* extract TEIDs */
372 var CreateSessionResponse resp := rx.gtpcv2_pdu.createSessionResponse;
373 g_teic_remote := resp.fullyQualifiedTEID[0].tEID_GRE_Key;
374
375 /* extract allocated address[es] */
376 var PDN_Address_and_Prefix paa := resp.pDN_AddressAllocation.pDN_Address_and_Prefix;
377 if (ischosen(paa.iPv4_Address)) {
378 g_ip4_addr := paa.iPv4_Address;
379 } else if (ischosen(paa.iPv6_Address)) {
380 g_ip6_addr := paa.iPv6_Address.iPv6_Address;
381 g_ip6_plen := paa.iPv6_Address.prefixLength;
382 } else if (ischosen(paa.iPv4_IPv6)) {
383 g_ip4_addr := paa.iPv4_IPv6.iPv4_Address;
384 g_ip6_addr := paa.iPv4_IPv6.iPv6_Address;
385 g_ip6_plen := paa.iPv4_IPv6.prefixLength;
386 }
387 var integer i;
388 for (i := 0; i < lengthof(resp.bearerContextGrouped); i := i+1) {
389 var BearerContextGrouped bctx := resp.bearerContextGrouped[i];
390 select (bctx.instance) {
391 case ('0000'B) { // created
392 process_bctx_create(bctx);
393 }
394 case ('0001'B) { // removed
395 setverdict(fail, "We don't expect removed bearer contexts yet");
396 }
397 }
398 }
399 }
400 [] GTP2.receive(tr_GTP2C_CreateSessionResp(d_teid:=g_teic, cause:=?)) -> value rx {
401 setverdict(fail, "Unexpected CreateSessionResp(cause=",
402 rx.gtpcv2_pdu.createSessionResponse.cause.causeValue, ")");
403 }
404 [] GTP2.receive {
405 setverdict(fail, "Unexpected GTPv2 while waiting for CreateSessionResp");
406 }
407 }
408
409}
410
411/* delete the session from the PGW */
412private function f_delete_session(template (omit) OCT1 tx_cause := omit,
413 template (present) OCT4 exp_teid,
Pau Espin Pedrol5b0327b2022-04-11 13:02:36 +0200414 template (present) OCT1 exp_cause,
415 boolean expect_diameter := true) runs on PGW_Session_CT {
Harald Welte4526da92020-03-05 23:08:10 +0100416 var template (value) FullyQualifiedTEID fteid_c_ie
417 fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_SGW_GTPC, g_teic, 0,
418 f_inet_addr(mp_local_hostname_c), omit);
419 var template PDU_GTPCv2 g2c :=
420 ts_GTP2C_DeleteSessionReq(d_teid := g_teic_remote, cause := tx_cause,
421 sender_fteid := fteid_c_ie,
422 teid_list := {}, bearer_id := 1);
423
424 GTP2.send(g2c);
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200425 if (Gx.checkstate("Connected") and expect_diameter) {
426 as_DIA_Gx_CCR(TERMINATION_REQUEST);
Harald Weltef4001512020-04-26 21:48:34 +0200427 }
Harald Welte4526da92020-03-05 23:08:10 +0100428 alt {
429 [] GTP2.receive(tr_GTP2C_DeleteSessionResp(d_teid := exp_teid, cause := exp_cause)) {
430 setverdict(pass);
431 }
432 [] GTP2.receive(tr_GTP2C_DeleteSessionResp(?, ?)) {
433 setverdict(fail, "Unexpected DeleteSessionResp");
434 }
435 [] GTP2.receive {
436 setverdict(fail, "Unexpected GTPv2 while waiting for DeleteSessionResp");
437 }
438 }
439
440 /* destroy tunnel in daemon */
441 if (isbound(g_teid)) {
442 var UECUPS_DestroyTun uecups_destroy := {
443 local_gtp_ep := valueof(ts_UECUPS_SockAddr(f_inet_addr(mp_local_hostname_u))),
444 rx_teid := oct2int(g_teid)
445 };
446 /* FIXME: what about IPv4/IPv6 differentiation? */
447 f_gtp2_destroy_tunnel(uecups_destroy);
448 }
449}
450
451/* start a program on the user plane side; return its PID */
Vadim Yanitskiy284c68e2022-02-02 22:30:37 +0600452private function f_start_prog(charstring command, boolean redirect_output := true)
453runs on PGW_Session_CT return integer
Harald Welte4526da92020-03-05 23:08:10 +0100454{
455 var UECUPS_StartProgram sprog := {
456 command := command,
457 environment := {},
458 run_as_user := mp_run_prog_as_user,
459 tun_netns_name := g_pars.tun_netns_name
460 };
Vadim Yanitskiy284c68e2022-02-02 22:30:37 +0600461
462 /* Redirect stdout/stderr to the user-specified location */
463 if (redirect_output) {
464 var charstring prefix := mp_run_prog_log_path & "/" & testcasename();
465 sprog.command := sprog.command & " 1>>" & prefix & ".prog.stdout";
466 sprog.command := sprog.command & " 2>>" & prefix & ".prog.stderr";
467 }
468
Vadim Yanitskiy36ab7972022-02-01 20:46:05 +0600469 log("Starting a program: ", command);
Harald Welte4526da92020-03-05 23:08:10 +0100470 var UECUPS_StartProgramRes res := f_gtp2_start_program(sprog);
471 if (res.result != OK) {
472 setverdict(fail, "Unable to start program '", command, "'");
473 }
474 return res.pid;
475}
476
477/* wait for termination of a given PID with specified exit_code */
478private function f_wait_term(integer pid, template (present) integer exit_code := 0,
479 float tout := 10.0) runs on PGW_Session_CT
480{
Vadim Yanitskiy36ab7972022-02-01 20:46:05 +0600481 var UECUPS_ProgramTermInd pti;
Harald Welte4526da92020-03-05 23:08:10 +0100482 timer T := tout;
483
484 T.start;
485 alt {
486 [] GTP2.receive(UECUPS_ProgramTermInd:{pid := pid, exit_code := exit_code}) {
487 setverdict(pass);
488 }
Vadim Yanitskiy36ab7972022-02-01 20:46:05 +0600489 [] GTP2.receive(UECUPS_ProgramTermInd:?) -> value pti {
490 setverdict(fail, "Received unexpected ProgramTermInd := ", pti);
Harald Welte4526da92020-03-05 23:08:10 +0100491 }
492 [] T.timeout {
493 setverdict(fail, "timeout waiting for user-plane program termination");
494 }
495 }
496}
497
498/* execute a program and wait for result */
Vadim Yanitskiy284c68e2022-02-02 22:30:37 +0600499private function f_start_prog_wait(charstring command,
500 template integer exit_code := 0,
501 float tout := 10.0,
502 boolean redirect_output := true)
503runs on PGW_Session_CT
Harald Welte4526da92020-03-05 23:08:10 +0100504{
Vadim Yanitskiy284c68e2022-02-02 22:30:37 +0600505 var integer pid := f_start_prog(command, redirect_output);
Harald Welte4526da92020-03-05 23:08:10 +0100506 f_wait_term(pid, exit_code, tout);
507}
508
509/* execute ping command and wait for result */
510private function f_ping4(charstring host, integer interval := 1, integer count := 10) runs on PGW_Session_CT
511{
512 var charstring ping :="ping -c " & int2str(count) & " -i " & int2str(interval);
513 ping := ping & " -I " & f_inet_ntoa(g_ip4_addr);
514 ping := ping & " " & host;
Harald Welte8cfdc7c2020-04-21 22:48:34 +0200515 f_start_prog_wait(ping, tout := int2float(5 + interval*count));
Harald Welte4526da92020-03-05 23:08:10 +0100516}
517
518
519
520
521/* send echo request; expect response */
522testcase TC_tx_echo() runs on PGW_Test_CT {
523 timer T := 5.0;
524
525 f_init();
526
527 TEID0.send(ts_GTP2C_EchoReq(0));
528 T.start;
529 alt {
530 [] TEID0.receive(tr_GTP2C_EchoResp) {
531 setverdict(pass);
532 }
533 [] T.timeout {
534 setverdict(fail, "timeout waiting for Echo Response");
535 }
536 }
537}
538
539/* create a session, expect it to succeed */
540private function f_TC_createSession() runs on PGW_Session_CT {
541 f_create_session();
542 setverdict(pass);
543}
544testcase TC_createSession() runs on PGW_Test_CT {
545 var PGW_Session_CT vc_conn;
546 var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun22"));
547 f_init();
548 vc_conn := f_start_handler(refers(f_TC_createSession), pars);
549 vc_conn.done;
550}
551
552/* create a session, then execute a ping command on the user plane */
553private function f_TC_createSession_ping4() runs on PGW_Session_CT {
554 f_create_session();
555 f_ping4(mp_ping_hostname);
556 setverdict(pass);
557}
558testcase TC_createSession_ping4() runs on PGW_Test_CT {
559 var PGW_Session_CT vc_conn;
560 var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23"));
561 f_init();
562 vc_conn := f_start_handler(refers(f_TC_createSession_ping4), pars);
563 vc_conn.done;
564}
Harald Weltefe595e42020-04-21 22:56:47 +0200565testcase TC_createSession_ping4_256() runs on PGW_Test_CT {
566 var PGW_Session_CT vc_conn[256];
567 var integer i;
568
569 f_init();
570
571 for (i := 0; i < sizeof(vc_conn); i:=i+1) {
572 var charstring tundev := "ping" & int2str(i);
573 var SessionPars pars := valueof(t_SessionPars(f_gen_imsi(i), tundev));
574 vc_conn[i] := f_start_handler(refers(f_TC_createSession_ping4), pars);
575 }
576
577 for (i := 0; i < lengthof(vc_conn); i:=i+1) {
578 vc_conn[i].done;
579 }
580}
581
Harald Welte4526da92020-03-05 23:08:10 +0100582
583/* create a session, then delete it again */
584private function f_TC_createSession_deleteSession() runs on PGW_Session_CT {
585 f_create_session();
586 f_delete_session(omit, g_teic, '10'O);
587 setverdict(pass);
588}
589testcase TC_createSession_deleteSession() runs on PGW_Test_CT {
590 var PGW_Session_CT vc_conn;
591 var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23"));
592 f_init();
593 vc_conn := f_start_handler(refers(f_TC_createSession_deleteSession), pars);
594 vc_conn.done;
595}
596
597/* send a DeleteSessionReq for an unknown/invalid TEID */
598private function f_TC_deleteSession_unknown() runs on PGW_Session_CT {
599 g_teic := f_gtp2_allocate_teid();
600 g_teic_remote := f_rnd_octstring(4);
Pau Espin Pedrol5b0327b2022-04-11 13:02:36 +0200601 f_delete_session(omit, '00000000'O, '40'O /* Context Unknown */, false);
Harald Welte4526da92020-03-05 23:08:10 +0100602 setverdict(pass);
603}
604testcase TC_deleteSession_unknown() runs on PGW_Test_CT {
605 var PGW_Session_CT vc_conn;
606 var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23"));
607 f_init();
608 vc_conn := f_start_handler(refers(f_TC_deleteSession_unknown), pars);
609 vc_conn.done;
610}
611
612
613
614
615control {
616 execute( TC_tx_echo() );
617 execute( TC_createSession() );
618 execute( TC_createSession_ping4() );
Harald Weltefe595e42020-04-21 22:56:47 +0200619 execute( TC_createSession_ping4_256() );
Harald Welte4526da92020-03-05 23:08:10 +0100620 execute( TC_createSession_deleteSession() );
621 execute( TC_deleteSession_unknown() );
622}
623
624
625}