blob: 68157f3bb482bb5f0c5343a3e56fafaa3b4807e0 [file] [log] [blame]
Harald Welte379d45a2017-08-03 09:55:15 +02001module GGSN_Tests {
2
Harald Welte34b5a952019-05-27 11:54:11 +02003/* GGSN test suite in TTCN-3
4 * (C) 2017-2019 Harald Welte <laforge@gnumonks.org>
5 * (C) 2018-2019 sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
Pau Espin Pedrold25095f2022-05-18 16:29:05 +020014 import from TCCEncoding_Functions all;
Harald Welte34b5a952019-05-27 11:54:11 +020015
Harald Welte94ade362017-08-04 00:36:55 +020016 import from General_Types all;
Harald Welte811651e2017-08-05 15:25:06 +020017 import from Osmocom_Types all;
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +010018 import from Misc_Helpers all;
Harald Welte94ade362017-08-04 00:36:55 +020019 import from IPL4asp_PortType all;
20 import from IPL4asp_Types all;
Pau Espin Pedrol4b090c92024-02-29 19:47:07 +010021 import from GTPv1C_CodecPort all;
22 import from GTPv1U_CodecPort all;
23 import from GTPv1C_CodecPort_CtrlFunct all;
24 import from GTPv1U_CodecPort_CtrlFunct all;
Harald Welte94ade362017-08-04 00:36:55 +020025 import from GTPC_Types all;
26 import from GTPU_Types all;
Pau Espin Pedrol4b090c92024-02-29 19:47:07 +010027 import from GTPv1C_Templates all;
28 import from GTPv1U_Templates all;
Harald Welte71a36022017-12-04 18:55:58 +010029 import from IPCP_Types all;
Harald Weltef8298542019-04-10 10:15:28 +020030 import from PAP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020031 import from IP_Types all;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +010032 import from ICMP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020033 import from ICMPv6_Types all;
Harald Welteddeecbb2017-08-18 22:53:30 +020034 import from Native_Functions all;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +020035 import from Osmocom_VTY_Functions all;
36 import from TELNETasp_PortType all;
Harald Welte94ade362017-08-04 00:36:55 +020037
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010038 import from DIAMETER_Types all;
39 import from DIAMETER_Templates all;
Pau Espin Pedrol867b1302024-01-24 16:14:28 +010040 import from DIAMETER_ts29_212_Templates all;
Pau Espin Pedrol117a94f2023-12-21 16:10:12 +010041 import from DIAMETER_ts29_272_Templates all;
Pau Espin Pedrol867b1302024-01-24 16:14:28 +010042 import from DIAMETER_ts32_299_Templates all;
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010043 import from DIAMETER_Emulation all;
44
Harald Welte94ade362017-08-04 00:36:55 +020045 const integer GTP0_PORT := 3386;
46 const integer GTP1C_PORT := 2123;
47 const integer GTP1U_PORT := 2152;
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010048 const integer PCRF_PORT := 3868;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +010049 const integer OCS_PORT := 3869;
Harald Welteddeecbb2017-08-18 22:53:30 +020050
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010051 type enumerated GGSN_Impl {
52 GGSN_IMPL_OSMOCOM,
53 GGSN_IMPL_OPEN5GS
54 };
55
Harald Welteddeecbb2017-08-18 22:53:30 +020056 modulepar {
Stefan Sperlingcb782b92018-04-03 16:03:15 +020057 /* Default IP addresses. May be overridden by GGSN_Tests configuration files. */
58
59 /* The SGSN simulated by TTCN3 will bind to these addresses for GTP control and GTP user planes. */
Harald Welteddeecbb2017-08-18 22:53:30 +020060 charstring m_bind_ip_gtpc := "127.23.42.1";
61 charstring m_bind_ip_gtpu := "127.23.42.1";
62
Stefan Sperlingcb782b92018-04-03 16:03:15 +020063 /* Addresses the GGSN which is being tested is listening on for SGSN connections. */
Harald Welteddeecbb2017-08-18 22:53:30 +020064 charstring m_ggsn_ip_gtpc := "127.0.0.6";
65 charstring m_ggsn_ip_gtpu := "127.0.0.6";
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010066
Stefan Sperlingcb782b92018-04-03 16:03:15 +020067 /*
68 * Our tests expect to see these DNS servers in 'Create PDP context responses' sent by the GGSN.
69 * These addresses must therefore match 'ip[v6] dns' options configured in osmo-ggsn.conf.
70 *
71 * These addresses are not expected to serve actual DNS requests. However, tests may expect to be
72 * able to ping these addresses (currently, IPv4 addresses must respond with an ICMP 'echo reply',
73 * and IPv6 addresses may respond with either ICMPv6 'echo reply' or 'destination unreachable').
74 */
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010075 charstring m_ggsn_ip4_dns1 := "192.168.100.1"
76 charstring m_ggsn_ip4_dns2 := "8.8.8.8"
Pau Espin Pedrol363ba482018-01-29 18:42:00 +010077 charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888"
78 charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844"
Stefan Sperlingcb782b92018-04-03 16:03:15 +020079
80 /*
81 * Additional address ranges are defined in osmo-ggsn.conf from which addresses are assigned
82 * to MS "behind" the simulated SGSN. These addresses appear on tun devices used by osmo-ggsn.
83 * The tests expect to be able to send ping packets between any two simulated MS within the same
84 * address range. This requires IP forwarding to be enabled on the corresponding tun interfaces.
85 */
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +010086 integer mp_t3_response := 5; /* local T3-RESPONSE timeout, seconds */
87 integer mp_n3_requests := 3; /* local N3-REQUESTS counter */
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010088
89 GGSN_Impl m_ggsn_impl := GGSN_IMPL_OSMOCOM;
Harald Welteddeecbb2017-08-18 22:53:30 +020090 }
Harald Welte94ade362017-08-04 00:36:55 +020091
Harald Welte811651e2017-08-05 15:25:06 +020092 type set PdpContext {
93 hexstring imsi,
94 octetstring msisdn optional,
95 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020096 ProtConfigOptions pco_req optional,
97 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020098 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020099 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +0200100 BIT4 nsapi,
101 /* TEI (Data) local side */
102 OCT4 teid,
103 /* TEI (Control) local side */
104 OCT4 teic,
105 /* TEI (Data) remote side */
106 OCT4 teid_remote,
107 /* TEI (Control) remote side */
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100108 OCT4 teic_remote,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100109 OCT1 ratType optional,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200110 UserLocationInformation uli optional,
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200111 OCT2 charging_char optional,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200112 OCT8 imeisv optional,
113 MS_TimeZone ms_tz optional
Harald Welte811651e2017-08-05 15:25:06 +0200114 }
115
Harald Welte94ade362017-08-04 00:36:55 +0200116 type component GT_CT {
117 port GTPC_PT GTPC;
118 port GTPU_PT GTPU;
119
Harald Welte0be142b2017-08-13 13:28:10 +0200120 var boolean g_initialized := false;
121
Harald Welte94ade362017-08-04 00:36:55 +0200122 var OCT1 g_restart_ctr := '01'O;
123 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200124 var OCT4 g_sgsn_ip_c;
125 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +0200126 /* FIXME: parse remName from config file */
Pau Espin Pedrol4b090c92024-02-29 19:47:07 +0100127 var Gtp1cPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
128 var Gtp1uPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200129 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200130
131 /* next to-be-sent GTP-C sequence number */
132 var uint16_t g_c_seq_nr;
133 /* next to-be-sent GTP-U sequence number */
134 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200135
136 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200137 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100138 var integer g_use_echo_intval := 0; /* 0 = disabled */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100139
Pau Espin Pedrol733369a2022-05-20 18:39:55 +0200140 /* Emulated PCRF, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200141 var DIAMETER_conn_parameters g_gx_pars;
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100142 var DIAMETER_Emulation_CT vc_Gx;
143 port DIAMETER_PT Gx_UNIT;
144 port DIAMETEREM_PROC_PT Gx_PROC;
Pau Espin Pedrol733369a2022-05-20 18:39:55 +0200145
146 /* Emulated OCS, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200147 var DIAMETER_conn_parameters g_gy_pars;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100148 var DIAMETER_Emulation_CT vc_Gy;
149 port DIAMETER_PT Gy_UNIT;
150 port DIAMETEREM_PROC_PT Gy_PROC;
151 var integer g_gy_validity_time := 0; /* In seconds. 0 => disabled, !0 => grant over CC-Time period */
Pau Espin Pedrol52562c92022-05-23 15:45:46 +0200152 var integer g_gy_volume_threshold := 0; /* In octets. 0 => disabled, !0 => request IUT to revalidate after N octets */
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200153 var PDU_DIAMETER g_rx_gy; /* Store last received Gy message */
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200154 }
155
156 private function f_init_vty() runs on GT_CT {
157 map(self:GGSNVTY, system:GGSNVTY);
158 f_vty_set_prompts(GGSNVTY);
159 f_vty_transceive(GGSNVTY, "enable");
160 }
161
162 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
163 f_vty_enter_config(GGSNVTY);
164 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200165
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200166 f_vty_transceive(GGSNVTY, "apn internet");
167 if (enable) {
168 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
169 } else {
170 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
171 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200172 f_vty_transceive(GGSNVTY, "exit");
173
174 f_vty_transceive(GGSNVTY, "apn inet6");
175 if (enable) {
176 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
177 } else {
178 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
179 }
180 f_vty_transceive(GGSNVTY, "exit");
181
182 f_vty_transceive(GGSNVTY, "apn inet46");
183 if (enable) {
184 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
185 } else {
186 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
187 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200188 f_vty_transceive(GGSNVTY, "end");
189 }
190
191 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
192 if (expect_gptu_txseq) {
193 if (gtpu.s_bit != '1'B) {
194 log("GTPU sequence number expected but not present")
195 return false;
196 }
197 } else {
198 if (gtpu.s_bit != '0'B) {
199 log("GTPU sequence number not expected but present")
200 return false;
201 }
202 }
203 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200204 }
205
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100206 private function f_vty_enable_echo_interval(integer intval_sec) runs on GT_CT {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200207 f_vty_enter_config(GGSNVTY);
208 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100209 if (intval_sec > 0) {
210 f_vty_transceive(GGSNVTY, "echo-interval " & int2str(intval_sec));
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200211 } else {
212 f_vty_transceive(GGSNVTY, "no echo-interval");
213 }
214 f_vty_transceive(GGSNVTY, "end");
215 }
216
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100217 private function DiameterForwardUnitdataCallback(PDU_DIAMETER msg)
218 runs on DIAMETER_Emulation_CT return template PDU_DIAMETER {
219 DIAMETER_UNIT.send(msg);
220 return omit;
221 }
222
223 private function f_init_diameter(charstring id) runs on GT_CT {
224 var DIAMETEROps ops := {
225 create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback),
226 unitdata_cb := refers(DiameterForwardUnitdataCallback),
227 raw := true /* handler mode (single component for all IMSI)) */
228 };
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100229
230 /* Gx setup: */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200231 g_gx_pars := {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100232 remote_ip := m_ggsn_ip_gtpc,
233 remote_sctp_port := -1,
234 local_ip := m_bind_ip_gtpc,
235 local_sctp_port := PCRF_PORT,
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100236 origin_host := "pcrf.localdomain",
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100237 origin_realm := "localdomain",
Pau Espin Pedrol33b47492022-03-08 17:43:01 +0100238 auth_app_id := omit,
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100239 vendor_app_id := c_DIAMETER_3GPP_Gx_AID
240 };
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100241 vc_Gx := DIAMETER_Emulation_CT.create(id);
242 map(vc_Gx:DIAMETER, system:DIAMETER_CODEC_PT);
243 connect(vc_Gx:DIAMETER_UNIT, self:Gx_UNIT);
244 connect(vc_Gx:DIAMETER_PROC, self:Gx_PROC);
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200245 vc_Gx.start(DIAMETER_Emulation.main(ops, g_gx_pars, id));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100246
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100247 /* Gy setup: */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200248 g_gy_pars := {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100249 remote_ip := m_ggsn_ip_gtpc,
250 remote_sctp_port := -1,
251 local_ip := m_bind_ip_gtpc,
252 local_sctp_port := OCS_PORT,
253 origin_host := "ocs.localdomain",
254 origin_realm := "localdomain",
255 auth_app_id := c_DIAMETER_CREDIT_CONTROL_AID,
256 vendor_app_id := omit
257 };
258 vc_Gy := DIAMETER_Emulation_CT.create(id);
259 map(vc_Gy:DIAMETER, system:DIAMETER_CODEC_PT);
260 connect(vc_Gy:DIAMETER_UNIT, self:Gy_UNIT);
261 connect(vc_Gy:DIAMETER_PROC, self:Gy_PROC);
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200262 vc_Gy.start(DIAMETER_Emulation.main(ops, g_gy_pars, id));
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100263
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100264 f_diameter_wait_capability(Gx_UNIT);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100265 f_diameter_wait_capability(Gy_UNIT);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100266 /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdong ping-pongs):
267 * RFC6733 sec 5.1
268 * RFC3539 sec 3.4.1 [5]
269 * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49
270 */
271 f_sleep(1.0);
272 }
273
Harald Welte94ade362017-08-04 00:36:55 +0200274 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200275 if (g_initialized == true) {
276 return;
277 }
278 g_initialized := true;
279
Harald Welteddeecbb2017-08-18 22:53:30 +0200280 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
281 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
282
Harald Welte94ade362017-08-04 00:36:55 +0200283 var Result res;
284 map(self:GTPC, system:GTPC);
Pau Espin Pedrol4b090c92024-02-29 19:47:07 +0100285 res := GTPv1C_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200286 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200287 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200288
289 map(self:GTPU, system:GTPU);
Pau Espin Pedrol4b090c92024-02-29 19:47:07 +0100290 res := GTPv1U_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200291 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200292
293 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200294 g_c_seq_nr := f_rnd_int(65535);
295 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200296
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100297 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
298 f_init_vty();
299 f_vty_set_gpdu_txseq(use_gtpu_txseq);
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100300 f_vty_enable_echo_interval(g_use_echo_intval);
Oliver Smith95722c62023-10-20 13:59:10 +0200301 /* Emit a marker to appear in the SUT's own logging output */
302 f_logp(GGSNVTY, testcasename() & "() start");
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100303 } else if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
304 f_init_diameter(testcasename());
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100305 }
Harald Welte94ade362017-08-04 00:36:55 +0200306 }
307
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100308 function f_shutdown_helper() runs on GT_CT {
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +0100309 /* Sleep (T3-RESPONSE * N3-REQUESTS) seconds.
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100310 * This ensures all retransmit queues are cleared before jumping
311 * into next tests, hence avoding situation where a test resuses
312 * a seqnum still in the GGSN's resp queue (dup req detector).
313 * See OS#5485 avout decreasing time. We could also add a new
314 * VTY command that calls gtp_clear_queues() */
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +0100315 f_sleep(int2float(mp_t3_response * mp_n3_requests));
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100316 setverdict(pass);
317 }
318
Harald Welte94ade362017-08-04 00:36:55 +0200319 /* Altstep implementing responses to any incoming echo requests */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100320 private altstep pingpong() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200321 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200322 var Gtp1uUnitdata udu;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100323 [g_use_echo_intval > 0] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200324 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200325 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200326 repeat;
327 };
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100328 [g_use_echo_intval == 0] GTPC.receive(tr_GTPC_PING(?)) {
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100329 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
330 "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200331 };
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100332 [] T_default.timeout {
333 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
Oliver Smithbbbe05d2024-02-28 11:14:32 +0100334 "pingpong T_default timeout");
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100335 };
Harald Welte94ade362017-08-04 00:36:55 +0200336 }
337
Harald Welte811651e2017-08-05 15:25:06 +0200338 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200339 const octetstring c_ApnInternet := '08696E7465726E6574'O;
340 const octetstring c_ApnInet6 := '05696E657436'O;
341 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200342
Harald Welte811651e2017-08-05 15:25:06 +0200343 /* return random NSAPI */
344 function f_rnd_nsapi() return BIT4 {
345 return int2bit(f_rnd_int(16), 4);
346 }
347
348 /* return random TEI[DC] */
349 function f_rnd_tei() return OCT4 {
350 return int2oct(f_rnd_int(4294967296), 4);
351 }
352
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200353 /* return random IMEI(SV) */
354 function f_rnd_imeisv() return OCT8 {
355 return hex2oct(f_rnd_hexstring(16, 10));
356 }
357
Harald Welte811651e2017-08-05 15:25:06 +0200358 /* define an (internal) representation of a PDP context */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +0200359 template PdpContext t_DefinePDP(hexstring imsi, charstring msisdn, octetstring apn,
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100360 EndUserAddress eua, OCT1 ratType := '02'O /* GERAN */) := {
Harald Welte811651e2017-08-05 15:25:06 +0200361 imsi := imsi,
Pau Espin Pedrold25095f2022-05-18 16:29:05 +0200362 msisdn := '11'O & f_enc_TBCD(msisdn), /* encoded as TS 29.060 7.7.33, TS 29.002 */
Harald Welte811651e2017-08-05 15:25:06 +0200363 nsapi := f_rnd_nsapi(),
364 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200365 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200366 eua := eua,
367 teid := f_rnd_tei(),
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100368 teic := f_rnd_tei(),
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100369 ratType := ratType,
370 uli := {
371 type_gtpc := '98'O,
372 lengthf := 0 /* filled in by encoder */,
373 geographicLocationType := '00'O /* CGI */,
374 geographicLocation := {
375 geographicLocationCGI := ts_GeographicLocationCGI('262'H, '42F'H, '0001'O, '0002'O)
376 }
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200377 },
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200378 charging_char := '0000'O,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200379 imeisv := f_rnd_imeisv(),
380 ms_tz := f_ts_MS_TimeZone('03'O, '01'B)
Harald Welte811651e2017-08-05 15:25:06 +0200381 }
382
383 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200384 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200385 GTPC.send(data);
Pau Espin Pedrol82a7f702022-05-19 17:41:29 +0200386 g_c_seq_nr := (g_c_seq_nr + 1) mod 65536;
Harald Welte811651e2017-08-05 15:25:06 +0200387 }
388
389 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200390 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200391 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200392 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
Pau Espin Pedrol82a7f702022-05-19 17:41:29 +0200393 g_d_seq_nr := (g_d_seq_nr + 1) mod 65536;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200394 } else {
395 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
396 }
Harald Welte811651e2017-08-05 15:25:06 +0200397 }
398
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100399 function f_handle_create_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in template OCT1 exp_cause := '80'O) runs on GT_CT {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200400 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100401
402 if (not match(cpr.cause.causevalue, exp_cause)) {
403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
404 "CreatePDPContextResp: cause expectancies didn't match");
405 }
406
407 if (cpr.cause.causevalue == '80'O) { /* Accepted */
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200408 /* Check if EUA type corresponds to requested type */
409 if (match(ctx.eua, t_EuaIPv4(?)) and
410 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100411 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
412 "EUAv4 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200413 }
414 if (match(ctx.eua, t_EuaIPv6(?)) and
415 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
417 "EUAv6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200418 }
419 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
420 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
422 "EUAv4v6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200423 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100424 } else if (cpr.cause.causevalue == '81'O) { /* Cause: New PDP type due to network preference */
425 /* ETSI TS 129 060 7.3.2 Create PDP Context Response. OS#5449 */
426 /* This should only happen if EUA requested type is v4v6: */
427 if (not ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
428 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
429 "Cause not expected when requesting a non v4v6 EUA");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200430 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100431 if (not match(cpr.endUserAddress, (tr_EuaIPv4(?), tr_EuaIPv6(?)))) {
432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
433 "Cause not expected when requesting+receiving EUAv4v6");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200434 }
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200435 } else {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100436 if (ispresent(cpr.endUserAddress)) {
437 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
438 "EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
439 }
440 setverdict(pass);
441 return;
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200442 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100443
444 /* Check if PCO response corresponds to request */
445 if (ispresent(ctx.pco_req)) {
446 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
447 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
449 "IPv4 DNS Container requested, but missing");
450 }
451 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
452 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
453 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
454 "IPv6 DNS Container requested, but missing");
455 }
456 }
457 ctx.teid_remote := cpr.teidDataI.teidDataI;
458 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
459 ctx.eua := cpr.endUserAddress;
460 ctx.pco_neg := cpr.protConfigOptions;
461 setverdict(pass);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200462 }
463
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100464 function f_handle_update_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
465 var UpdatePDPContextResponseGGSN upr := ud.gtpc.gtpc_pdu.updatePDPContextResponse.updatePDPContextResponseGGSN;
466 if (exp_cause == '80'O and exp_cause == upr.cause.causevalue) {
467 ctx.teid_remote := upr.teidDataI.teidDataI;
468 ctx.teic_remote := upr.teidControlPlane.teidControlPlane;
469 if (ispresent(upr.protConfigOptions)) {
470 ctx.pco_neg := upr.protConfigOptions;
471 }
472 setverdict(pass);
473 } else if (exp_cause != '80'O and exp_cause == upr.cause.causevalue) {
474 setverdict(pass);
475 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100476 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
477 "UpdatePDPContextResp: cause expectancies didn't match");
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100478 }
479 }
480
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100481 private altstep as_DIA_Gx_CCR(DCC_NONE_CC_Request_Type req_type) runs on GT_CT {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100482 var PDU_DIAMETER rx_dia;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100483 [] Gx_UNIT.receive(tr_DIA_Gx_CCR(req_type := req_type)) -> value rx_dia {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100484 var template (omit) AVP avp;
485 var octetstring sess_id;
486 var AVP_Unsigned32 req_num;
487
488 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
489 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
490
491 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
492 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
493
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100494 Gx_UNIT.send(ts_DIA_Gx_CCA(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id,
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100495 req_type, req_num));
496 }
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100497 [] Gx_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100498 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
499 log2str("Received unexpected DIAMETER ", rx_dia));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100500 }
501 }
502
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200503 private function f_tr_DIA_Gy_CCR(template (omit) PdpContext ctx, DCC_NONE_CC_Request_Type req_type)
504 runs on GT_CT return template (present) PDU_DIAMETER
505 {
506 var template (present) PDU_DIAMETER tpl;
507 var charstring smf_origin_host := "smf.localdomain";
508 var template (present) octetstring imsi := ?;
509 var template (present) octetstring msisdn := ?;
510 var template (present) octetstring imeisv := ?;
511 var template (present) octetstring rat_type := ?;
512 var template (present) OCT4 charging_char := ?;
513 var template (present) OCT1 nsapi := ?;
514 if (not istemplatekind(ctx, "omit")) {
515 var PdpContext ctx_val := valueof(ctx);
516 imsi := char2oct(f_dec_TBCD(imsi_hex2oct(ctx_val.imsi)));
517 msisdn := char2oct(f_dec_TBCD(substr(ctx_val.msisdn, 1, lengthof(ctx_val.msisdn) -1)));
518 imeisv := char2oct(f_dec_TBCD(ctx_val.imeisv));
519 rat_type := ctx_val.ratType;
520 charging_char := char2oct(oct2str(ctx_val.charging_char));
521 nsapi := char2oct(hex2str(bit2hex(ctx_val.nsapi)));
522 }
523 select (req_type) {
524 case (INITIAL_REQUEST) {
525 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
526 avps := superset(
527 tr_AVP_SessionId,
528 tr_AVP_OriginHost(smf_origin_host),
529 tr_AVP_OriginRealm(g_gy_pars.origin_realm),
530 tr_AVP_DestinationRealm(g_gy_pars.origin_realm),
531 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
532 tr_AVP_ServiceContextId,
533 tr_AVP_CcReqType(req_type),
534 tr_AVP_CcReqNum(?),
535 tr_AVP_EventTimestamp(?),
536 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
537 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
538 tr_AVP_RequestedAction(DIRECT_DEBITING),
539 tr_AVP_3GPP_AoCRequestType,
540 tr_AVP_MultipleServicesIndicator,
541 tr_AVP_Multiple_Services_Credit_Control(content := superset(
542 tr_AVP_Requested_Service_Unit,
Pau Espin Pedrol6477d732022-06-03 12:04:40 +0200543 tr_AVP_PCC_3GPP_QoS_Information,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200544 tr_AVP_GI_3GPP_RatType(rat_type)
545 )),
546 tr_AVP_3GPP_ServiceInformation(content := superset(
547 tr_AVP_3GPP_PSInformation(content := superset(
548 tr_AVP_3GPP_ChargingId,
549 tr_AVP_3GPP_PDPType((IPv4,IPv6,IPv4v6)),
550 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
551 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_bind_ip_gtpc))),
552 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_ggsn_ip_gtpc))),
553 tr_AVP_3GPP_CalledStationId,
554 tr_AVP_3GPP_SelectionMode,
555 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
556 tr_AVP_3GPP_SGSNMCCMNC,
557 tr_AVP_3GPP_NSAPI(nsapi),
558 tr_AVP_3GPP_MS_TimeZone,
559 tr_AVP_3GPP_ULI,
560 tr_AVP_UserEquipmentInfo({
561 tr_AVP_UserEquipmentInfoType(IMEISV),
562 tr_AVP_UserEquipmentInfoValue(imeisv)
563 })
564 ))
565 ))
566 ));
567 }
568 case (UPDATE_REQUEST) {
569 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
570 avps := superset(
571 tr_AVP_SessionId,
572 tr_AVP_OriginHost(smf_origin_host),
573 tr_AVP_OriginRealm(g_gy_pars.origin_realm),
574 tr_AVP_DestinationRealm(g_gy_pars.origin_realm),
575 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
576 tr_AVP_ServiceContextId,
577 tr_AVP_CcReqType(req_type),
578 tr_AVP_CcReqNum(?),
579 tr_AVP_DestinationHost(?),
580 tr_AVP_EventTimestamp(?),
581 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
582 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
583 tr_AVP_RequestedAction(DIRECT_DEBITING),
584 tr_AVP_3GPP_AoCRequestType,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200585 tr_AVP_Multiple_Services_Credit_Control(content := superset(
586 tr_AVP_Requested_Service_Unit,
587 tr_AVP_Used_Service_Unit,
Pau Espin Pedrolcba0f6d2022-05-24 13:49:46 +0200588 /* tr_AVP_3GPP_Reporting_Reason, can be sometimes inside UsedServiceUnit */
Pau Espin Pedrol6477d732022-06-03 12:04:40 +0200589 tr_AVP_PCC_3GPP_QoS_Information,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200590 tr_AVP_GI_3GPP_RatType(rat_type)
591 )),
592 tr_AVP_3GPP_ServiceInformation(content := superset(
593 tr_AVP_3GPP_PSInformation(content := superset(
594 tr_AVP_3GPP_ChargingId,
595 /* tr_AVP_3GPP_PDPType, Only in INIT */
596 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
597 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_bind_ip_gtpc))),
598 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_ggsn_ip_gtpc))),
599 tr_AVP_3GPP_CalledStationId,
600 tr_AVP_3GPP_SelectionMode,
601 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
602 tr_AVP_3GPP_SGSNMCCMNC,
603 tr_AVP_3GPP_NSAPI(nsapi),
604 tr_AVP_3GPP_MS_TimeZone,
605 tr_AVP_3GPP_ULI,
606 tr_AVP_UserEquipmentInfo({
607 tr_AVP_UserEquipmentInfoType(IMEISV),
608 tr_AVP_UserEquipmentInfoValue(imeisv)
609 })
610 ))
611 ))
612 ));
613 }
614 case (TERMINATION_REQUEST) {
615 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
616 avps := superset(
617 tr_AVP_SessionId,
618 tr_AVP_OriginHost(smf_origin_host),
619 tr_AVP_OriginRealm(g_gy_pars.origin_realm),
620 tr_AVP_DestinationRealm(g_gy_pars.origin_realm),
621 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
622 tr_AVP_ServiceContextId,
623 tr_AVP_CcReqType(req_type),
624 tr_AVP_CcReqNum(?),
625 tr_AVP_DestinationHost(?),
626 tr_AVP_EventTimestamp(?),
627 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
628 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
629 tr_AVP_TerminationCause(?),
630 tr_AVP_RequestedAction(DIRECT_DEBITING),
631 tr_AVP_3GPP_AoCRequestType,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200632 tr_AVP_Multiple_Services_Credit_Control(content := superset(
633 /* tr_AVP_Requested_Service_Unit, Only in INIT and UPDATE */
634 tr_AVP_Used_Service_Unit,
Pau Espin Pedrolcba0f6d2022-05-24 13:49:46 +0200635 tr_AVP_3GPP_Reporting_Reason(FINAL),
Pau Espin Pedrol6477d732022-06-03 12:04:40 +0200636 tr_AVP_PCC_3GPP_QoS_Information,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200637 tr_AVP_GI_3GPP_RatType(rat_type)
638 )),
639 tr_AVP_3GPP_ServiceInformation(content := superset(
640 tr_AVP_3GPP_PSInformation(content := superset(
641 tr_AVP_3GPP_ChargingId,
642 /* tr_AVP_3GPP_PDPType, Only in INIT */
643 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
644 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_bind_ip_gtpc))),
645 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_ggsn_ip_gtpc))),
646 tr_AVP_3GPP_CalledStationId,
647 tr_AVP_3GPP_SelectionMode,
648 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
649 tr_AVP_3GPP_SGSNMCCMNC,
650 tr_AVP_3GPP_NSAPI(nsapi),
651 tr_AVP_3GPP_MS_TimeZone,
652 tr_AVP_3GPP_ULI,
653 tr_AVP_UserEquipmentInfo({
654 tr_AVP_UserEquipmentInfoType(IMEISV),
655 tr_AVP_UserEquipmentInfoValue(imeisv)
656 })
657 ))
658 ))
659 ));
660 }
661 }
662 return tpl;
663 }
664
665 private altstep as_DIA_Gy_CCR(template (omit) PdpContext ctx, DCC_NONE_CC_Request_Type req_type) runs on GT_CT {
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200666 [] Gy_UNIT.receive(f_tr_DIA_Gy_CCR(ctx, req_type := req_type)) -> value g_rx_gy {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100667 var template (value) PDU_DIAMETER tx_dia;
668 var template (omit) AVP avp;
669 var octetstring sess_id;
670 var AVP_Unsigned32 req_num;
671
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200672 avp := f_DIAMETER_get_avp(g_rx_gy, c_AVP_Code_BASE_NONE_Session_Id);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100673 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
674
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200675 avp := f_DIAMETER_get_avp(g_rx_gy, c_AVP_Code_DCC_NONE_CC_Request_Number);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100676 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
677 if (g_gy_validity_time > 0) {
Pau Espin Pedrol52562c92022-05-23 15:45:46 +0200678 if (g_gy_volume_threshold > 0) {
679 tx_dia := ts_DIA_Gy_CCA_ValidityTimeVolumeThreshold(g_rx_gy.hop_by_hop_id, g_rx_gy.end_to_end_id, sess_id,
680 req_type, req_num, g_gy_validity_time, g_gy_volume_threshold);
681 } else {
682 tx_dia := ts_DIA_Gy_CCA_ValidityTime(g_rx_gy.hop_by_hop_id, g_rx_gy.end_to_end_id, sess_id,
683 req_type, req_num, g_gy_validity_time);
684 }
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100685 } else {
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200686 tx_dia := ts_DIA_Gy_CCA(g_rx_gy.hop_by_hop_id, g_rx_gy.end_to_end_id, sess_id,
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100687 req_type, req_num);
688 }
689 Gy_UNIT.send(tx_dia);
690 }
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200691 [] Gy_UNIT.receive(PDU_DIAMETER:?) -> value g_rx_gy {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100692 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200693 log2str("Received unexpected DIAMETER Gy", g_rx_gy));
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100694 }
695 }
696
Harald Welte811651e2017-08-05 15:25:06 +0200697 /* send a PDP context activation */
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100698 function f_pdp_ctx_act(inout PdpContext ctx, template OCT1 exp_cause := '80'O) runs on GT_CT return CreatePDPContextResponse {
Harald Welte94ade362017-08-04 00:36:55 +0200699 var Gtp1cUnitdata ud;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100700 var CreatePDPContextResponse cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200701 var default d;
702
703 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200704 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx.imsi, g_restart_ctr,
Harald Welte811651e2017-08-05 15:25:06 +0200705 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200706 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200707 ctx.uli, ctx.charging_char, ctx.imeisv, ctx.ms_tz));
Harald Welte94ade362017-08-04 00:36:55 +0200708 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200709 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100710 if (Gx_PROC.checkstate("Connected")) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100711 as_DIA_Gx_CCR(INITIAL_REQUEST);
712 }
713 if (Gy_PROC.checkstate("Connected")) {
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200714 as_DIA_Gy_CCR(ctx, INITIAL_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100715 }
Harald Welte94ade362017-08-04 00:36:55 +0200716 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200717 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200718 f_handle_create_req(ctx, ud, exp_cause);
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100719 cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Harald Welte94ade362017-08-04 00:36:55 +0200720 }
721 }
722 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200723 T_default.stop;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100724 return cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200725 }
726
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200727 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
728 var Gtp1cUnitdata ud;
729 var default d;
730
731 T_default.start;
732 d := activate(pingpong());
733 alt {
734 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
735 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
736 setverdict(pass);
737 } else if (not istemplatekind(expect_cause, "omit") and
738 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
739 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
740 setverdict(pass);
741 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100742 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
743 "DeletePDPContextReq: cause expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200744 }
745
746 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
747 setverdict(pass);
748 } else {
749 setverdict(fail);
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100750 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
751 "DeletePDPContextReq: tearDownIndicator expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200752 }
753 }
754 }
755 deactivate(d);
756 T_default.stop;
757 }
758
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +0100759 function f_pdp_ctx_del(PdpContext ctx, template BIT1 teardown_ind, OCT1 expect_causevalue := '80'O, boolean expect_diameter := true) runs on GT_CT {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200760 var Gtp1cUnitdata ud;
761 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200762 var OCT4 expect_teid;
763
764 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
765 message with cause value "Non existent" shall be zero. */
766 if (expect_causevalue == 'C0'O) {
767 expect_teid := '00000000'O;
768 } else {
769 expect_teid := ctx.teic;
770 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200771
Harald Welte41575e92017-08-13 13:49:57 +0200772 f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, ctx.teic_remote, ctx.nsapi, teardown_ind));
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200773 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200774 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100775 if (Gx_PROC.checkstate("Connected") and expect_diameter) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100776 as_DIA_Gx_CCR(TERMINATION_REQUEST);
777 }
778 if (Gy_PROC.checkstate("Connected") and expect_diameter) {
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200779 as_DIA_Gy_CCR(ctx, TERMINATION_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100780 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200781 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200782 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
783 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200784 setverdict(pass);
785 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100786 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
787 "DeletePDPContextResp: cause expectancies didn't match");
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200788 }
789 }
790 }
791 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200792 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200793 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100794
795 /* send a Update PdP Context Request, expect Response */
796 function f_pdp_ctx_update(inout PdpContext ctx, OCT1 exp_cause := '80'O, template (omit) OCT4 new_teid := omit, template (omit) OCT4 new_teic := omit) runs on GT_CT {
797 var Gtp1cUnitdata ud;
798 var default d;
799
800 if (not istemplatekind(new_teid, "omit")) {
801 ctx.teid := valueof(new_teid);
802 }
803 if (not istemplatekind(new_teic, "omit")) {
804 ctx.teic := valueof(new_teic);
805 }
806
807 log("sending UpdatePDP");
808 f_send_gtpc(ts_GTPC_UpdatePDP(g_peer_c, ctx.teic_remote, g_c_seq_nr, ctx.imsi, g_restart_ctr,
809 ctx.teid, ctx.teic, ctx.nsapi, g_sgsn_ip_c, g_sgsn_ip_u,
810 ctx.pco_req, ctx.ratType, ctx.uli));
811 T_default.start;
812 d := activate(pingpong());
813 alt {
814 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, updatePDPContextResponse, ctx.teic)) -> value ud {
815 f_handle_update_req(ctx, ud, exp_cause);
816 }
817 }
818 deactivate(d);
819 T_default.stop;
820 }
821
Harald Welte811651e2017-08-05 15:25:06 +0200822 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
823 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
824 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
825 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200826
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200827 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100828 template (value) PDU_ICMP ts_ICMPv4_ERQ(octetstring data := ''O) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100829 echo := {
830 type_field := 8,
831 code := 0,
832 checksum := '0000'O,
833 identifier := '0345'O,
834 sequence_number := '0001'O,
Pau Espin Pedrol52562c92022-05-23 15:45:46 +0200835 data := data
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100836 }
837 }
838
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200839 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100840 template (present) PDU_ICMP tr_ICMPv4_ERQ := {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100841 echo := {
842 type_field := 8,
843 code := 0,
844 checksum := ?,
845 identifier := ?,
846 sequence_number := ?,
847 data := ?
848 }
849 }
850
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200851 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100852 template (present) PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100853 echo_reply := {
854 type_field := 0,
855 code := 0,
856 checksum := ?,
857 identifier := ?,
858 sequence_number := ?,
859 data := data
860 }
861 }
862
863 /* template for receiving/matching an ICMPv6 Destination Unreachable */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100864 template (present) PDU_ICMP tr_ICMPv4_DU := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100865 destination_unreachable := {
866 type_field := 1,
867 code := ?,
868 checksum := ?,
869 unused := ?,
870 original_ip_msg := ?
871 }
872 }
873
874 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100875 template (value) IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100876 header := {
877 ver := 4,
878 hlen := 5,
879 tos := 0,
880 tlen := tlen,
881 id := 35902,
882 res := '0'B,
883 dfrag := '1'B,
884 mfrag := '0'B,
885 foffset := 0,
886 ttl := 64,
887 proto := proto,
888 cksum := 0,
889 srcaddr := srcaddr,
890 dstaddr := dstaddr
891 },
892 ext_headers := omit,
893 payload := payload
894 }
895
Harald Welte231b9412017-08-09 17:16:31 +0200896 /* template to generate a 'Prefix Information' ICMPv6 option */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100897 template (value) OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200898 prefixInformation := {
899 typeField := 3,
900 lengthIndicator := 8,
901 prefixLength := prefix_len,
902 reserved1 := '000000'B,
903 a_Bit := '0'B,
904 l_Bit := '0'B,
905 validLifetime := oct2int('FFFFFFFF'O),
906 preferredLifetime := oct2int('FFFFFFFF'O),
907 reserved2 := '00000000'O,
908 prefix := prefix
909 }
910 }
911
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200912 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100913 template (value) PDU_ICMPv6 ts_ICMPv6_ERQ := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100914 echoRequest := {
915 typeField := 128,
916 code := 0,
917 checksum := '0000'O,
918 identifier := 0,
919 sequenceNr := 0,
920 data := ''O
921 }
922 }
923
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200924 /* template for sending an ICMPv6 router solicitation */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100925 template (value) PDU_ICMPv6 ts_ICMPv6_RS := {
Harald Welte231b9412017-08-09 17:16:31 +0200926 routerSolicitation := {
927 typeField := 133,
928 code := 0,
929 checksum := '0000'O,
930 reserved := '00000000'O,
931 /* TODO: do we need 'Source link-layer address' ? */
932 options := omit
933 }
934 }
935
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200936 /* template for sending an ICMPv6 router advertisement */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100937 template (value) PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200938 routerAdvertisement := {
939 typeField := 134,
940 code := 0,
941 checksum := '0000'O,
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100942 curHopLimit := 0,
Harald Welte231b9412017-08-09 17:16:31 +0200943 reserved := '000000'B,
944 o_Bit := '0'B,
945 m_Bit := '0'B,
946 routerLifetime := oct2int('FFFF'O),
947 reachableTime := oct2int('FFFFFFFF'O),
948 retransTimer := oct2int('FFFFFFFF'O),
949 options := {
950 ts_ICMP6_OptPrefix(prefix, prefix_len)
951 }
952 }
953 }
954
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200955 /* template for sending an ICMPv6 neighbor solicitation */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100956 template (value) PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
Harald Welte231b9412017-08-09 17:16:31 +0200957 neighborSolicitation := {
958 typeField := 135,
959 code := 0,
960 checksum := '0000'O,
961 reserved := '00000000'O,
962 targetAddress := target_addr,
963 /* TODO: do we need 'Source link-layer address' ? */
964 options := omit
965 }
966 }
967
968 /* derive ICMPv6 link-local address from lower 64bit of link_id */
969 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100970 template (present) OptionField tr_ICMP6_OptPrefix(template (present) OCT16 prefix, template (present) INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200971 prefixInformation := {
972 typeField := 3,
973 lengthIndicator := 4,
974 prefixLength := prefix_len,
975 reserved1 := ?,
976 a_Bit := ?,
977 l_Bit := ?,
978 validLifetime := ?,
979 preferredLifetime := ?,
980 reserved2 := ?,
981 prefix := prefix
982 }
983 }
984
Pau Espin Pedrolae04c792023-12-05 14:51:42 +0100985 /* template for receiving/matching an ICMPv6 'MTU' option, rfc4861 4.6.4 */
986 template (present) OptionField tr_ICMP6_OptMTU(template (present) integer mtu := ?) := {
987 mTU := {
988 typeField := 5,
989 lengthIndicator := 1,
990 reserved := ?,
991 mTU_Value := mtu
992 }
993 }
994
Harald Welte231b9412017-08-09 17:16:31 +0200995 /* template for receiving/matching an ICMPv6 router advertisement */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100996 template (present) PDU_ICMPv6 tr_ICMPv6_RA(template (present) OCT16 prefix, template (present) INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200997 routerAdvertisement := {
998 typeField := 134,
999 code := 0,
1000 checksum := ?,
1001 curHopLimit := ?,
1002 reserved := ?,
1003 o_Bit := '0'B,
1004 m_Bit := '0'B,
1005 routerLifetime := ?,
1006 reachableTime := ?,
1007 retransTimer := ?,
Pau Espin Pedrolae04c792023-12-05 14:51:42 +01001008 options := ({ tr_ICMP6_OptPrefix(prefix, prefix_len) },
1009 { tr_ICMP6_OptPrefix(prefix, prefix_len), tr_ICMP6_OptMTU }
1010 )
Harald Welte231b9412017-08-09 17:16:31 +02001011 }
1012 }
1013
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001014 /* template for receiving/matching an ICMPv6 Destination Unreachable */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001015 template (present) PDU_ICMPv6 tr_ICMPv6_DU := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001016 destinationUnreachable := {
1017 typeField := 1,
1018 code := ?,
1019 checksum := ?,
1020 unused := ?,
1021 originalIpMsg := ?
1022 }
1023 }
1024
Stefan Sperling6cd217e2018-03-30 15:17:34 +02001025 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001026 template (present) PDU_ICMPv6 tr_ICMPv6_ERQ := {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001027 echoRequest := {
1028 typeField := 128,
1029 code := 0,
1030 checksum := ?,
1031 identifier := ?,
1032 sequenceNr := ?,
1033 data := ?
1034 }
1035 }
1036
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001037 /* template for receiving/matching an ICMPv6 echo reply */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001038 template (present) PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001039 echoReply := {
1040 typeField := 129,
1041 code := 0,
1042 checksum := ?,
1043 identifier := ?,
1044 sequenceNr := ?,
1045 data := data
1046 }
1047 }
1048
Harald Welte231b9412017-08-09 17:16:31 +02001049 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001050 template (value) IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
Harald Welte231b9412017-08-09 17:16:31 +02001051 header := {
1052 ver := 6,
1053 trclass := 0,
1054 flabel := 0,
1055 plen := 0,
1056 nexthead := nexthead,
1057 hlim := hlim,
1058 srcaddr := srcaddr,
1059 dstaddr := dstaddr
1060 },
1061 ext_headers := omit,
1062 payload := payload
1063 }
1064
1065 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
1066 return 'FE80000000000000'O & substr(link_id, 8, 8);
1067 }
1068
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001069 function f_ipv6_global(in OCT16 link_id) return OCT16 {
1070 return substr(link_id, 0, 8) & '1234123412341234'O;
1071 }
1072
1073 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
1074 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
1075 var integer i;
1076 var octetstring res := substr(addr, 0, prefix);
1077 for (i := prefix; i < lengthof(addr); i := i + 1) {
1078 var octetstring a := addr[i] xor4b '11'O;
1079 res := res & a;
1080 }
1081 return res;
1082 }
1083
Harald Welte231b9412017-08-09 17:16:31 +02001084 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
1085 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
1086 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
1087 }
1088
1089 /* generate and encode ICMPv6 router solicitation */
1090 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
1091 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
1092 var OCT16 saddr := f_ipv6_link_local(link_id);
1093
1094 var octetstring tmp;
1095 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
1096 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
1097
1098 return f_IPv6_enc(ip6);
1099 }
1100
Pau Espin Pedrol57604212022-02-14 16:54:18 +01001101 /* Get link-id from PDP Context EUA */
1102 function f_ctx_get_ipv6_interface_id(in PdpContext ctx) return OCT16 {
1103 var OCT16 interface_id;
1104 if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
1105 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1106 } else if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv6)) {
1107 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
1108 } else {
1109 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected request to submit icmpv6 rs in IPv4 PDP context");
1110 }
1111 return interface_id;
1112 }
1113
Harald Welte231b9412017-08-09 17:16:31 +02001114 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
1115 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +01001116 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001117 return f_gen_icmpv6_router_solicitation(interface_id);
1118 }
1119
1120 /* generate and encode ICMPv6 neighbor solicitation */
1121 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
1122 var octetstring tmp;
1123 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
1124 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
1125 return f_IPv6_enc(ip6);
1126 }
1127
1128 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
1129 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +01001130 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001131 var OCT16 link_local := f_ipv6_link_local(interface_id);
1132 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
1133
1134 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
1135 }
1136
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001137 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02001138 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr, octetstring pl := ''O) return octetstring {
1139 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ(pl)));
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001140 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
1141 var octetstring data := f_IPv4_enc(ip4);
1142 var OCT2 cksum := f_IPv4_checksum(data);
1143 data[10] := cksum[0];
1144 data[11] := cksum[1];
1145 return data;
1146 }
1147
1148 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
1149 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
1150 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
1151 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
1152 var octetstring data := f_IPv6_enc(ip6);
1153 return data;
1154 }
1155
1156 /* Wait for ICMPv4 from GTP */
1157 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +02001158 var Gtp1uUnitdata ud;
1159 T_default.start;
1160 alt {
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001161 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ctx.teid)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +02001162 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001163 setverdict(fail);
1164 stop;
1165 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001166 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1167 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
1168 if (ip4.header.ver != 4) {
1169 repeat;
1170 }
1171 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
1172 if (not match(icmp4, expected)) {
1173 repeat;
1174 }
1175 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001176 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Oliver Smith9daae3e2024-02-28 11:54:22 +01001177 setverdict(fail, "Received wrong local TEID");
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001178 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001179 [] GTPU.receive { setverdict(fail); }
1180 [] T_default.timeout { setverdict(fail); }
1181 }
1182 T_default.stop;
1183 }
1184
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001185 /* Wait for ICMPv4 echo request from GTP */
1186 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
1187 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
1188 }
1189
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001190 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
1191 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
1192 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
1193 }
1194
1195 /* Wait for ICMPv6 from GTP */
1196 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
1197 var Gtp1uUnitdata ud;
1198 T_default.start;
1199 alt {
Harald Welte231b9412017-08-09 17:16:31 +02001200 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +02001201 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Pau Espin Pedrol9c1c2ae2023-12-05 14:24:49 +01001202 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1203 log2str("Received GTPU with wrong txseq while waiting for ICMPv6: ", expected));
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001204 }
Harald Welte231b9412017-08-09 17:16:31 +02001205 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1206 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001207 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +02001208 repeat;
1209 }
1210 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001211 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +02001212 repeat;
1213 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001214 /* We are waiting for RA, update ctx */
1215 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
1216 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
1217 log("RA with /64 prefix ", ctx.ip6_prefix);
1218 }
Harald Welte231b9412017-08-09 17:16:31 +02001219 }
1220 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
Pau Espin Pedrol9c1c2ae2023-12-05 14:24:49 +01001221 [] GTPU.receive {
1222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1223 log2str("Received unexpected GTPU while waiting for ICMPv6: ", expected));
1224 }
1225 [] T_default.timeout {
1226 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1227 log2str("Timeout waiting for ICMPv6: ", expected));
1228 }
Harald Welte231b9412017-08-09 17:16:31 +02001229 }
1230 T_default.stop;
1231 }
1232
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001233 /* wait for GGSN to send us an ICMPv6 router advertisement */
1234 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
1235 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
1236 }
1237
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001238 /* Wait for ICMPv6 echo request from GTP */
1239 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
1240 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
1241 }
1242
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001243 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
1244 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
1245 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
1246 }
1247
Oliver Smithee6a0882019-03-08 11:05:46 +01001248 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
1249 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
1250 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1251 return f_gen_icmpv6_router_solicitation(interface_id);
1252 }
1253
1254 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
1255 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
1256 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1257 var OCT16 link_local := f_ipv6_link_local(interface_id);
1258 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
1259
1260 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
1261 }
1262
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001263 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
1264 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
1265 T_default.start;
1266 alt {
1267 [] GTPU.receive { setverdict(fail); }
1268 [] T_default.timeout { }
1269 }
1270 T_default.stop;
1271 }
1272
Harald Welte79737b42019-04-10 10:39:30 +02001273 /* list of protocols where we don't accept duplicates */
1274 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
1275 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
1276 var integer i;
1277 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
1278 if (id == protocol_ids_nodupes[i]) {
1279 return false;
1280 }
1281 }
1282 return true;
1283 }
1284
1285 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
1286 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
1287 var OCT2List protocol_ids := {};
1288 var integer i, j;
1289 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
1290 var OCT2 id := pco.protocols[i].protocolID;
1291 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
1292 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
1293 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
1294 }
1295 }
1296 protocol_ids := protocol_ids & { id };
1297 }
1298 }
1299
Harald Welte0ef285b2017-08-13 20:06:01 +02001300 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +02001301 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +02001302 f_init();
Harald Welte231b9412017-08-09 17:16:31 +02001303
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001304 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welte811651e2017-08-05 15:25:06 +02001305 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +02001306 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001307 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001308 }
1309
Harald Welte0ef285b2017-08-13 20:06:01 +02001310 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001311 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
1312 f_init();
1313
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001314 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001315 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1316 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001317
Harald Welte79737b42019-04-10 10:39:30 +02001318 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001319 /* verify PCO contains both primary and secondary DNS */
1320 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1321 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1322 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1323 }
1324
1325 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1326 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1327 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1328 }
1329
Harald Welteed7a1772017-08-09 20:26:20 +02001330 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001331 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001332 }
1333
Harald Welte0ef285b2017-08-13 20:06:01 +02001334 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +02001335 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
1336 f_init();
1337
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001338 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001339 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1340 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001341
Harald Welte79737b42019-04-10 10:39:30 +02001342 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +02001343 //f_send_gtpu(ctx, c_router_solicit);
1344 //f_send_gtpu(ctx, c_neigh_solicit);
1345
1346 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1347 f_wait_rtr_adv(ctx);
1348 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1349
Harald Welte811651e2017-08-05 15:25:06 +02001350 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001351 f_shutdown_helper();
Harald Welte94ade362017-08-04 00:36:55 +02001352 }
1353
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001354 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
1355 Test we can send ICMPv6 ping over GTPU to DNS server. */
1356 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
1357 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001358 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001359 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1360 f_pdp_ctx_act(ctx);
1361
1362 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1363 f_wait_rtr_adv(ctx);
1364 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1365
1366 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1367
1368 /* Check if we can use valid link-local src addr. */
1369 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1370 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
Pau Espin Pedrolb63d85f2022-02-07 16:11:47 +01001371 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
1372 f_wait_icmp6_echo_reply(ctx);
1373 } else {
1374 f_wait_gtpu_fail(ctx);
1375 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001376
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001377 /* Check if we can use valid global src addr, should work */
1378 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1379 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
1380 f_wait_icmp6_echo_reply(ctx);
1381
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001382 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001383 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001384 }
1385
1386 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1387 testcase TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr() runs on GT_CT {
1388 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001389 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001390 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1391 f_pdp_ctx_act(ctx);
1392
1393 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1394 f_wait_rtr_adv(ctx);
1395 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1396
1397 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1398 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1399 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1400 f_wait_gtpu_fail(ctx);
1401
1402 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001403 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001404 }
1405
1406 /* Assert that packets with wrong global src addr are dropped by GGSN */
1407 testcase TC_pdp6_act_deact_gtpu_access_wrong_global_saddr() runs on GT_CT {
1408 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001409 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001410 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1411 f_pdp_ctx_act(ctx);
1412
1413 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1414 f_wait_rtr_adv(ctx);
1415 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1416
1417 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1418 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001419 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1420 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
1421 f_wait_gtpu_fail(ctx);
1422
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001423 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001424 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001425 }
1426
1427 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped */
1428 testcase TC_pdp6_act_deact_gtpu_access_ipv4_apn6() runs on GT_CT {
1429 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001430 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001431 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1432 f_pdp_ctx_act(ctx);
1433
1434 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1435 f_wait_rtr_adv(ctx);
1436 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1437
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001438 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
1439 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
1440 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
1441 f_wait_gtpu_fail(ctx);
1442
1443 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001444 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001445 }
1446
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001447 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1448 testcase TC_pdp6_clients_interact() runs on GT_CT {
1449 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001450 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1451 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001452 f_pdp_ctx_act(ctxA);
1453 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
1454 f_wait_rtr_adv(ctxA);
1455 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
1456
1457 f_pdp_ctx_act(ctxB);
1458 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
1459 f_wait_rtr_adv(ctxB);
1460 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
1461
1462 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1463 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1464 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1465 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1466
1467 /* Validate if clients can interact using ll addr. */
1468 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1469 f_wait_gtpu_fail(ctxB);
1470
1471 /* Validate if clients can interact using global addr. */
1472 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1473 f_wait_gtpu_fail(ctxB);
1474
1475 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001476 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001477 f_shutdown_helper();
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001478 }
1479
Harald Welte0ef285b2017-08-13 20:06:01 +02001480 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +02001481 testcase TC_pdp4_act_deact() runs on GT_CT {
1482 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001483 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001484 f_pdp_ctx_act(ctx);
1485 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001486 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001487 }
1488
Harald Welte0ef285b2017-08-13 20:06:01 +02001489 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +02001490 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
1491 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001492 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1493 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrolcff72f82024-01-26 16:58:48 +01001494 var uint8_t ipcp_req_id := oct2int(f_rnd_octstring(1));
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001495 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolcff72f82024-01-26 16:58:48 +01001496 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP(ipcp_req_id));
Harald Welteed7a1772017-08-09 20:26:20 +02001497 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001498 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +01001499 /* verify IPCP is at all contained */
1500 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1501 setverdict(fail, "IPCP not found in PCO");
1502 }
1503 /* verify IPCP contains both primary and secondary DNS */
1504 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolcff72f82024-01-26 16:58:48 +01001505 if (not match(ipcp, tr_IPCP_Ack_DNS(ipcp_req_id, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1506 if (not match(ipcp, tr_IPCP_Ack_DNS(ipcp_req_id))) {
1507 if (not match(ipcp, tr_IPCP_Ack_DNS(?))) {
1508 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1509 } else {
1510 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected identifier");
1511 }
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001512 } else {
1513 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1514 }
Harald Welte71a36022017-12-04 18:55:58 +01001515 }
Harald Welteed7a1772017-08-09 20:26:20 +02001516 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001517 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001518 }
1519
Harald Weltef8298542019-04-10 10:15:28 +02001520 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
1521 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
1522 f_init();
1523 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1524 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001525 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltef8298542019-04-10 10:15:28 +02001526 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1527 f_pdp_ctx_act(ctx);
1528 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1529 /* verify IPCP is at all contained */
1530 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1531 setverdict(fail, "IPCP not found in PCO");
1532 }
1533 /* verify IPCP contains both primary and secondary DNS */
1534 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1535 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1536 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1537 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1538 } else {
1539 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1540 }
1541 }
1542 /* verify that PAP is contained */
1543 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1544 setverdict(fail, "PAP not found in PCO");
1545 }
1546 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1547 if (not match(pap, tr_PAP_AuthAck)) {
1548 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1549 }
1550 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001551 f_shutdown_helper();
Harald Weltef8298542019-04-10 10:15:28 +02001552 }
1553
Harald Welte0ef285b2017-08-13 20:06:01 +02001554 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001555 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1556 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001557 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001558 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001559 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001560
Harald Welte79737b42019-04-10 10:39:30 +02001561 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001562 /* verify PCO contains both primary and secondary DNS */
1563 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1564 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1565 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1566 }
1567
1568 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1569 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1570 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1571 }
1572
Harald Welteed7a1772017-08-09 20:26:20 +02001573 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001574 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001575 }
1576
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001577 /* Test PDP context activation for dynamic IPv4 EUA.
1578 Test we can send ICMPv6 ping over GTPU to DNS server. */
1579 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1580 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001581 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001582 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1583 f_pdp_ctx_act(ctx);
1584
Harald Welte79737b42019-04-10 10:39:30 +02001585 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001586 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1587
1588 /* Check if we can use valid global src addr, should work */
1589 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1590 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1591 f_wait_icmp4_echo_reply(ctx);
1592
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001593 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001594 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001595 }
1596
1597 /* Assert that packets with wrong global src addr are dropped by GGSN */
1598 testcase TC_pdp4_act_deact_gtpu_access_wrong_saddr() runs on GT_CT {
1599 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001600 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001601 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1602 f_pdp_ctx_act(ctx);
1603
1604 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1605 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1606 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001607 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1608 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1609 f_wait_gtpu_fail(ctx);
1610
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001611 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001612 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001613 }
1614
1615 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1616 testcase TC_pdp4_act_deact_gtpu_access_ipv6_apn4() runs on GT_CT {
1617 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001618 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001619 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1620 f_pdp_ctx_act(ctx);
1621
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001622 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1623 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1624 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1625 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001626
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001627 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001628 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001629 }
1630
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001631 /* Helper function for tests below. */
1632 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001633 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001634 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1635 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001636 f_pdp_ctx_act(ctxA);
1637 f_pdp_ctx_act(ctxB);
1638 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1639 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1640 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1641 f_wait_icmp4_echo_request(ctxB);
1642
1643 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001644 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001645 }
1646
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001647 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1648 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001649 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001650 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001651 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001652 }
1653
1654 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1655 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001656 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001657 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001658 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001659 }
1660
Harald Weltedca80052017-08-13 20:01:38 +02001661 testcase TC_echo_req_resp() runs on GT_CT {
1662 f_init();
1663 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1664 T_default.start;
1665 alt {
1666 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1667 [] GTPC.receive { repeat; };
1668 [] T_default.timeout { setverdict(fail); }
1669 }
1670 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001671 f_shutdown_helper();
Harald Weltedca80052017-08-13 20:01:38 +02001672 }
1673
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001674 testcase TC_echo_req_resp_gtpu() runs on GT_CT {
1675 f_init();
1676 GTPU.send(ts_GTPU_PING(g_peer_u, g_d_seq_nr));
1677 T_default.start;
1678 alt {
1679 [] GTPU.receive(tr_GTPU_PONG(g_peer_u)) { setverdict(pass); };
1680 [] GTPU.receive { repeat; };
1681 [] T_default.timeout { setverdict(fail); }
1682 }
1683 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001684 f_shutdown_helper();
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001685 }
1686
Philipp Maier33e52612018-05-30 17:22:02 +02001687 /* Test if the parser can cope with PCO that only contain either a
1688 * single primary DNS or a secondary DNS. */
1689 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1690
1691 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1692 * the test is executed.
1693 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1694
1695 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001696 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001697 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1698 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1699 var octetstring pco_neg_dns;
1700 var octetstring pco_neg_dns_expected;
1701
1702 /* PCO with primary DNS only */
1703 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1704 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001705 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001706 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1707 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1708 /* Note: The prepended hex bytes encode the following information:
1709 * 0x02 = Configuration ACK
1710 * 0x00 = Identifier
1711 * 0x000a = Length
1712 * 0x81 = Type (Primary DNS Server Address)
1713 * 0x06 = Length
1714 * (4 byte IP-Address appended) */
1715 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1716 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1717 }
1718 f_pdp_ctx_del(ctx, '1'B);
1719
1720 /* PCO with secondary DNS only */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001721 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001722 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1723 f_pdp_ctx_act(ctx);
1724 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1725 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1726 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1727 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1728 }
1729 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001730 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001731 }
1732
1733 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1734 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1735 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1736 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1737
1738 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1739 * the test is executed.
1740 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1741
1742 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001743 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001744 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1745 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1746 var octetstring pco_neg_dns;
1747 var octetstring pco_neg_dns_expected;
1748
1749 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1750 f_pdp_ctx_act(ctx);
1751
1752 /* Check if primary DNS is contained */
1753 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1754 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1755 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1756 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1757 }
Philipp Maier33e52612018-05-30 17:22:02 +02001758
1759 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001760 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1761 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001762 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1763 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1764 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1765 }
1766 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001767 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001768 }
1769
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001770 /* Validate that SUT updates remote TEIC when requested through UpdatePDPContextRequest */
1771 testcase TC_pdp4_act_update_teic() runs on GT_CT {
1772 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001773 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001774 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1775 f_pdp_ctx_act(ctx);
1776
1777 /* UpdatePDPContestRequest changing the local TEIC */
1778 var OCT4 new_teic := ctx.teic;
1779 new_teic[3] := new_teic[3] xor4b '11'O;
1780 f_pdp_ctx_update(ctx, new_teic := new_teic);
1781
1782 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001783 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001784 }
1785
1786 /* Validate that SUT updates remote TEID when requested through UpdatePDPContextRequest */
1787 testcase TC_pdp4_act_update_teid() runs on GT_CT {
1788 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001789 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001790 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1791 f_pdp_ctx_act(ctx);
1792
1793 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1794 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1795 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1796
1797 /* Data is sent (back) to the local TEID established during CreatePDPContext */
1798 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1799 f_wait_icmp4_echo_reply(ctx);
1800
1801 /* UpdatePDPContestRequest changing the local TEID */
1802 var OCT4 new_teid := ctx.teid;
1803 new_teid[3] := new_teid[3] xor4b '11'O;
1804 f_pdp_ctx_update(ctx, new_teid := new_teid);
1805
1806 /* Check if we can send data after updating the PDP context. Answer should be sent to the new TEID */
1807 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1808 f_wait_icmp4_echo_reply(ctx);
1809
1810 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001811 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001812 }
1813
Oliver Smithee6a0882019-03-08 11:05:46 +01001814 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1815 testcase TC_pdp46_act_deact() runs on GT_CT {
1816 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001817 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001818 f_pdp_ctx_act(ctx);
1819 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001820 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001821 }
1822
1823 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1824 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1825 f_init();
1826 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1827 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001828 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001829 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1830 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001831 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001832 /* verify IPCP is at all contained */
1833 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1834 setverdict(fail, "IPCP not found in PCO");
1835 }
Harald Welte79737b42019-04-10 10:39:30 +02001836 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001837 /* verify IPCP contains both primary and secondary IPv4 DNS */
1838 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1839 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1840 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1841 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1842 } else {
1843 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1844 }
1845 }
1846 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001847 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001848 }
1849
1850 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1851 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1852 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001853 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001854 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1855 f_pdp_ctx_act(ctx);
1856
1857 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1858 f_wait_rtr_adv(ctx);
1859 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1860
1861 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001862 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001863 }
1864
1865 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1866 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1867 f_init();
1868
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001869 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001870 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1871 f_pdp_ctx_act(ctx);
1872
Harald Welte79737b42019-04-10 10:39:30 +02001873 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001874 /* verify PCO contains both primary and secondary IPv4 DNS */
1875 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1876 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1877 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1878 }
1879
1880 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1881 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1882 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1883 }
1884
1885 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001886 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001887 }
1888
1889 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1890 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1891 f_init();
1892
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001893 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001894 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1895 f_pdp_ctx_act(ctx);
1896
Harald Welte79737b42019-04-10 10:39:30 +02001897 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001898 /* verify PCO contains both primary and secondary IPv6 DNS */
1899 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1900 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1901 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1902 }
1903
1904 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1905 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1906 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1907 }
1908
1909 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001910 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001911 }
1912
1913 /* Test PDP context activation for dynamic IPv4v6 EUA.
1914 Test we can send ICMPv6 ping over GTPU to DNS server. */
1915 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1916 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001917 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001918 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1919 f_pdp_ctx_act(ctx);
1920
1921 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1922
1923 /* Check if we can use valid global src addr, should work */
1924 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1925 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1926 f_wait_icmp4_echo_reply(ctx);
1927
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001928 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001929 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001930 }
1931
1932 /* Assert that packets with wrong ipv4 src addr are dropped by GGSN on APN IPv4v6 */
1933 testcase TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4() runs on GT_CT {
1934 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001935 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001936 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1937 f_pdp_ctx_act(ctx);
1938
1939 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1940 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
Oliver Smithee6a0882019-03-08 11:05:46 +01001941 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1942 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1943 f_wait_gtpu_fail(ctx);
1944
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001945 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001946 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001947 }
1948
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001949 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1950 testcase TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6() runs on GT_CT {
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001951 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001952 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001953 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1954 f_pdp_ctx_act(ctx);
1955
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001956 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1957 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1958 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1959 f_wait_gtpu_fail(ctx);
1960
1961 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001962 f_shutdown_helper();
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001963 }
1964
1965 /* Assert that packets with wrong ipv6 global src addr are dropped by GGSN on APN IPv4v6 */
1966 testcase TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6() runs on GT_CT {
1967 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001968 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001969 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1970 f_pdp_ctx_act(ctx);
1971
1972 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1973 f_wait_rtr_adv(ctx);
1974 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1975
1976 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1977 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1978 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1979 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
Oliver Smithee6a0882019-03-08 11:05:46 +01001980 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001981
Oliver Smithee6a0882019-03-08 11:05:46 +01001982 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001983 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001984 }
1985
1986 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1987 testcase TC_pdp46_clients_interact() runs on GT_CT {
1988 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001989 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1990 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001991 f_pdp_ctx_act(ctxA);
1992 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1993 f_wait_rtr_adv(ctxA);
1994 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1995
1996 f_pdp_ctx_act(ctxB);
1997 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1998 f_wait_rtr_adv(ctxB);
1999 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
2000
2001 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
2002 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
2003 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
2004 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
2005
2006 /* Validate if clients can interact using ll addr. */
2007 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
2008 f_wait_gtpu_fail(ctxB);
2009
2010 /* Validate if clients can interact using global addr. */
2011 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
2012 f_wait_gtpu_fail(ctxB);
2013
2014 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02002015 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002016 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01002017 }
2018
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002019 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
2020 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002021 const OCT1 cause_accept := '80'O; /* Normal accept cause */
2022 const OCT1 cause_new_pdp_type := '81'O; /* Cause: New PDP type due to network preference */
2023 const OCT1 cause_unknown_pdp := 'DC'O; /* Cause: Unknown PDP address or PDP type */
2024 var CreatePDPContextResponse cpr;
2025
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002026 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002027 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002028 cpr := f_pdp_ctx_act(ctx46, (cause_unknown_pdp, cause_new_pdp_type));
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002029
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002030 if (cpr.cause.causevalue == cause_new_pdp_type) {
2031 /* 3GPP TS 23.060 sec 9.2.1: "If the MS requests PDP type IPv4v6,
2032 * but the operator preferences dictate the use of a single IP
2033 * version only, the PDP type shall be changed to a single address
2034 * PDP type (IPv4 or IPv6) and a reason cause shall be returned to
2035 * the MS indicating that only the assigned PDP type is allowed. In
2036 * this case, the MS shall not request another PDP context for the
2037 * other PDP type during the existence of the PDP context." */
2038 f_pdp_ctx_del(ctx46, '1'B);
2039 } else {
2040 /* 3GPP TS 23.060 sec 9.2.1 NOTE 5: If the MS requests PDP type
2041 * IPv4v6, and the PDP context is rejected due to "unknown PDP
2042 * type", the MS can attempt to establish dual-stack connectivity
2043 * by performing two PDP context request procedures to activate an
2044 * IPv4 PDP context and an IPv6 PDP context, both to the same APN. A
2045 * typical MS first attempts v4v6, and if rejected, then tries v4
2046 * and v6 separetly */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002047 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002048 f_pdp_ctx_act(ctx4, cause_accept); /* Normal accept cause */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002049
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002050 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002051 f_pdp_ctx_act(ctx6, cause_unknown_pdp); /* Cause: Unknown PDP address or PDP type */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002052
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002053 f_pdp_ctx_del(ctx4, '1'B);
2054 }
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002055 f_shutdown_helper();
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002056 }
2057
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002058 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
2059 testcase TC_pdp_act2_recovery() runs on GT_CT {
2060 var Gtp1cUnitdata ud;
2061 var default d;
2062 var boolean ctxA_deleted := false;
2063 var boolean ctxB_created := false;
2064
2065 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002066 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2067 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002068 f_pdp_ctx_act(ctxA);
2069
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06002070 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002071
2072 log("sending 2nd CreatePDP (recovery increased)");
2073 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
2074 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
2075 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
2076 T_default.start;
2077 d := activate(pingpong());
2078 alt {
2079 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
2080 f_handle_create_req(ctxB, ud);
2081 if (not ctxB_created) {
2082 ctxB_created := true;
2083 setverdict(pass);
2084 } else {
2085 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
2086 }
2087
2088 if (not ctxA_deleted) {
2089 repeat;
2090 }
2091 }
2092 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
2093 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
2094 setverdict(pass);
2095 } else {
2096 setverdict(fail);
2097 }
2098
2099 if (not ctxA_deleted) {
2100 ctxA_deleted := true;
2101 setverdict(pass);
2102 } else {
2103 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
2104 }
2105
2106 if (not ctxB_created) {
2107 repeat;
2108 }
2109 }
2110 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
2111 setverdict(fail, "GGSN dropping still valid pdp ctx");
2112 }
2113 }
2114 deactivate(d);
2115 T_default.stop;
2116
2117 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002118 f_shutdown_helper();
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002119 }
2120
2121
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +01002122 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent responses (T3-RESPONSE * N3-REQUESTS):
2123 * If same delete req is sent and duplicate is detected, saved duplicate response should be sent back. */
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002124 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
2125 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002126 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002127 f_pdp_ctx_act(ctx);
2128 f_pdp_ctx_del(ctx, '1'B);
2129 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +01002130 f_sleep(int2float(mp_t3_response));
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002131 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
2132 duplicate. If it was not a duplicate, osmo-ggsn would answer
2133 with a failure since that PDP ctx was already deleted. */
Pau Espin Pedrold6b51332022-05-19 17:47:11 +02002134 if (g_c_seq_nr == 0) {
2135 g_c_seq_nr := 65535;
2136 } else {
2137 g_c_seq_nr := g_c_seq_nr - 1;
2138 }
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01002139 f_pdp_ctx_del(ctx, '1'B, expect_diameter := false);
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002140
2141 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
2142 var OCT1 cause_nonexistent := 'C0'O;
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01002143 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent, expect_diameter := false);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002144 f_shutdown_helper();
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002145 }
2146
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002147 /* Activate PDP context + trigger Recovery procedure through EchoResp */
2148 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
2149 var Gtp1cUnitdata ud;
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002150 g_use_echo_intval := 5;
2151 timer T_echo;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002152 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002153 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002154 f_pdp_ctx_act(ctx);
2155
2156 /* Wait to receive echo request and send initial Restart counter */
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002157 T_echo.start(int2float(g_use_echo_intval) + 1.0);
2158 alt {
2159 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002160 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
2161 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002162 }
2163 [] T_echo.timeout {
2164 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2165 "Timeout waiting for ping");
2166 }
2167 }
2168 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002169
2170 /* Wait to receive second echo request and send incremented Restart
2171 counter. This will fake a restarted SGSN, and pdp ctx allocated
2172 should be released by GGSN */
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06002173 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002174 T_echo.start(int2float(g_use_echo_intval) + 1.0);
2175 alt {
2176 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002177 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
2178 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002179 }
2180 [] T_echo.timeout {
2181 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2182 "Timeout waiting for ping");
2183 }
2184 }
2185 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002186 f_pdp_ctx_exp_del_req(ctx, omit, true);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002187 f_shutdown_helper();
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002188 }
2189
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002190 /* Test creation, user plane and deletion of big amount (1000) of concurrent PDP context */
2191 testcase TC_lots_of_concurrent_pdp_ctx() runs on GT_CT {
2192 var Gtp1cUnitdata udc;
2193 var Gtp1uUnitdata udu;
2194 const integer num_ctx := 1000;
2195 var PdpContext ctx[num_ctx];
2196 timer T_next := 0.01;
2197 var integer next_req_ctx := 0;
2198 var integer rx_resp_ctx := 0;
2199 var integer rx_pong := 0;
2200 var OCT4 dns1_addr;
2201 var OCT4 saddr;
2202 var integer teic;
2203 var integer idx;
2204
2205 f_init();
2206
2207 for (var integer i := 0; i < num_ctx; i := i + 1) {
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002208 ctx[i] := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234" & int2str(f_rnd_int(4294967296)), c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002209 ctx[i].teic := int2oct(i+1, 4); /* +1: skip TEIC=0 */
2210 ctx[i].teid := int2oct(i+1, 4); /* +1: skip TEID=0 */
2211 ctx[i].pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2212 }
2213
2214 T_default.start(60.0);
2215
2216 T_next.start;
2217 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002218 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002219 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, INITIAL_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002220 [] pingpong();
2221 [] T_next.timeout {
2222 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx[next_req_ctx].imsi, g_restart_ctr,
2223 ctx[next_req_ctx].teid, ctx[next_req_ctx].teic, ctx[next_req_ctx].nsapi,
2224 ctx[next_req_ctx].eua, ctx[next_req_ctx].apn, g_sgsn_ip_c, g_sgsn_ip_u,
2225 ctx[next_req_ctx].msisdn, ctx[next_req_ctx].pco_req, ctx[next_req_ctx].ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002226 ctx[next_req_ctx].uli, ctx[next_req_ctx].charging_char, ctx[next_req_ctx].imeisv,
2227 ctx[next_req_ctx].ms_tz));
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002228 next_req_ctx := next_req_ctx + 1;
2229 if (next_req_ctx < num_ctx) {
2230 T_next.start;
2231 }
2232 repeat;
2233 }
2234 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2235 teic := oct2int(udc.gtpc.teid);
2236 if (not match(teic, (1 .. num_ctx))) {
2237 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2238 "Rx Unexpected TEIC");
2239 }
2240 idx := teic - 1;
2241 f_handle_create_req(ctx[idx], udc);
2242 rx_resp_ctx := rx_resp_ctx + 1;
2243
2244 dns1_addr := f_PCO_extract_proto(ctx[idx].pco_neg, '000d'O);
2245 saddr := ctx[idx].eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2246 f_send_gtpu(ctx[idx], f_gen_icmpv4_echo(saddr, dns1_addr));
2247 repeat;
2248 }
2249 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value udu {
2250 var octetstring gpdu := udu.gtpu.gtpu_IEs.g_PDU_IEs.data;
2251 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
2252 if (ip4.header.ver != 4) {
2253 repeat;
2254 }
2255 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
2256 if (not match(icmp4, (tr_ICMPv4_ERP, tr_ICMPv4_DU))) {
2257 repeat;
2258 }
2259 rx_pong := rx_pong + 1;
2260 if (rx_pong < num_ctx) {
2261 repeat;
2262 }
2263 setverdict(pass);
2264 }
2265 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2266 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2267 }
2268
2269 /* Let's close them now: */
2270 next_req_ctx := 0;
2271 rx_resp_ctx := 0;
2272 T_next.start;
2273 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002274 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002275 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002276 [] pingpong();
2277 [] T_next.timeout {
2278 f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, ctx[next_req_ctx].teic_remote, ctx[next_req_ctx].nsapi, '1'B));
2279 next_req_ctx := next_req_ctx + 1;
2280 if (next_req_ctx < num_ctx) {
2281 T_next.start;
2282 }
2283 repeat;
2284 }
2285 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2286 teic := oct2int(udc.gtpc.teid);
2287 if (not match(teic, (1 .. num_ctx))) {
2288 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2289 "Rx Unexpected TEIC");
2290 }
2291 rx_resp_ctx := rx_resp_ctx + 1;
2292 if (rx_resp_ctx < num_ctx) {
2293 repeat;
2294 }
2295 setverdict(pass);
2296 }
2297 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2298 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2299 }
2300 T_next.stop;
2301
2302 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002303 f_shutdown_helper();
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002304 }
2305
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002306 /* Test callocation of PDP contexts until reaching addr pool exhaustion */
2307 type record of OCT4 TEIClist;
2308 testcase TC_addr_pool_exhaustion() runs on GT_CT {
2309 var Gtp1cUnitdata udc;
2310 var Gtp1uUnitdata udu;
2311 var PdpContext ctx;
2312 timer T_next := 0.005;
2313 var integer next_req_ctx := 0;
2314 var integer rx_resp_ctx := 0;
2315 var integer num_ctx;
2316 var boolean cont_req := true;
2317 var CreatePDPContextResponse cpr;
2318 var TEIClist teic_list := {};
2319 var integer teic;
2320
2321 f_init();
2322
2323 T_default.start(120.0);
2324
2325 T_next.start;
2326 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002327 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002328 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, INITIAL_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002329 [] pingpong();
2330 [] T_next.timeout {
2331 if (cont_req) {
2332 if (next_req_ctx - rx_resp_ctx < 100) { /* if we have too many in progress, wait a bit to continue */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002333 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234" & int2str(f_rnd_int(4294967296)), c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002334 ctx.nsapi := '0001'B;
2335 ctx.teic := int2oct(next_req_ctx+1, 4); /* +1: skip TEIC=0 */
2336 ctx.teid := int2oct(next_req_ctx+1, 4); /* +1: skip TEID=0 */
2337 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx.imsi, g_restart_ctr,
2338 ctx.teid, ctx.teic, ctx.nsapi,
2339 ctx.eua, ctx.apn, g_sgsn_ip_c, g_sgsn_ip_u,
2340 ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002341 ctx.uli, ctx.charging_char, ctx.imeisv,
2342 ctx.ms_tz));
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002343 next_req_ctx := next_req_ctx + 1;
2344 }
2345 T_next.start;
2346 }
2347 repeat;
2348 }
2349 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2350 cpr := udc.gtpc.gtpc_pdu.createPDPContextResponse;
2351
2352 if (cpr.cause.causevalue == '80'O) {
2353 teic_list := teic_list & {cpr.teidControlPlane.teidControlPlane};
2354 } else {
2355 if (cont_req == true) {
2356 num_ctx := rx_resp_ctx;
2357 log("Successfully created ", num_ctx, " PDP contexts before exhausting the pool");
2358 setverdict(pass);
2359 }
2360 cont_req := false;
2361 }
2362 rx_resp_ctx := rx_resp_ctx + 1;
2363 if (not cont_req and next_req_ctx == rx_resp_ctx) {
2364 break;
2365 } else {
2366 repeat;
2367 }
2368 }
2369 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2370 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2371 }
2372
2373 /* Let's close them now: */
2374 next_req_ctx := 0;
2375 rx_resp_ctx := 0;
2376 T_next.start;
2377 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002378 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002379 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002380 [] pingpong();
2381 [] T_next.timeout {
2382 f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, teic_list[next_req_ctx], '0001'B, '1'B));
2383 next_req_ctx := next_req_ctx + 1;
2384 if (next_req_ctx < num_ctx) {
2385 T_next.start;
2386 }
2387 repeat;
2388 }
2389 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2390 teic := oct2int(udc.gtpc.teid);
2391 if (not match(teic, (1 .. num_ctx))) {
2392 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2393 "Rx Unexpected TEIC");
2394 }
2395 rx_resp_ctx := rx_resp_ctx + 1;
2396 if (rx_resp_ctx < num_ctx) {
2397 repeat;
2398 }
2399 setverdict(pass);
2400 }
2401 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2402 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2403 }
2404 T_next.stop;
2405
2406 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002407 f_shutdown_helper();
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002408 }
2409
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002410 /* Test charging over Gy interface. */
2411 testcase TC_gy_charging_cc_time() runs on GT_CT {
2412 var default d;
2413
2414 g_gy_validity_time := 3; /* Grant access for 3 seconds, needs to be re-validated afterwards */
2415 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002416 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002417 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2418 f_pdp_ctx_act(ctx);
2419
2420 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2421
2422 /* Send some UL traffic: */
2423 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2424 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2425 f_wait_icmp4_echo_reply(ctx);
2426
2427 T_default.start(10.0);
2428 d := activate(pingpong());
2429
2430 g_gy_validity_time := 2;
2431 /* First update reports octests/pkt on both UL/DL (see icmp ping-pong above) */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002432 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002433 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (3..4), 28, 28);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002434
2435 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002436 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002437 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (2..3), 0, 0);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002438
2439 /* Third update: make sure report contains again octets/pkts for both UL/DL: */
2440 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2441 f_wait_icmp4_echo_reply(ctx);
2442 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2443 f_wait_icmp4_echo_reply(ctx);
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002444 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002445 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (2..3), 56, 56);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002446
2447 /* Let the CCA reach the GGSN */
2448 f_sleep(0.5);
2449 deactivate(d);
2450 T_default.stop;
2451
2452 /* Send some data and validate it is reported in the TERMINATION_REQUEST
2453 * (triggered by PFCP Session Deletion Response): */
2454 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2455 f_wait_icmp4_echo_reply(ctx);
2456
2457 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002458 f_validate_gy_cc_report(g_rx_gy, FINAL, (0..2), 28, 28);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002459
2460
2461 f_shutdown_helper();
2462 }
2463
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002464 /* Test Volume-Quota-Thresold AVP triggers request before Validity-Time */
2465 testcase TC_gy_charging_volume_quota_threshold() runs on GT_CT {
2466 var default d;
2467 timer Tout;
2468 g_gy_volume_threshold := 1000; /* Will make a trigger when we send bigger payload below */
2469 g_gy_validity_time := 8; /* Grant access for 8 seconds, needs to be re-validated afterwards */
2470 f_init();
2471 var float tout_sec := int2float(g_gy_validity_time) / 2.0;
2472 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2473 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2474 f_pdp_ctx_act(ctx);
2475
2476 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2477
2478 T_default.start(40.0);
2479 d := activate(pingpong());
2480
2481 /* Send some UL traffic: */
2482 var octetstring payload := f_rnd_octstring(1200);
2483 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2484 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr, payload));
2485 f_wait_icmp4_echo_reply(ctx);
2486
2487 /* ICMP Req generates one report: */
2488 Tout.start(tout_sec);
2489 alt {
2490 [] as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
2491 [] Tout.timeout {
2492 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2493 "TImeout waiting for Gy UPDATE triggered by Volume-Quota-Threshold");
2494 }
2495 }
Pau Espin Pedrol5fa8f782022-10-03 13:57:54 +02002496 f_validate_gy_cc_report(g_rx_gy, THRESHOLD, (0..6), (1200..1400), 0);
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002497
2498 /* ICMP Resp (echo back) generates one report: */
2499 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol5fa8f782022-10-03 13:57:54 +02002500 f_validate_gy_cc_report(g_rx_gy, THRESHOLD, (0..1), 0, (1200..1400));
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002501
2502 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
2503 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
2504 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (8..9), 0, 0);
2505
2506 /* Let the CCA reach the GGSN */
2507 f_sleep(0.5);
2508 deactivate(d);
2509 T_default.stop;
2510
2511 f_pdp_ctx_del(ctx, '1'B);
2512 f_validate_gy_cc_report(g_rx_gy, FINAL, (0..2), 0, 0);
2513
2514
2515 f_shutdown_helper();
2516 }
2517
Harald Welte94ade362017-08-04 00:36:55 +02002518 control {
Harald Welteed7a1772017-08-09 20:26:20 +02002519 execute(TC_pdp4_act_deact());
2520 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02002521 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02002522 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002523 execute(TC_pdp4_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002524 execute(TC_pdp4_act_deact_gtpu_access_wrong_saddr());
2525 execute(TC_pdp4_act_deact_gtpu_access_ipv6_apn4());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02002526 execute(TC_pdp4_clients_interact_with_txseq());
2527 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02002528 execute(TC_pdp4_act_deact_with_single_dns());
2529 execute(TC_pdp4_act_deact_with_separate_dns());
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01002530 execute(TC_pdp4_act_update_teic());
2531 execute(TC_pdp4_act_update_teid());
Harald Welteed7a1772017-08-09 20:26:20 +02002532
2533 execute(TC_pdp6_act_deact());
2534 execute(TC_pdp6_act_deact_pcodns());
2535 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002536 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002537 execute(TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr());
2538 execute(TC_pdp6_act_deact_gtpu_access_wrong_global_saddr());
2539 execute(TC_pdp6_act_deact_gtpu_access_ipv4_apn6());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01002540 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02002541
Oliver Smithee6a0882019-03-08 11:05:46 +01002542 execute(TC_pdp46_act_deact());
2543 execute(TC_pdp46_act_deact_ipcp());
2544 execute(TC_pdp46_act_deact_icmp6());
2545 execute(TC_pdp46_act_deact_pcodns4());
2546 execute(TC_pdp46_act_deact_pcodns6());
2547 execute(TC_pdp46_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002548 execute(TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4());
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01002549 execute(TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002550 execute(TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6());
Oliver Smithee6a0882019-03-08 11:05:46 +01002551 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002552 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01002553
Harald Weltedca80052017-08-13 20:01:38 +02002554 execute(TC_echo_req_resp());
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01002555 execute(TC_echo_req_resp_gtpu());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002556 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002557 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002558
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01002559 execute(TC_pdp_act_restart_ctr_echo());
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002560
2561 execute(TC_lots_of_concurrent_pdp_ctx());
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002562 /* Keep at the end, crashes older osmo-ggsn versions (OS#5469): */
2563 execute(TC_addr_pool_exhaustion());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002564
2565 /* open5gs specific tests: */
2566 if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
2567 execute(TC_gy_charging_cc_time());
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002568 execute(TC_gy_charging_volume_quota_threshold());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002569 }
Harald Welte94ade362017-08-04 00:36:55 +02002570 }
Harald Welte379d45a2017-08-03 09:55:15 +02002571}