blob: e1f49abaa90ddcee14ffe291c8a0406ffadc2ae5 [file] [log] [blame]
Harald Welte4526da92020-03-05 23:08:10 +01001module PGW_Tests {
2
Pau Espin Pedrole343a882022-05-18 18:51:11 +02003import from TCCEncoding_Functions all;
4
Harald Welte4526da92020-03-05 23:08:10 +01005import from General_Types all;
6import from Osmocom_Types all;
7import from Native_Functions all;
Pau Espin Pedrol251d0642022-04-20 18:16:45 +02008import from Misc_Helpers all;
Harald Welte4526da92020-03-05 23:08:10 +01009
10import from GTPv2_Types all;
11import from GTPv2_Templates all;
12import from GTPv2_Emulation all;
13
14import from UECUPS_Types all;
15
16import from DNS_Helpers all;
17
Harald Weltef4001512020-04-26 21:48:34 +020018
19import from DIAMETER_Types all;
20import from DIAMETER_Templates all;
21import from DIAMETER_Emulation all;
22
23
Harald Welte4526da92020-03-05 23:08:10 +010024modulepar {
Vadim Yanitskiy589972f2022-01-20 19:38:16 +060025 charstring mp_pgw_hostname := "127.0.0.4";
Harald Welte4526da92020-03-05 23:08:10 +010026 charstring mp_local_hostname_c := "127.0.0.1";
27 charstring mp_local_hostname_u := "127.0.0.1";
Harald Weltef4001512020-04-26 21:48:34 +020028
Vadim Yanitskiy284c68e2022-02-02 22:30:37 +060029 charstring mp_run_prog_log_path := "/tmp";
Harald Welte4526da92020-03-05 23:08:10 +010030 charstring mp_run_prog_as_user := "laforge";
31 charstring mp_ping_hostname := "10.45.0.1";
Harald Weltef4001512020-04-26 21:48:34 +020032
Vadim Yanitskiy589972f2022-01-20 19:38:16 +060033 charstring mp_pcrf_local_ip := "127.0.0.9";
Harald Weltef4001512020-04-26 21:48:34 +020034 integer mp_pcrf_local_port := 3868;
Pau Espin Pedrol251d0642022-04-20 18:16:45 +020035
36 charstring mp_ocs_local_ip := "127.0.0.9";
37 integer mp_ocs_local_port := 3869;
Pau Espin Pedrole343a882022-05-18 18:51:11 +020038
39 charstring mp_diam_realm := "localdomain";
Harald Welte4526da92020-03-05 23:08:10 +010040}
41
42/* main component, we typically have one per testcase */
43type component PGW_Test_CT {
44 var GTPv2_Emulation_CT vc_GTP2;
45 port GTP2EM_PT TEID0;
Harald Weltef4001512020-04-26 21:48:34 +020046
47 /* emulated PCRF */
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +020048 var DIAMETER_Emulation_CT vc_Gx;
49 port DIAMETER_PT Gx_UNIT;
50 port DIAMETEREM_PROC_PT Gx_PROC;
Pau Espin Pedrol251d0642022-04-20 18:16:45 +020051 /* emulated OCS */
52 var DIAMETER_Emulation_CT vc_Gy;
53 port DIAMETER_PT Gy_UNIT;
54 port DIAMETEREM_PROC_PT Gy_PROC;
Pau Espin Pedrol08880f12022-04-07 19:05:15 +020055 /* global test case guard timer (actual timeout value is set in f_init()) */
56 timer T_guard;
57}
58
59/* global altstep for global guard timer; */
60altstep as_Tguard() runs on PGW_Test_CT {
61 [] T_guard.timeout {
62 setverdict(fail, "Timeout of T_guard");
63 mtc.stop;
64 }
Harald Welte4526da92020-03-05 23:08:10 +010065}
66
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +020067type component DIAMETER_ConnHdlr_CT extends DIAMETER_ConnHdlr {
68 port DIAMETER_Conn_PT DIAMETER_CLIENT;
69}
70
71function f_diam_connhldr_ct_main(hexstring imsi) runs on DIAMETER_ConnHdlr_CT {
72 var PDU_DIAMETER msg;
73
74 if (DIAMETER_PROC.checkstate("Connected")) {
75 f_diameter_expect(imsi);
76 }
77
78 while (true) {
79 alt {
80 [] DIAMETER_CLIENT.receive(PDU_DIAMETER:?) -> value msg {
81 DIAMETER.send(msg);
82 }
83 [] DIAMETER.receive(PDU_DIAMETER:?) -> value msg {
84 DIAMETER_CLIENT.send(msg);
85 }
86 }
87 }
88}
89
90
Harald Welte4526da92020-03-05 23:08:10 +010091/* per-session component; we typically have 1..N per testcase */
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +020092type component PGW_Session_CT extends GTP2_ConnHdlr {
Harald Welte4526da92020-03-05 23:08:10 +010093 var SessionPars g_pars;
94
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +020095 port DIAMETER_Conn_PT Gx;
Pau Espin Pedrol251d0642022-04-20 18:16:45 +020096 port DIAMETER_Conn_PT Gy;
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +020097
Harald Welte4526da92020-03-05 23:08:10 +010098 /* TEI (Data) local side */
99 var OCT4 g_teid;
100 /* TEI (Control) local side */
101 var OCT4 g_teic;
102 /* TEI (Data) remote side */
103 var OCT4 g_teid_remote;
104 /* TEI (Control) remote side */
105 var OCT4 g_teic_remote;
106 /* GTP-U IPv4 address remote sie */
107 var OCT4 g_gtpu4_remote;
108 var OCT16 g_gtpu6_remote;
109
110 /* Address allocation */
111 var OCT4 g_ip4_addr;
112 var OCT16 g_ip6_addr;
113 var integer g_ip6_plen;
Pau Espin Pedrol2fde1ef2022-05-20 18:53:09 +0200114
115 /* Store last received Gy message */
116 var PDU_DIAMETER g_rx_gy;
Harald Welte4526da92020-03-05 23:08:10 +0100117}
118
119/* configuration data for a given Session */
120type record SessionPars {
121 hexstring imsi,
Pau Espin Pedrole343a882022-05-18 18:51:11 +0200122 hexstring msisdn optional,
Harald Welte4526da92020-03-05 23:08:10 +0100123 // serving network
124 integer rat_type,
125 // flags?
126 charstring apn,
127 /* Apn subscribed or non-subscribed */
128 boolean selection_mode,
129 BIT3 pdn_type,
130 /* PAA */
131 /* Max APN Restriction */
132 /* APN-AMBR */
133 octetstring pco optional,
134 octetstring epco optional,
135 /* Bearer Contexts to be created */
136
137 charstring tun_dev_name,
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200138 charstring tun_netns_name optional,
139
140 /* In seconds. 0 => disabled, !0 => grant over CC-Time period */
141 integer gy_validity_time
Harald Welte4526da92020-03-05 23:08:10 +0100142}
143
144template (value) SessionPars
145t_SessionPars(hexstring imsi, charstring tundev, integer rat_type := 6, charstring apn := "internet",
146 boolean selection_mode := false, BIT3 pdn_type := '001'B) := {
147 imsi := imsi,
Pau Espin Pedrole343a882022-05-18 18:51:11 +0200148 msisdn := '1234'H,
Harald Welte4526da92020-03-05 23:08:10 +0100149 rat_type := rat_type,
150 apn := apn,
151 selection_mode := selection_mode,
152 pdn_type := pdn_type,
153 pco := omit,
154 epco := omit,
155 tun_dev_name := tundev,
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200156 tun_netns_name := tundev,
157 gy_validity_time := 0
Harald Welte4526da92020-03-05 23:08:10 +0100158}
159
160type record BearerConfig {
161 integer eps_bearer_id
162}
163
164type function void_fn() runs on PGW_Session_CT;
165
Harald Weltef4001512020-04-26 21:48:34 +0200166friend function DiameterForwardUnitdataCallback(PDU_DIAMETER msg)
167runs on DIAMETER_Emulation_CT return template PDU_DIAMETER {
168 DIAMETER_UNIT.send(msg);
169 return omit;
170}
171
172friend function f_init_diameter(charstring id) runs on PGW_Test_CT {
173 var DIAMETEROps ops := {
174 create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback),
Vadim Yanitskiyb46f01e2021-12-06 03:23:13 +0300175 unitdata_cb := refers(DiameterForwardUnitdataCallback),
176 raw := false /* handler mode (IMSI based routing) */
Harald Weltef4001512020-04-26 21:48:34 +0200177 };
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200178 var DIAMETER_conn_parameters pars;
179
180 /* Gx setup: */
181 pars := {
Harald Weltef4001512020-04-26 21:48:34 +0200182 remote_ip := mp_pgw_hostname,
183 remote_sctp_port := -1,
184 local_ip := mp_pcrf_local_ip,
185 local_sctp_port := mp_pcrf_local_port,
Pau Espin Pedrole343a882022-05-18 18:51:11 +0200186 origin_host := "pcrf." & mp_diam_realm,
187 origin_realm := mp_diam_realm,
Pau Espin Pedrol33b47492022-03-08 17:43:01 +0100188 auth_app_id := omit,
Harald Weltef4001512020-04-26 21:48:34 +0200189 vendor_app_id := c_DIAMETER_3GPP_Gx_AID
190 };
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200191 vc_Gx := DIAMETER_Emulation_CT.create(id);
192 map(vc_Gx:DIAMETER, system:DIAMETER_CODEC_PT);
193 connect(vc_Gx:DIAMETER_UNIT, self:Gx_UNIT);
194 connect(vc_Gx:DIAMETER_PROC, self:Gx_PROC);
195 vc_Gx.start(DIAMETER_Emulation.main(ops, pars, id));
Harald Weltef4001512020-04-26 21:48:34 +0200196
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200197 /* Gy setup: */
198 pars := {
199 remote_ip := mp_pgw_hostname,
200 remote_sctp_port := -1,
201 local_ip := mp_ocs_local_ip,
202 local_sctp_port := mp_ocs_local_port,
Pau Espin Pedrole343a882022-05-18 18:51:11 +0200203 origin_host := "ocs." & mp_diam_realm,
204 origin_realm := mp_diam_realm,
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200205 auth_app_id := c_DIAMETER_CREDIT_CONTROL_AID,
206 vendor_app_id := omit
207 };
208 vc_Gy := DIAMETER_Emulation_CT.create(id);
209 map(vc_Gy:DIAMETER, system:DIAMETER_CODEC_PT);
210 connect(vc_Gy:DIAMETER_UNIT, self:Gy_UNIT);
211 connect(vc_Gy:DIAMETER_PROC, self:Gy_PROC);
212 vc_Gy.start(DIAMETER_Emulation.main(ops, pars, id));
213
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200214 f_diameter_wait_capability(Gx_UNIT);
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200215 f_diameter_wait_capability(Gy_UNIT);
Pau Espin Pedrolbb5f45f2022-04-11 12:36:55 +0200216 /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdong ping-pongs):
217 * RFC6733 sec 5.1
218 * RFC3539 sec 3.4.1 [5]
219 * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49
220 */
221 f_sleep(1.0);
Harald Weltef4001512020-04-26 21:48:34 +0200222}
223
Pau Espin Pedrol08880f12022-04-07 19:05:15 +0200224private function f_init(float guard_timeout := 60.0) runs on PGW_Test_CT {
225 T_guard.start(guard_timeout);
226 activate(as_Tguard());
227
Harald Welte4526da92020-03-05 23:08:10 +0100228 var Gtp2EmulationCfg cfg := {
229 gtpc_bind_ip := mp_local_hostname_c,
230 gtpc_bind_port := GTP2C_PORT,
231 gtpc_remote_ip := mp_pgw_hostname,
232 gtpc_remote_port := GTP2C_PORT,
233 sgw_role := true,
234 use_gtpu_daemon := true
235 };
236
237 vc_GTP2 := GTPv2_Emulation_CT.create("GTP2_EM");
238 map(vc_GTP2:GTP2C, system:GTP2C);
239 connect(vc_GTP2:TEID0, self:TEID0);
240 vc_GTP2.start(GTPv2_Emulation.main(cfg));
Harald Weltef4001512020-04-26 21:48:34 +0200241
242 if (mp_pcrf_local_ip != "") {
243 f_init_diameter(testcasename());
244 }
Harald Welte4526da92020-03-05 23:08:10 +0100245}
246
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200247function f_start_handler(void_fn fn, template (omit) SessionPars pars_tmpl := omit)
Harald Welte4526da92020-03-05 23:08:10 +0100248runs on PGW_Test_CT return PGW_Session_CT {
249 var charstring id := testcasename();
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200250 var DIAMETER_ConnHdlr_CT vc_conn_gx, vc_conn_gy;
Harald Welte4526da92020-03-05 23:08:10 +0100251 var PGW_Session_CT vc_conn;
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200252 var SessionPars pars;
253
254 if (isvalue(pars_tmpl)) {
255 pars := valueof(pars_tmpl);
256 } else {
257 /*TODO: set default values */
258 }
259
Harald Welte4526da92020-03-05 23:08:10 +0100260 vc_conn := PGW_Session_CT.create(id);
261 connect(vc_conn:GTP2, vc_GTP2:CLIENT);
262 connect(vc_conn:GTP2_PROC, vc_GTP2:CLIENT_PROC);
Harald Weltef4001512020-04-26 21:48:34 +0200263
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200264 if (isbound(vc_Gx)) {
265 vc_conn_gx := DIAMETER_ConnHdlr_CT.create(id);
266 connect(vc_conn_gx:DIAMETER, vc_Gx:DIAMETER_CLIENT);
267 connect(vc_conn_gx:DIAMETER_PROC, vc_Gx:DIAMETER_PROC);
268 connect(vc_conn:Gx, vc_conn_gx:DIAMETER_CLIENT);
269 vc_conn_gx.start(f_diam_connhldr_ct_main(pars.imsi));
Harald Weltef4001512020-04-26 21:48:34 +0200270 }
271
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200272 if (isbound(vc_Gy)) {
273 vc_conn_gy := DIAMETER_ConnHdlr_CT.create(id);
274 connect(vc_conn_gy:DIAMETER, vc_Gy:DIAMETER_CLIENT);
275 connect(vc_conn_gy:DIAMETER_PROC, vc_Gy:DIAMETER_PROC);
276 connect(vc_conn:Gy, vc_conn_gy:DIAMETER_CLIENT);
277 vc_conn_gy.start(f_diam_connhldr_ct_main(pars.imsi));
278 }
279
Harald Welte4526da92020-03-05 23:08:10 +0100280 vc_conn.start(f_handler_init(fn, pars));
281 return vc_conn;
282}
283
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200284private function f_handler_init(void_fn fn, SessionPars pars)
Harald Welte4526da92020-03-05 23:08:10 +0100285runs on PGW_Session_CT {
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200286 g_pars := valueof(pars);
Harald Welte4526da92020-03-05 23:08:10 +0100287 fn.apply();
288}
289
Harald Weltefe595e42020-04-21 22:56:47 +0200290private function f_concat_pad(integer tot_len, hexstring prefix, integer suffix) return hexstring {
291 var integer suffix_len := tot_len - lengthof(prefix);
292 var charstring suffix_ch := int2str(suffix);
293 var integer pad_len := suffix_len - lengthof(suffix_ch);
294
295 return prefix & int2hex(0, pad_len) & str2hex(suffix_ch);
296}
297
298function f_gen_imei(integer suffix) return hexstring {
299 return f_concat_pad(14, '49999'H, suffix);
300}
301
302function f_gen_imsi(integer suffix) return hexstring {
303 return f_concat_pad(15, '26242'H, suffix);
304}
305
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200306private altstep as_DIA_Gx_CCR(DCC_NONE_CC_Request_Type req_type) runs on PGW_Session_CT {
Harald Weltef4001512020-04-26 21:48:34 +0200307 var PDU_DIAMETER rx_dia;
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200308 [] Gx.receive(tr_DIA_Gx_CCR(req_type := req_type)) -> value rx_dia {
Harald Weltef4001512020-04-26 21:48:34 +0200309 var template (omit) AVP avp;
310 var octetstring sess_id;
311 var AVP_Unsigned32 req_num;
312
313 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
314 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
315
316 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
317 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
318
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200319 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 +0200320 req_type, req_num));
321 }
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200322 [] Gx.receive(PDU_DIAMETER:?) -> value rx_dia {
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200323 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
324 log2str("Received unexpected DIAMETER ", rx_dia));
325 }
326}
327
Pau Espin Pedrole343a882022-05-18 18:51:11 +0200328function f_tr_DIA_Gy_CCR(DCC_NONE_CC_Request_Type req_type)
329runs on PGW_Session_CT return template (present) PDU_DIAMETER
330{
331 var template (present) PDU_DIAMETER tpl;
332 var charstring smf_origin_host := "smf." & mp_diam_realm;
333 var template (present) octetstring imsi := ?;
334 var template (present) octetstring msisdn := ?;
335 var template (present) octetstring rat_type := ?;
336 var template (present) OCT4 charging_char := ?;
337 var template (present) OCT1 nsapi := ?;
338 imsi := char2oct(f_dec_TBCD(imsi_hex2oct(g_pars.imsi)));
339 //msisdn := char2oct(f_dec_TBCD(substr(ctx_val.msisdn, 1, lengthof(ctx_val.msisdn) -1)));
340 rat_type := int2oct(g_pars.rat_type, 1);
341 charging_char := char2oct(oct2str('0000'O)); // f_create_session() uses hardcoded chg_car := '0000'O
342 nsapi := '01'O; // f_create_session() uses hardcoded bearer_id := 1
343 select (req_type) {
344 case (INITIAL_REQUEST) {
345 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
346 avps := superset(
347 tr_AVP_SessionId,
348 tr_AVP_OriginHost(smf_origin_host),
349 tr_AVP_OriginRealm(mp_diam_realm),
350 tr_AVP_DestinationRealm(mp_diam_realm),
351 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
352 tr_AVP_ServiceContextId,
353 tr_AVP_CcReqType(req_type),
354 tr_AVP_CcReqNum(?),
355 tr_AVP_EventTimestamp(?),
356 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
357 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
358 tr_AVP_RequestedAction(DIRECT_DEBITING),
359 tr_AVP_3GPP_AoCRequestType,
360 tr_AVP_MultipleServicesIndicator,
361 tr_AVP_Multiple_Services_Credit_Control(content := superset(
362 tr_AVP_Requested_Service_Unit,
363 tr_AVP_Used_Service_Unit,
364 tr_AVP_3GPP_QoS_Information,
365 tr_AVP_GI_3GPP_RatType(rat_type)
366 )),
367 tr_AVP_3GPP_ServiceInformation(content := superset(
368 tr_AVP_3GPP_PSInformation(content := superset(
369 tr_AVP_3GPP_ChargingId,
370 tr_AVP_3GPP_PDPType((IPv4,IPv6,IPv4v6)),
371 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
372 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(mp_pcrf_local_ip))),
373 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(mp_pgw_hostname))),
374 tr_AVP_3GPP_CalledStationId,
375 tr_AVP_3GPP_SelectionMode,
376 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
377 tr_AVP_3GPP_SGSNMCCMNC,
378 tr_AVP_3GPP_NSAPI(nsapi),
379 /*We don't yet send MS_Tz in CreateSessionReq:
380 tr_AVP_3GPP_MS_TimeZone,*/
381 tr_AVP_3GPP_ULI/*,
382 We don't yet send IMEI in CreateSessionReq:
383 tr_AVP_UserEquipmentInfo({
384 tr_AVP_UserEquipmentInfoType(IMEISV),
385 tr_AVP_UserEquipmentInfoValue(imeisv)
386 })*/
387 ))
388 ))
389 ));
390 }
391 case (UPDATE_REQUEST) {
392 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
393 avps := superset(
394 tr_AVP_SessionId,
395 tr_AVP_OriginHost(smf_origin_host),
396 tr_AVP_OriginRealm(mp_diam_realm),
397 tr_AVP_DestinationRealm(mp_diam_realm),
398 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
399 tr_AVP_ServiceContextId,
400 tr_AVP_CcReqType(req_type),
401 tr_AVP_CcReqNum(?),
402 tr_AVP_DestinationHost(?),
403 tr_AVP_EventTimestamp(?),
404 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
405 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
406 tr_AVP_RequestedAction(DIRECT_DEBITING),
407 tr_AVP_3GPP_AoCRequestType,
408 tr_AVP_MultipleServicesIndicator,
409 tr_AVP_Multiple_Services_Credit_Control(content := superset(
410 tr_AVP_Requested_Service_Unit,
411 tr_AVP_Used_Service_Unit,
Pau Espin Pedrolcba0f6d2022-05-24 13:49:46 +0200412 /* tr_AVP_3GPP_Reporting_Reason, can be sometimes inside UsedServiceUnit */
Pau Espin Pedrole343a882022-05-18 18:51:11 +0200413 tr_AVP_3GPP_QoS_Information,
414 tr_AVP_GI_3GPP_RatType(rat_type)
415 )),
416 tr_AVP_3GPP_ServiceInformation(content := superset(
417 tr_AVP_3GPP_PSInformation(content := superset(
418 tr_AVP_3GPP_ChargingId,
419 /* tr_AVP_3GPP_PDPType, Only in INIT */
420 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
421 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(mp_pcrf_local_ip))),
422 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(mp_pgw_hostname))),
423 tr_AVP_3GPP_CalledStationId,
424 tr_AVP_3GPP_SelectionMode,
425 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
426 tr_AVP_3GPP_SGSNMCCMNC,
427 tr_AVP_3GPP_NSAPI(nsapi),
428 /*We don't yet send MS_Tz in CreateSessionReq:
429 tr_AVP_3GPP_MS_TimeZone,*/
430 tr_AVP_3GPP_ULI/*,
431 We don't yet send IMEI in CreateSessionReq:
432 tr_AVP_UserEquipmentInfo({
433 tr_AVP_UserEquipmentInfoType(IMEISV),
434 tr_AVP_UserEquipmentInfoValue(imeisv)
435 })*/
436 ))
437 ))
438 ));
439 }
440 case (TERMINATION_REQUEST) {
441 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
442 avps := superset(
443 tr_AVP_SessionId,
444 tr_AVP_OriginHost(smf_origin_host),
445 tr_AVP_OriginRealm(mp_diam_realm),
446 tr_AVP_DestinationRealm(mp_diam_realm),
447 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
448 tr_AVP_ServiceContextId,
449 tr_AVP_CcReqType(req_type),
450 tr_AVP_CcReqNum(?),
451 tr_AVP_DestinationHost(?),
452 tr_AVP_EventTimestamp(?),
453 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
454 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
455 tr_AVP_TerminationCause(?),
456 tr_AVP_RequestedAction(DIRECT_DEBITING),
457 tr_AVP_3GPP_AoCRequestType,
458 tr_AVP_MultipleServicesIndicator,
459 tr_AVP_Multiple_Services_Credit_Control(content := superset(
460 /* tr_AVP_Requested_Service_Unit, Only in INIT and UPDATE */
461 tr_AVP_Used_Service_Unit,
Pau Espin Pedrolcba0f6d2022-05-24 13:49:46 +0200462 tr_AVP_3GPP_Reporting_Reason(FINAL),
Pau Espin Pedrole343a882022-05-18 18:51:11 +0200463 tr_AVP_3GPP_QoS_Information,
464 tr_AVP_GI_3GPP_RatType(rat_type)
465 )),
466 tr_AVP_3GPP_ServiceInformation(content := superset(
467 tr_AVP_3GPP_PSInformation(content := superset(
468 tr_AVP_3GPP_ChargingId,
469 /* tr_AVP_3GPP_PDPType, Only in INIT */
470 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
471 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(mp_pcrf_local_ip))),
472 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(mp_pgw_hostname))),
473 tr_AVP_3GPP_CalledStationId,
474 tr_AVP_3GPP_SelectionMode,
475 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
476 tr_AVP_3GPP_SGSNMCCMNC,
477 tr_AVP_3GPP_NSAPI(nsapi),
478 /*We don't yet send MS_Tz in CreateSessionReq:
479 tr_AVP_3GPP_MS_TimeZone,*/
480 tr_AVP_3GPP_ULI/*,
481 We don't yet send IMEI in CreateSessionReq:
482 tr_AVP_UserEquipmentInfo({
483 tr_AVP_UserEquipmentInfoType(IMEISV),
484 tr_AVP_UserEquipmentInfoValue(imeisv)
485 })*/
486 ))
487 ))
488 ));
489 }
490 }
491 return tpl;
492}
493
Pau Espin Pedrol2fde1ef2022-05-20 18:53:09 +0200494private altstep as_DIA_Gy_CCR(DCC_NONE_CC_Request_Type req_type)
495runs on PGW_Session_CT {
496 [] Gy.receive(f_tr_DIA_Gy_CCR(req_type := req_type)) -> value g_rx_gy {
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200497 var template (value) PDU_DIAMETER tx_dia;
498 var template (omit) AVP avp;
499 var octetstring sess_id;
500 var AVP_Unsigned32 req_num;
501
Pau Espin Pedrol2fde1ef2022-05-20 18:53:09 +0200502 avp := f_DIAMETER_get_avp(g_rx_gy, c_AVP_Code_BASE_NONE_Session_Id);
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200503 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
504
Pau Espin Pedrol2fde1ef2022-05-20 18:53:09 +0200505 avp := f_DIAMETER_get_avp(g_rx_gy, c_AVP_Code_DCC_NONE_CC_Request_Number);
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200506 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
507 if (g_pars.gy_validity_time > 0) {
Pau Espin Pedrol2fde1ef2022-05-20 18:53:09 +0200508 tx_dia := ts_DIA_Gy_CCA_ValidityTime(g_rx_gy.hop_by_hop_id, g_rx_gy.end_to_end_id, sess_id,
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200509 req_type, req_num, g_pars.gy_validity_time);
510 } else {
Pau Espin Pedrol2fde1ef2022-05-20 18:53:09 +0200511 tx_dia := ts_DIA_Gy_CCA(g_rx_gy.hop_by_hop_id, g_rx_gy.end_to_end_id, sess_id,
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200512 req_type, req_num);
513 }
514 Gy.send(tx_dia);
515 }
Pau Espin Pedrol2fde1ef2022-05-20 18:53:09 +0200516 [] Gy.receive(PDU_DIAMETER:?) -> value g_rx_gy {
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200517 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
Pau Espin Pedrol2fde1ef2022-05-20 18:53:09 +0200518 log2str("Received unexpected DIAMETER Gy", g_rx_gy));
Harald Weltef4001512020-04-26 21:48:34 +0200519 }
520}
521
Harald Welte4526da92020-03-05 23:08:10 +0100522
523/* find TEID of given interface type (and optionally instance) */
524private function f_find_teid(FullyQualifiedTEID_List list,
525 template (present) integer if_type,
526 template (present) BIT4 instance := ?)
527return template (omit) FullyQualifiedTEID
528{
529 var integer i;
530 for (i := 0; i < lengthof(list); i := i+1) {
531 if (match(list[i].interfaceType, if_type) and
532 match(list[i].instance, instance)) {
533 return list[i];
534 }
535 }
536 return omit;
537}
538
539/* process one to-be-created bearer context */
540private function process_bctx_create(BearerContextGrouped bctx) runs on PGW_Session_CT
541{
542 /* FIXME: EPS Bearer ID */
543 /* FIXME: Cause */
544
545 /* find F-TEID of the P-GW U side */
546 var FullyQualifiedTEID rx_fteid;
547 rx_fteid := valueof(f_find_teid(bctx.bearerContextIEs.fullyQualifiedTEID, 5, '0010'B));
548 g_teid_remote := rx_fteid.tEID_GRE_Key;
549 if (rx_fteid.v4_Flag == '1'B) {
550 g_gtpu4_remote := rx_fteid.iPv4_Address;
551 }
552 if (rx_fteid.v6_Flag == '1'B) {
553 g_gtpu6_remote := rx_fteid.iPv6_Address;
554 }
555
556 var UECUPS_CreateTun uecups_create := {
557 tx_teid := oct2int(g_teid_remote),
558 rx_teid := oct2int(g_teid),
559 user_addr_type := IPV4,
560 user_addr := '00000000'O,
561 local_gtp_ep := valueof(ts_UECUPS_SockAddr(f_inet_addr(mp_local_hostname_u))),
562 remote_gtp_ep := valueof(ts_UECUPS_SockAddr(g_gtpu4_remote)),
563 tun_dev_name := g_pars.tun_dev_name,
564 tun_netns_name := g_pars.tun_netns_name
565 };
566
567 /* create tunnel in daemon */
568 if (isbound(g_ip4_addr)) {
569 uecups_create.user_addr := g_ip4_addr;
570 f_gtp2_create_tunnel(uecups_create);
571 }
572 if (isbound(g_ip6_addr)) {
573 uecups_create.user_addr_type := IPV6;
574 uecups_create.user_addr := g_ip6_addr;
575 f_gtp2_create_tunnel(uecups_create);
576 }
577}
578
579/* create a session on the PGW */
580private function f_create_session() runs on PGW_Session_CT {
581 var PDU_GTPCv2 rx;
582
583 /* allocate + register TEID-C on local side */
584 g_teic := f_gtp2_allocate_teid();
585 g_teid := g_teic;
586
587 var template (value) FullyQualifiedTEID fteid_c_ie, fteid_u_ie;
588 fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_SGW_GTPC, g_teic, 0,
589 f_inet_addr(mp_local_hostname_c), omit);
590 fteid_u_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_SGW_GTPU, g_teid, 2,
591 f_inet_addr(mp_local_hostname_u), omit);
592 var template (value) PDU_GTPCv2 g2c :=
Pau Espin Pedrole343a882022-05-18 18:51:11 +0200593 ts_GTP2C_CreateSessionReq(imsi := g_pars.imsi, msisdn := g_pars.msisdn, rat_type := 6,
Harald Welte4526da92020-03-05 23:08:10 +0100594 sender_fteid := fteid_c_ie,
595 apn := f_enc_dns_hostname(g_pars.apn),
596 pdn_type := g_pars.pdn_type, teid_list := { fteid_u_ie },
597 chg_car := '0000'O, bearer_id := 1);
598 /* open5gs up to 1.2.3 won't accept it without ULI, despite not mandatory */
599 var template (value) TAI tai := { '0'H, '0'H, '1'H, 'F'H, '0'H, '1'H, '0001'O };
600 var template (value) ECGI ecgi := { '0'H, '0'H, '1'H, 'F'H, '0'H, '1'H, '0'H, 23 };
601 g2c.gtpcv2_pdu.createSessionRequest.userLocationInfo := ts_GTP2C_UserLocInfo(tai := tai, ecgi := ecgi);
Vadim Yanitskiybada3c92022-01-20 18:59:07 +0600602 g2c.gtpcv2_pdu.createSessionRequest.servingNetwork := ts_GTP2C_ServingNetwork('001'H, '01F'H);
Harald Welte4526da92020-03-05 23:08:10 +0100603
604 GTP2.send(g2c);
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200605 if (Gx.checkstate("Connected")) {
606 as_DIA_Gx_CCR(INITIAL_REQUEST);
Harald Weltef4001512020-04-26 21:48:34 +0200607 }
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200608 if (Gy.checkstate("Connected")) {
609 as_DIA_Gy_CCR(INITIAL_REQUEST);
610 }
Harald Welte4526da92020-03-05 23:08:10 +0100611 alt {
612 [] GTP2.receive(tr_GTP2C_CreateSessionResp(d_teid:=g_teic, cause:='10'O)) -> value rx {
613 /* extract TEIDs */
614 var CreateSessionResponse resp := rx.gtpcv2_pdu.createSessionResponse;
615 g_teic_remote := resp.fullyQualifiedTEID[0].tEID_GRE_Key;
616
617 /* extract allocated address[es] */
618 var PDN_Address_and_Prefix paa := resp.pDN_AddressAllocation.pDN_Address_and_Prefix;
619 if (ischosen(paa.iPv4_Address)) {
620 g_ip4_addr := paa.iPv4_Address;
621 } else if (ischosen(paa.iPv6_Address)) {
622 g_ip6_addr := paa.iPv6_Address.iPv6_Address;
623 g_ip6_plen := paa.iPv6_Address.prefixLength;
624 } else if (ischosen(paa.iPv4_IPv6)) {
625 g_ip4_addr := paa.iPv4_IPv6.iPv4_Address;
626 g_ip6_addr := paa.iPv4_IPv6.iPv6_Address;
627 g_ip6_plen := paa.iPv4_IPv6.prefixLength;
628 }
629 var integer i;
630 for (i := 0; i < lengthof(resp.bearerContextGrouped); i := i+1) {
631 var BearerContextGrouped bctx := resp.bearerContextGrouped[i];
632 select (bctx.instance) {
633 case ('0000'B) { // created
634 process_bctx_create(bctx);
635 }
636 case ('0001'B) { // removed
637 setverdict(fail, "We don't expect removed bearer contexts yet");
638 }
639 }
640 }
641 }
642 [] GTP2.receive(tr_GTP2C_CreateSessionResp(d_teid:=g_teic, cause:=?)) -> value rx {
643 setverdict(fail, "Unexpected CreateSessionResp(cause=",
644 rx.gtpcv2_pdu.createSessionResponse.cause.causeValue, ")");
645 }
646 [] GTP2.receive {
647 setverdict(fail, "Unexpected GTPv2 while waiting for CreateSessionResp");
648 }
649 }
650
651}
652
653/* delete the session from the PGW */
654private function f_delete_session(template (omit) OCT1 tx_cause := omit,
655 template (present) OCT4 exp_teid,
Pau Espin Pedrol5b0327b2022-04-11 13:02:36 +0200656 template (present) OCT1 exp_cause,
657 boolean expect_diameter := true) runs on PGW_Session_CT {
Harald Welte4526da92020-03-05 23:08:10 +0100658 var template (value) FullyQualifiedTEID fteid_c_ie
659 fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_SGW_GTPC, g_teic, 0,
660 f_inet_addr(mp_local_hostname_c), omit);
661 var template PDU_GTPCv2 g2c :=
662 ts_GTP2C_DeleteSessionReq(d_teid := g_teic_remote, cause := tx_cause,
663 sender_fteid := fteid_c_ie,
664 teid_list := {}, bearer_id := 1);
665
666 GTP2.send(g2c);
Pau Espin Pedrol8b3123f2022-04-20 17:17:05 +0200667 if (Gx.checkstate("Connected") and expect_diameter) {
668 as_DIA_Gx_CCR(TERMINATION_REQUEST);
Harald Weltef4001512020-04-26 21:48:34 +0200669 }
Pau Espin Pedrol251d0642022-04-20 18:16:45 +0200670 if (Gy.checkstate("Connected") and expect_diameter) {
671 as_DIA_Gy_CCR(TERMINATION_REQUEST);
672 }
Harald Welte4526da92020-03-05 23:08:10 +0100673 alt {
674 [] GTP2.receive(tr_GTP2C_DeleteSessionResp(d_teid := exp_teid, cause := exp_cause)) {
675 setverdict(pass);
676 }
677 [] GTP2.receive(tr_GTP2C_DeleteSessionResp(?, ?)) {
678 setverdict(fail, "Unexpected DeleteSessionResp");
679 }
680 [] GTP2.receive {
681 setverdict(fail, "Unexpected GTPv2 while waiting for DeleteSessionResp");
682 }
683 }
684
685 /* destroy tunnel in daemon */
686 if (isbound(g_teid)) {
687 var UECUPS_DestroyTun uecups_destroy := {
688 local_gtp_ep := valueof(ts_UECUPS_SockAddr(f_inet_addr(mp_local_hostname_u))),
689 rx_teid := oct2int(g_teid)
690 };
691 /* FIXME: what about IPv4/IPv6 differentiation? */
692 f_gtp2_destroy_tunnel(uecups_destroy);
693 }
694}
695
696/* start a program on the user plane side; return its PID */
Vadim Yanitskiy284c68e2022-02-02 22:30:37 +0600697private function f_start_prog(charstring command, boolean redirect_output := true)
698runs on PGW_Session_CT return integer
Harald Welte4526da92020-03-05 23:08:10 +0100699{
700 var UECUPS_StartProgram sprog := {
701 command := command,
702 environment := {},
703 run_as_user := mp_run_prog_as_user,
704 tun_netns_name := g_pars.tun_netns_name
705 };
Vadim Yanitskiy284c68e2022-02-02 22:30:37 +0600706
707 /* Redirect stdout/stderr to the user-specified location */
708 if (redirect_output) {
709 var charstring prefix := mp_run_prog_log_path & "/" & testcasename();
710 sprog.command := sprog.command & " 1>>" & prefix & ".prog.stdout";
711 sprog.command := sprog.command & " 2>>" & prefix & ".prog.stderr";
712 }
713
Vadim Yanitskiy36ab7972022-02-01 20:46:05 +0600714 log("Starting a program: ", command);
Harald Welte4526da92020-03-05 23:08:10 +0100715 var UECUPS_StartProgramRes res := f_gtp2_start_program(sprog);
716 if (res.result != OK) {
717 setverdict(fail, "Unable to start program '", command, "'");
718 }
719 return res.pid;
720}
721
722/* wait for termination of a given PID with specified exit_code */
723private function f_wait_term(integer pid, template (present) integer exit_code := 0,
724 float tout := 10.0) runs on PGW_Session_CT
725{
Vadim Yanitskiy36ab7972022-02-01 20:46:05 +0600726 var UECUPS_ProgramTermInd pti;
Harald Welte4526da92020-03-05 23:08:10 +0100727 timer T := tout;
728
729 T.start;
730 alt {
731 [] GTP2.receive(UECUPS_ProgramTermInd:{pid := pid, exit_code := exit_code}) {
732 setverdict(pass);
733 }
Vadim Yanitskiy36ab7972022-02-01 20:46:05 +0600734 [] GTP2.receive(UECUPS_ProgramTermInd:?) -> value pti {
735 setverdict(fail, "Received unexpected ProgramTermInd := ", pti);
Harald Welte4526da92020-03-05 23:08:10 +0100736 }
737 [] T.timeout {
738 setverdict(fail, "timeout waiting for user-plane program termination");
739 }
740 }
741}
742
743/* execute a program and wait for result */
Vadim Yanitskiy284c68e2022-02-02 22:30:37 +0600744private function f_start_prog_wait(charstring command,
745 template integer exit_code := 0,
746 float tout := 10.0,
747 boolean redirect_output := true)
748runs on PGW_Session_CT
Harald Welte4526da92020-03-05 23:08:10 +0100749{
Vadim Yanitskiy284c68e2022-02-02 22:30:37 +0600750 var integer pid := f_start_prog(command, redirect_output);
Harald Welte4526da92020-03-05 23:08:10 +0100751 f_wait_term(pid, exit_code, tout);
752}
753
754/* execute ping command and wait for result */
755private function f_ping4(charstring host, integer interval := 1, integer count := 10) runs on PGW_Session_CT
756{
757 var charstring ping :="ping -c " & int2str(count) & " -i " & int2str(interval);
758 ping := ping & " -I " & f_inet_ntoa(g_ip4_addr);
759 ping := ping & " " & host;
Harald Welte8cfdc7c2020-04-21 22:48:34 +0200760 f_start_prog_wait(ping, tout := int2float(5 + interval*count));
Harald Welte4526da92020-03-05 23:08:10 +0100761}
762
763
764
765
766/* send echo request; expect response */
767testcase TC_tx_echo() runs on PGW_Test_CT {
768 timer T := 5.0;
769
770 f_init();
771
772 TEID0.send(ts_GTP2C_EchoReq(0));
773 T.start;
774 alt {
775 [] TEID0.receive(tr_GTP2C_EchoResp) {
776 setverdict(pass);
777 }
778 [] T.timeout {
779 setverdict(fail, "timeout waiting for Echo Response");
780 }
781 }
782}
783
784/* create a session, expect it to succeed */
785private function f_TC_createSession() runs on PGW_Session_CT {
786 f_create_session();
787 setverdict(pass);
788}
789testcase TC_createSession() runs on PGW_Test_CT {
790 var PGW_Session_CT vc_conn;
791 var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun22"));
792 f_init();
793 vc_conn := f_start_handler(refers(f_TC_createSession), pars);
794 vc_conn.done;
795}
796
797/* create a session, then execute a ping command on the user plane */
798private function f_TC_createSession_ping4() runs on PGW_Session_CT {
799 f_create_session();
800 f_ping4(mp_ping_hostname);
801 setverdict(pass);
802}
803testcase TC_createSession_ping4() runs on PGW_Test_CT {
804 var PGW_Session_CT vc_conn;
805 var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23"));
806 f_init();
807 vc_conn := f_start_handler(refers(f_TC_createSession_ping4), pars);
808 vc_conn.done;
809}
Harald Weltefe595e42020-04-21 22:56:47 +0200810testcase TC_createSession_ping4_256() runs on PGW_Test_CT {
811 var PGW_Session_CT vc_conn[256];
812 var integer i;
813
814 f_init();
815
816 for (i := 0; i < sizeof(vc_conn); i:=i+1) {
817 var charstring tundev := "ping" & int2str(i);
818 var SessionPars pars := valueof(t_SessionPars(f_gen_imsi(i), tundev));
819 vc_conn[i] := f_start_handler(refers(f_TC_createSession_ping4), pars);
820 }
821
822 for (i := 0; i < lengthof(vc_conn); i:=i+1) {
823 vc_conn[i].done;
824 }
825}
826
Harald Welte4526da92020-03-05 23:08:10 +0100827
828/* create a session, then delete it again */
829private function f_TC_createSession_deleteSession() runs on PGW_Session_CT {
830 f_create_session();
831 f_delete_session(omit, g_teic, '10'O);
832 setverdict(pass);
833}
834testcase TC_createSession_deleteSession() runs on PGW_Test_CT {
835 var PGW_Session_CT vc_conn;
836 var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23"));
837 f_init();
838 vc_conn := f_start_handler(refers(f_TC_createSession_deleteSession), pars);
839 vc_conn.done;
840}
841
842/* send a DeleteSessionReq for an unknown/invalid TEID */
843private function f_TC_deleteSession_unknown() runs on PGW_Session_CT {
844 g_teic := f_gtp2_allocate_teid();
845 g_teic_remote := f_rnd_octstring(4);
Pau Espin Pedrol5b0327b2022-04-11 13:02:36 +0200846 f_delete_session(omit, '00000000'O, '40'O /* Context Unknown */, false);
Harald Welte4526da92020-03-05 23:08:10 +0100847 setverdict(pass);
848}
849testcase TC_deleteSession_unknown() runs on PGW_Test_CT {
850 var PGW_Session_CT vc_conn;
851 var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23"));
852 f_init();
853 vc_conn := f_start_handler(refers(f_TC_deleteSession_unknown), pars);
854 vc_conn.done;
855}
856
Pau Espin Pedrol431f3462022-04-20 18:45:35 +0200857/* Test charging over Gy interface. */
858private function f_TC_gy_charging_cc_time() runs on PGW_Session_CT {
859 var default d;
Harald Welte4526da92020-03-05 23:08:10 +0100860
Pau Espin Pedrol431f3462022-04-20 18:45:35 +0200861 f_create_session();
Harald Welte4526da92020-03-05 23:08:10 +0100862
Pau Espin Pedrol431f3462022-04-20 18:45:35 +0200863 /* We should receive an update even if no traffic is sent: */
864 as_DIA_Gy_CCR(UPDATE_REQUEST);
Pau Espin Pedrol2fde1ef2022-05-20 18:53:09 +0200865 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (3..4), 0, 0);
Pau Espin Pedrol431f3462022-04-20 18:45:35 +0200866
867 d := activate(as_DIA_Gy_CCR(UPDATE_REQUEST));
868 f_ping4(mp_ping_hostname);
869 /* Let the CCA reach the GGSN */
870 f_sleep(0.5);
871 deactivate(d);
Pau Espin Pedrol2fde1ef2022-05-20 18:53:09 +0200872 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (3..4), (28..1000), (28..1000));
873
874 as_DIA_Gy_CCR(UPDATE_REQUEST);
875 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (3..4), ?, ?);
Pau Espin Pedrol431f3462022-04-20 18:45:35 +0200876
877 f_delete_session(omit, g_teic, '10'O);
Pau Espin Pedrol2fde1ef2022-05-20 18:53:09 +0200878 f_validate_gy_cc_report(g_rx_gy, FINAL, (0..1), 0, 0);
Pau Espin Pedrol431f3462022-04-20 18:45:35 +0200879 setverdict(pass);
880}
881testcase TC_gy_charging_cc_time() runs on PGW_Test_CT {
882 var PGW_Session_CT vc_conn;
883 var SessionPars pars := valueof(t_SessionPars('001010123456789'H, "tun23"));
884 pars.gy_validity_time := 3; /* Grant access for 3 seconds, needs to be re-validated afterwards */
885 f_init();
886 vc_conn := f_start_handler(refers(f_TC_gy_charging_cc_time), pars);
887 vc_conn.done;
888}
Harald Welte4526da92020-03-05 23:08:10 +0100889
890control {
891 execute( TC_tx_echo() );
892 execute( TC_createSession() );
893 execute( TC_createSession_ping4() );
Harald Weltefe595e42020-04-21 22:56:47 +0200894 execute( TC_createSession_ping4_256() );
Harald Welte4526da92020-03-05 23:08:10 +0100895 execute( TC_createSession_deleteSession() );
896 execute( TC_deleteSession_unknown() );
Pau Espin Pedrol431f3462022-04-20 18:45:35 +0200897 execute( TC_gy_charging_cc_time() );
Harald Welte4526da92020-03-05 23:08:10 +0100898}
899
900
901}