blob: 32d4a1dbecbe3341bd2fc34c85d4ed0069db6f2a [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;
21 import from GTP_CodecPort all;
22 import from GTP_CodecPort_CtrlFunct all;
Harald Weltec69cf4e2018-02-17 20:57:02 +010023 import from GTP_Templates all;
Harald Welte94ade362017-08-04 00:36:55 +020024 import from GTPC_Types all;
25 import from GTPU_Types all;
Harald Welte71a36022017-12-04 18:55:58 +010026 import from IPCP_Types all;
Harald Weltef8298542019-04-10 10:15:28 +020027 import from PAP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020028 import from IP_Types all;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +010029 import from ICMP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020030 import from ICMPv6_Types all;
Harald Welteddeecbb2017-08-18 22:53:30 +020031 import from Native_Functions all;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +020032 import from Osmocom_VTY_Functions all;
33 import from TELNETasp_PortType all;
Harald Welte94ade362017-08-04 00:36:55 +020034
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010035 import from DIAMETER_Types all;
36 import from DIAMETER_Templates all;
Pau Espin Pedrol867b1302024-01-24 16:14:28 +010037 import from DIAMETER_ts29_212_Templates all;
Pau Espin Pedrol117a94f2023-12-21 16:10:12 +010038 import from DIAMETER_ts29_272_Templates all;
Pau Espin Pedrol867b1302024-01-24 16:14:28 +010039 import from DIAMETER_ts32_299_Templates all;
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010040 import from DIAMETER_Emulation all;
41
Harald Welte94ade362017-08-04 00:36:55 +020042 const integer GTP0_PORT := 3386;
43 const integer GTP1C_PORT := 2123;
44 const integer GTP1U_PORT := 2152;
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010045 const integer PCRF_PORT := 3868;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +010046 const integer OCS_PORT := 3869;
Harald Welteddeecbb2017-08-18 22:53:30 +020047
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010048 type enumerated GGSN_Impl {
49 GGSN_IMPL_OSMOCOM,
50 GGSN_IMPL_OPEN5GS
51 };
52
Harald Welteddeecbb2017-08-18 22:53:30 +020053 modulepar {
Stefan Sperlingcb782b92018-04-03 16:03:15 +020054 /* Default IP addresses. May be overridden by GGSN_Tests configuration files. */
55
56 /* The SGSN simulated by TTCN3 will bind to these addresses for GTP control and GTP user planes. */
Harald Welteddeecbb2017-08-18 22:53:30 +020057 charstring m_bind_ip_gtpc := "127.23.42.1";
58 charstring m_bind_ip_gtpu := "127.23.42.1";
59
Stefan Sperlingcb782b92018-04-03 16:03:15 +020060 /* Addresses the GGSN which is being tested is listening on for SGSN connections. */
Harald Welteddeecbb2017-08-18 22:53:30 +020061 charstring m_ggsn_ip_gtpc := "127.0.0.6";
62 charstring m_ggsn_ip_gtpu := "127.0.0.6";
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010063
Stefan Sperlingcb782b92018-04-03 16:03:15 +020064 /*
65 * Our tests expect to see these DNS servers in 'Create PDP context responses' sent by the GGSN.
66 * These addresses must therefore match 'ip[v6] dns' options configured in osmo-ggsn.conf.
67 *
68 * These addresses are not expected to serve actual DNS requests. However, tests may expect to be
69 * able to ping these addresses (currently, IPv4 addresses must respond with an ICMP 'echo reply',
70 * and IPv6 addresses may respond with either ICMPv6 'echo reply' or 'destination unreachable').
71 */
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010072 charstring m_ggsn_ip4_dns1 := "192.168.100.1"
73 charstring m_ggsn_ip4_dns2 := "8.8.8.8"
Pau Espin Pedrol363ba482018-01-29 18:42:00 +010074 charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888"
75 charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844"
Stefan Sperlingcb782b92018-04-03 16:03:15 +020076
77 /*
78 * Additional address ranges are defined in osmo-ggsn.conf from which addresses are assigned
79 * to MS "behind" the simulated SGSN. These addresses appear on tun devices used by osmo-ggsn.
80 * The tests expect to be able to send ping packets between any two simulated MS within the same
81 * address range. This requires IP forwarding to be enabled on the corresponding tun interfaces.
82 */
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +010083 integer mp_t3_response := 5; /* local T3-RESPONSE timeout, seconds */
84 integer mp_n3_requests := 3; /* local N3-REQUESTS counter */
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010085
86 GGSN_Impl m_ggsn_impl := GGSN_IMPL_OSMOCOM;
Harald Welteddeecbb2017-08-18 22:53:30 +020087 }
Harald Welte94ade362017-08-04 00:36:55 +020088
Harald Welte811651e2017-08-05 15:25:06 +020089 type set PdpContext {
90 hexstring imsi,
91 octetstring msisdn optional,
92 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020093 ProtConfigOptions pco_req optional,
94 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020095 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020096 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020097 BIT4 nsapi,
98 /* TEI (Data) local side */
99 OCT4 teid,
100 /* TEI (Control) local side */
101 OCT4 teic,
102 /* TEI (Data) remote side */
103 OCT4 teid_remote,
104 /* TEI (Control) remote side */
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100105 OCT4 teic_remote,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100106 OCT1 ratType optional,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200107 UserLocationInformation uli optional,
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200108 OCT2 charging_char optional,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200109 OCT8 imeisv optional,
110 MS_TimeZone ms_tz optional
Harald Welte811651e2017-08-05 15:25:06 +0200111 }
112
Harald Welte94ade362017-08-04 00:36:55 +0200113 type component GT_CT {
114 port GTPC_PT GTPC;
115 port GTPU_PT GTPU;
116
Harald Welte0be142b2017-08-13 13:28:10 +0200117 var boolean g_initialized := false;
118
Harald Welte94ade362017-08-04 00:36:55 +0200119 var OCT1 g_restart_ctr := '01'O;
120 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200121 var OCT4 g_sgsn_ip_c;
122 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +0200123 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200124 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
125 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200126 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200127
128 /* next to-be-sent GTP-C sequence number */
129 var uint16_t g_c_seq_nr;
130 /* next to-be-sent GTP-U sequence number */
131 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200132
133 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200134 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100135 var integer g_use_echo_intval := 0; /* 0 = disabled */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100136
Pau Espin Pedrol733369a2022-05-20 18:39:55 +0200137 /* Emulated PCRF, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200138 var DIAMETER_conn_parameters g_gx_pars;
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100139 var DIAMETER_Emulation_CT vc_Gx;
140 port DIAMETER_PT Gx_UNIT;
141 port DIAMETEREM_PROC_PT Gx_PROC;
Pau Espin Pedrol733369a2022-05-20 18:39:55 +0200142
143 /* Emulated OCS, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200144 var DIAMETER_conn_parameters g_gy_pars;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100145 var DIAMETER_Emulation_CT vc_Gy;
146 port DIAMETER_PT Gy_UNIT;
147 port DIAMETEREM_PROC_PT Gy_PROC;
148 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 +0200149 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 +0200150 var PDU_DIAMETER g_rx_gy; /* Store last received Gy message */
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200151 }
152
153 private function f_init_vty() runs on GT_CT {
154 map(self:GGSNVTY, system:GGSNVTY);
155 f_vty_set_prompts(GGSNVTY);
156 f_vty_transceive(GGSNVTY, "enable");
157 }
158
159 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
160 f_vty_enter_config(GGSNVTY);
161 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200162
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200163 f_vty_transceive(GGSNVTY, "apn internet");
164 if (enable) {
165 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
166 } else {
167 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
168 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200169 f_vty_transceive(GGSNVTY, "exit");
170
171 f_vty_transceive(GGSNVTY, "apn inet6");
172 if (enable) {
173 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
174 } else {
175 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
176 }
177 f_vty_transceive(GGSNVTY, "exit");
178
179 f_vty_transceive(GGSNVTY, "apn inet46");
180 if (enable) {
181 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
182 } else {
183 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
184 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200185 f_vty_transceive(GGSNVTY, "end");
186 }
187
188 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
189 if (expect_gptu_txseq) {
190 if (gtpu.s_bit != '1'B) {
191 log("GTPU sequence number expected but not present")
192 return false;
193 }
194 } else {
195 if (gtpu.s_bit != '0'B) {
196 log("GTPU sequence number not expected but present")
197 return false;
198 }
199 }
200 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200201 }
202
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100203 private function f_vty_enable_echo_interval(integer intval_sec) runs on GT_CT {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200204 f_vty_enter_config(GGSNVTY);
205 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100206 if (intval_sec > 0) {
207 f_vty_transceive(GGSNVTY, "echo-interval " & int2str(intval_sec));
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200208 } else {
209 f_vty_transceive(GGSNVTY, "no echo-interval");
210 }
211 f_vty_transceive(GGSNVTY, "end");
212 }
213
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100214 private function DiameterForwardUnitdataCallback(PDU_DIAMETER msg)
215 runs on DIAMETER_Emulation_CT return template PDU_DIAMETER {
216 DIAMETER_UNIT.send(msg);
217 return omit;
218 }
219
220 private function f_init_diameter(charstring id) runs on GT_CT {
221 var DIAMETEROps ops := {
222 create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback),
223 unitdata_cb := refers(DiameterForwardUnitdataCallback),
224 raw := true /* handler mode (single component for all IMSI)) */
225 };
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100226
227 /* Gx setup: */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200228 g_gx_pars := {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100229 remote_ip := m_ggsn_ip_gtpc,
230 remote_sctp_port := -1,
231 local_ip := m_bind_ip_gtpc,
232 local_sctp_port := PCRF_PORT,
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100233 origin_host := "pcrf.localdomain",
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100234 origin_realm := "localdomain",
Pau Espin Pedrol33b47492022-03-08 17:43:01 +0100235 auth_app_id := omit,
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100236 vendor_app_id := c_DIAMETER_3GPP_Gx_AID
237 };
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100238 vc_Gx := DIAMETER_Emulation_CT.create(id);
239 map(vc_Gx:DIAMETER, system:DIAMETER_CODEC_PT);
240 connect(vc_Gx:DIAMETER_UNIT, self:Gx_UNIT);
241 connect(vc_Gx:DIAMETER_PROC, self:Gx_PROC);
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200242 vc_Gx.start(DIAMETER_Emulation.main(ops, g_gx_pars, id));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100243
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100244 /* Gy setup: */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200245 g_gy_pars := {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100246 remote_ip := m_ggsn_ip_gtpc,
247 remote_sctp_port := -1,
248 local_ip := m_bind_ip_gtpc,
249 local_sctp_port := OCS_PORT,
250 origin_host := "ocs.localdomain",
251 origin_realm := "localdomain",
252 auth_app_id := c_DIAMETER_CREDIT_CONTROL_AID,
253 vendor_app_id := omit
254 };
255 vc_Gy := DIAMETER_Emulation_CT.create(id);
256 map(vc_Gy:DIAMETER, system:DIAMETER_CODEC_PT);
257 connect(vc_Gy:DIAMETER_UNIT, self:Gy_UNIT);
258 connect(vc_Gy:DIAMETER_PROC, self:Gy_PROC);
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200259 vc_Gy.start(DIAMETER_Emulation.main(ops, g_gy_pars, id));
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100260
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100261 f_diameter_wait_capability(Gx_UNIT);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100262 f_diameter_wait_capability(Gy_UNIT);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100263 /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdong ping-pongs):
264 * RFC6733 sec 5.1
265 * RFC3539 sec 3.4.1 [5]
266 * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49
267 */
268 f_sleep(1.0);
269 }
270
Harald Welte94ade362017-08-04 00:36:55 +0200271 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200272 if (g_initialized == true) {
273 return;
274 }
275 g_initialized := true;
276
Harald Welteddeecbb2017-08-18 22:53:30 +0200277 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
278 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
279
Harald Welte94ade362017-08-04 00:36:55 +0200280 var Result res;
281 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +0200282 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200283 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200284 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200285
286 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +0200287 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200288 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200289
290 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200291 g_c_seq_nr := f_rnd_int(65535);
292 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200293
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100294 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
295 f_init_vty();
296 f_vty_set_gpdu_txseq(use_gtpu_txseq);
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100297 f_vty_enable_echo_interval(g_use_echo_intval);
Oliver Smith95722c62023-10-20 13:59:10 +0200298 /* Emit a marker to appear in the SUT's own logging output */
299 f_logp(GGSNVTY, testcasename() & "() start");
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100300 } else if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
301 f_init_diameter(testcasename());
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100302 }
Harald Welte94ade362017-08-04 00:36:55 +0200303 }
304
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100305 function f_shutdown_helper() runs on GT_CT {
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +0100306 /* Sleep (T3-RESPONSE * N3-REQUESTS) seconds.
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100307 * This ensures all retransmit queues are cleared before jumping
308 * into next tests, hence avoding situation where a test resuses
309 * a seqnum still in the GGSN's resp queue (dup req detector).
310 * See OS#5485 avout decreasing time. We could also add a new
311 * VTY command that calls gtp_clear_queues() */
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +0100312 f_sleep(int2float(mp_t3_response * mp_n3_requests));
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100313 setverdict(pass);
314 }
315
Harald Welte94ade362017-08-04 00:36:55 +0200316 /* Altstep implementing responses to any incoming echo requests */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100317 private altstep pingpong() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200318 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200319 var Gtp1uUnitdata udu;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100320 [g_use_echo_intval > 0] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200321 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200322 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200323 repeat;
324 };
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100325 [g_use_echo_intval == 0] GTPC.receive(tr_GTPC_PING(?)) {
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100326 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
327 "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200328 };
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100329 [] T_default.timeout {
330 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
Oliver Smithbbbe05d2024-02-28 11:14:32 +0100331 "pingpong T_default timeout");
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100332 };
Harald Welte94ade362017-08-04 00:36:55 +0200333 }
334
Harald Welte811651e2017-08-05 15:25:06 +0200335 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200336 const octetstring c_ApnInternet := '08696E7465726E6574'O;
337 const octetstring c_ApnInet6 := '05696E657436'O;
338 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200339
Harald Welte811651e2017-08-05 15:25:06 +0200340 /* return random NSAPI */
341 function f_rnd_nsapi() return BIT4 {
342 return int2bit(f_rnd_int(16), 4);
343 }
344
345 /* return random TEI[DC] */
346 function f_rnd_tei() return OCT4 {
347 return int2oct(f_rnd_int(4294967296), 4);
348 }
349
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200350 /* return random IMEI(SV) */
351 function f_rnd_imeisv() return OCT8 {
352 return hex2oct(f_rnd_hexstring(16, 10));
353 }
354
Harald Welte811651e2017-08-05 15:25:06 +0200355 /* define an (internal) representation of a PDP context */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +0200356 template PdpContext t_DefinePDP(hexstring imsi, charstring msisdn, octetstring apn,
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100357 EndUserAddress eua, OCT1 ratType := '02'O /* GERAN */) := {
Harald Welte811651e2017-08-05 15:25:06 +0200358 imsi := imsi,
Pau Espin Pedrold25095f2022-05-18 16:29:05 +0200359 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 +0200360 nsapi := f_rnd_nsapi(),
361 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200362 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200363 eua := eua,
364 teid := f_rnd_tei(),
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100365 teic := f_rnd_tei(),
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100366 ratType := ratType,
367 uli := {
368 type_gtpc := '98'O,
369 lengthf := 0 /* filled in by encoder */,
370 geographicLocationType := '00'O /* CGI */,
371 geographicLocation := {
372 geographicLocationCGI := ts_GeographicLocationCGI('262'H, '42F'H, '0001'O, '0002'O)
373 }
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200374 },
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200375 charging_char := '0000'O,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200376 imeisv := f_rnd_imeisv(),
377 ms_tz := f_ts_MS_TimeZone('03'O, '01'B)
Harald Welte811651e2017-08-05 15:25:06 +0200378 }
379
380 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200381 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200382 GTPC.send(data);
Pau Espin Pedrol82a7f702022-05-19 17:41:29 +0200383 g_c_seq_nr := (g_c_seq_nr + 1) mod 65536;
Harald Welte811651e2017-08-05 15:25:06 +0200384 }
385
386 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200387 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200388 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200389 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
Pau Espin Pedrol82a7f702022-05-19 17:41:29 +0200390 g_d_seq_nr := (g_d_seq_nr + 1) mod 65536;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200391 } else {
392 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
393 }
Harald Welte811651e2017-08-05 15:25:06 +0200394 }
395
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100396 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 +0200397 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100398
399 if (not match(cpr.cause.causevalue, exp_cause)) {
400 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
401 "CreatePDPContextResp: cause expectancies didn't match");
402 }
403
404 if (cpr.cause.causevalue == '80'O) { /* Accepted */
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200405 /* Check if EUA type corresponds to requested type */
406 if (match(ctx.eua, t_EuaIPv4(?)) and
407 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100408 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
409 "EUAv4 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200410 }
411 if (match(ctx.eua, t_EuaIPv6(?)) and
412 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
414 "EUAv6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200415 }
416 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
417 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100418 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
419 "EUAv4v6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200420 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100421 } else if (cpr.cause.causevalue == '81'O) { /* Cause: New PDP type due to network preference */
422 /* ETSI TS 129 060 7.3.2 Create PDP Context Response. OS#5449 */
423 /* This should only happen if EUA requested type is v4v6: */
424 if (not ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
425 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
426 "Cause not expected when requesting a non v4v6 EUA");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200427 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100428 if (not match(cpr.endUserAddress, (tr_EuaIPv4(?), tr_EuaIPv6(?)))) {
429 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
430 "Cause not expected when requesting+receiving EUAv4v6");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200431 }
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200432 } else {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100433 if (ispresent(cpr.endUserAddress)) {
434 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
435 "EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
436 }
437 setverdict(pass);
438 return;
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200439 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100440
441 /* Check if PCO response corresponds to request */
442 if (ispresent(ctx.pco_req)) {
443 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
444 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
445 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
446 "IPv4 DNS Container requested, but missing");
447 }
448 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
449 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
450 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
451 "IPv6 DNS Container requested, but missing");
452 }
453 }
454 ctx.teid_remote := cpr.teidDataI.teidDataI;
455 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
456 ctx.eua := cpr.endUserAddress;
457 ctx.pco_neg := cpr.protConfigOptions;
458 setverdict(pass);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200459 }
460
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100461 function f_handle_update_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
462 var UpdatePDPContextResponseGGSN upr := ud.gtpc.gtpc_pdu.updatePDPContextResponse.updatePDPContextResponseGGSN;
463 if (exp_cause == '80'O and exp_cause == upr.cause.causevalue) {
464 ctx.teid_remote := upr.teidDataI.teidDataI;
465 ctx.teic_remote := upr.teidControlPlane.teidControlPlane;
466 if (ispresent(upr.protConfigOptions)) {
467 ctx.pco_neg := upr.protConfigOptions;
468 }
469 setverdict(pass);
470 } else if (exp_cause != '80'O and exp_cause == upr.cause.causevalue) {
471 setverdict(pass);
472 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100473 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
474 "UpdatePDPContextResp: cause expectancies didn't match");
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100475 }
476 }
477
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100478 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 +0100479 var PDU_DIAMETER rx_dia;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100480 [] Gx_UNIT.receive(tr_DIA_Gx_CCR(req_type := req_type)) -> value rx_dia {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100481 var template (omit) AVP avp;
482 var octetstring sess_id;
483 var AVP_Unsigned32 req_num;
484
485 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
486 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
487
488 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
489 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
490
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100491 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 +0100492 req_type, req_num));
493 }
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100494 [] Gx_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100495 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
496 log2str("Received unexpected DIAMETER ", rx_dia));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100497 }
498 }
499
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200500 private function f_tr_DIA_Gy_CCR(template (omit) PdpContext ctx, DCC_NONE_CC_Request_Type req_type)
501 runs on GT_CT return template (present) PDU_DIAMETER
502 {
503 var template (present) PDU_DIAMETER tpl;
504 var charstring smf_origin_host := "smf.localdomain";
505 var template (present) octetstring imsi := ?;
506 var template (present) octetstring msisdn := ?;
507 var template (present) octetstring imeisv := ?;
508 var template (present) octetstring rat_type := ?;
509 var template (present) OCT4 charging_char := ?;
510 var template (present) OCT1 nsapi := ?;
511 if (not istemplatekind(ctx, "omit")) {
512 var PdpContext ctx_val := valueof(ctx);
513 imsi := char2oct(f_dec_TBCD(imsi_hex2oct(ctx_val.imsi)));
514 msisdn := char2oct(f_dec_TBCD(substr(ctx_val.msisdn, 1, lengthof(ctx_val.msisdn) -1)));
515 imeisv := char2oct(f_dec_TBCD(ctx_val.imeisv));
516 rat_type := ctx_val.ratType;
517 charging_char := char2oct(oct2str(ctx_val.charging_char));
518 nsapi := char2oct(hex2str(bit2hex(ctx_val.nsapi)));
519 }
520 select (req_type) {
521 case (INITIAL_REQUEST) {
522 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
523 avps := superset(
524 tr_AVP_SessionId,
525 tr_AVP_OriginHost(smf_origin_host),
526 tr_AVP_OriginRealm(g_gy_pars.origin_realm),
527 tr_AVP_DestinationRealm(g_gy_pars.origin_realm),
528 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
529 tr_AVP_ServiceContextId,
530 tr_AVP_CcReqType(req_type),
531 tr_AVP_CcReqNum(?),
532 tr_AVP_EventTimestamp(?),
533 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
534 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
535 tr_AVP_RequestedAction(DIRECT_DEBITING),
536 tr_AVP_3GPP_AoCRequestType,
537 tr_AVP_MultipleServicesIndicator,
538 tr_AVP_Multiple_Services_Credit_Control(content := superset(
539 tr_AVP_Requested_Service_Unit,
Pau Espin Pedrol6477d732022-06-03 12:04:40 +0200540 tr_AVP_PCC_3GPP_QoS_Information,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200541 tr_AVP_GI_3GPP_RatType(rat_type)
542 )),
543 tr_AVP_3GPP_ServiceInformation(content := superset(
544 tr_AVP_3GPP_PSInformation(content := superset(
545 tr_AVP_3GPP_ChargingId,
546 tr_AVP_3GPP_PDPType((IPv4,IPv6,IPv4v6)),
547 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
548 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_bind_ip_gtpc))),
549 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_ggsn_ip_gtpc))),
550 tr_AVP_3GPP_CalledStationId,
551 tr_AVP_3GPP_SelectionMode,
552 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
553 tr_AVP_3GPP_SGSNMCCMNC,
554 tr_AVP_3GPP_NSAPI(nsapi),
555 tr_AVP_3GPP_MS_TimeZone,
556 tr_AVP_3GPP_ULI,
557 tr_AVP_UserEquipmentInfo({
558 tr_AVP_UserEquipmentInfoType(IMEISV),
559 tr_AVP_UserEquipmentInfoValue(imeisv)
560 })
561 ))
562 ))
563 ));
564 }
565 case (UPDATE_REQUEST) {
566 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
567 avps := superset(
568 tr_AVP_SessionId,
569 tr_AVP_OriginHost(smf_origin_host),
570 tr_AVP_OriginRealm(g_gy_pars.origin_realm),
571 tr_AVP_DestinationRealm(g_gy_pars.origin_realm),
572 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
573 tr_AVP_ServiceContextId,
574 tr_AVP_CcReqType(req_type),
575 tr_AVP_CcReqNum(?),
576 tr_AVP_DestinationHost(?),
577 tr_AVP_EventTimestamp(?),
578 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
579 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
580 tr_AVP_RequestedAction(DIRECT_DEBITING),
581 tr_AVP_3GPP_AoCRequestType,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200582 tr_AVP_Multiple_Services_Credit_Control(content := superset(
583 tr_AVP_Requested_Service_Unit,
584 tr_AVP_Used_Service_Unit,
Pau Espin Pedrolcba0f6d2022-05-24 13:49:46 +0200585 /* tr_AVP_3GPP_Reporting_Reason, can be sometimes inside UsedServiceUnit */
Pau Espin Pedrol6477d732022-06-03 12:04:40 +0200586 tr_AVP_PCC_3GPP_QoS_Information,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200587 tr_AVP_GI_3GPP_RatType(rat_type)
588 )),
589 tr_AVP_3GPP_ServiceInformation(content := superset(
590 tr_AVP_3GPP_PSInformation(content := superset(
591 tr_AVP_3GPP_ChargingId,
592 /* tr_AVP_3GPP_PDPType, Only in INIT */
593 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
594 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_bind_ip_gtpc))),
595 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_ggsn_ip_gtpc))),
596 tr_AVP_3GPP_CalledStationId,
597 tr_AVP_3GPP_SelectionMode,
598 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
599 tr_AVP_3GPP_SGSNMCCMNC,
600 tr_AVP_3GPP_NSAPI(nsapi),
601 tr_AVP_3GPP_MS_TimeZone,
602 tr_AVP_3GPP_ULI,
603 tr_AVP_UserEquipmentInfo({
604 tr_AVP_UserEquipmentInfoType(IMEISV),
605 tr_AVP_UserEquipmentInfoValue(imeisv)
606 })
607 ))
608 ))
609 ));
610 }
611 case (TERMINATION_REQUEST) {
612 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
613 avps := superset(
614 tr_AVP_SessionId,
615 tr_AVP_OriginHost(smf_origin_host),
616 tr_AVP_OriginRealm(g_gy_pars.origin_realm),
617 tr_AVP_DestinationRealm(g_gy_pars.origin_realm),
618 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
619 tr_AVP_ServiceContextId,
620 tr_AVP_CcReqType(req_type),
621 tr_AVP_CcReqNum(?),
622 tr_AVP_DestinationHost(?),
623 tr_AVP_EventTimestamp(?),
624 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
625 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
626 tr_AVP_TerminationCause(?),
627 tr_AVP_RequestedAction(DIRECT_DEBITING),
628 tr_AVP_3GPP_AoCRequestType,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200629 tr_AVP_Multiple_Services_Credit_Control(content := superset(
630 /* tr_AVP_Requested_Service_Unit, Only in INIT and UPDATE */
631 tr_AVP_Used_Service_Unit,
Pau Espin Pedrolcba0f6d2022-05-24 13:49:46 +0200632 tr_AVP_3GPP_Reporting_Reason(FINAL),
Pau Espin Pedrol6477d732022-06-03 12:04:40 +0200633 tr_AVP_PCC_3GPP_QoS_Information,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200634 tr_AVP_GI_3GPP_RatType(rat_type)
635 )),
636 tr_AVP_3GPP_ServiceInformation(content := superset(
637 tr_AVP_3GPP_PSInformation(content := superset(
638 tr_AVP_3GPP_ChargingId,
639 /* tr_AVP_3GPP_PDPType, Only in INIT */
640 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
641 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_bind_ip_gtpc))),
642 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_ggsn_ip_gtpc))),
643 tr_AVP_3GPP_CalledStationId,
644 tr_AVP_3GPP_SelectionMode,
645 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
646 tr_AVP_3GPP_SGSNMCCMNC,
647 tr_AVP_3GPP_NSAPI(nsapi),
648 tr_AVP_3GPP_MS_TimeZone,
649 tr_AVP_3GPP_ULI,
650 tr_AVP_UserEquipmentInfo({
651 tr_AVP_UserEquipmentInfoType(IMEISV),
652 tr_AVP_UserEquipmentInfoValue(imeisv)
653 })
654 ))
655 ))
656 ));
657 }
658 }
659 return tpl;
660 }
661
662 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 +0200663 [] 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 +0100664 var template (value) PDU_DIAMETER tx_dia;
665 var template (omit) AVP avp;
666 var octetstring sess_id;
667 var AVP_Unsigned32 req_num;
668
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200669 avp := f_DIAMETER_get_avp(g_rx_gy, c_AVP_Code_BASE_NONE_Session_Id);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100670 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
671
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200672 avp := f_DIAMETER_get_avp(g_rx_gy, c_AVP_Code_DCC_NONE_CC_Request_Number);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100673 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
674 if (g_gy_validity_time > 0) {
Pau Espin Pedrol52562c92022-05-23 15:45:46 +0200675 if (g_gy_volume_threshold > 0) {
676 tx_dia := ts_DIA_Gy_CCA_ValidityTimeVolumeThreshold(g_rx_gy.hop_by_hop_id, g_rx_gy.end_to_end_id, sess_id,
677 req_type, req_num, g_gy_validity_time, g_gy_volume_threshold);
678 } else {
679 tx_dia := ts_DIA_Gy_CCA_ValidityTime(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);
681 }
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100682 } else {
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200683 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 +0100684 req_type, req_num);
685 }
686 Gy_UNIT.send(tx_dia);
687 }
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200688 [] Gy_UNIT.receive(PDU_DIAMETER:?) -> value g_rx_gy {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100689 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200690 log2str("Received unexpected DIAMETER Gy", g_rx_gy));
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100691 }
692 }
693
Harald Welte811651e2017-08-05 15:25:06 +0200694 /* send a PDP context activation */
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100695 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 +0200696 var Gtp1cUnitdata ud;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100697 var CreatePDPContextResponse cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200698 var default d;
699
700 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200701 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 +0200702 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200703 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200704 ctx.uli, ctx.charging_char, ctx.imeisv, ctx.ms_tz));
Harald Welte94ade362017-08-04 00:36:55 +0200705 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200706 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100707 if (Gx_PROC.checkstate("Connected")) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100708 as_DIA_Gx_CCR(INITIAL_REQUEST);
709 }
710 if (Gy_PROC.checkstate("Connected")) {
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200711 as_DIA_Gy_CCR(ctx, INITIAL_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100712 }
Harald Welte94ade362017-08-04 00:36:55 +0200713 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200714 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200715 f_handle_create_req(ctx, ud, exp_cause);
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100716 cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Harald Welte94ade362017-08-04 00:36:55 +0200717 }
718 }
719 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200720 T_default.stop;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100721 return cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200722 }
723
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200724 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
725 var Gtp1cUnitdata ud;
726 var default d;
727
728 T_default.start;
729 d := activate(pingpong());
730 alt {
731 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
732 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
733 setverdict(pass);
734 } else if (not istemplatekind(expect_cause, "omit") and
735 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
736 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
737 setverdict(pass);
738 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100739 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
740 "DeletePDPContextReq: cause expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200741 }
742
743 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
744 setverdict(pass);
745 } else {
746 setverdict(fail);
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100747 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
748 "DeletePDPContextReq: tearDownIndicator expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200749 }
750 }
751 }
752 deactivate(d);
753 T_default.stop;
754 }
755
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +0100756 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 +0200757 var Gtp1cUnitdata ud;
758 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200759 var OCT4 expect_teid;
760
761 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
762 message with cause value "Non existent" shall be zero. */
763 if (expect_causevalue == 'C0'O) {
764 expect_teid := '00000000'O;
765 } else {
766 expect_teid := ctx.teic;
767 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200768
Harald Welte41575e92017-08-13 13:49:57 +0200769 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 +0200770 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200771 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100772 if (Gx_PROC.checkstate("Connected") and expect_diameter) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100773 as_DIA_Gx_CCR(TERMINATION_REQUEST);
774 }
775 if (Gy_PROC.checkstate("Connected") and expect_diameter) {
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200776 as_DIA_Gy_CCR(ctx, TERMINATION_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100777 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200778 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200779 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
780 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200781 setverdict(pass);
782 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100783 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
784 "DeletePDPContextResp: cause expectancies didn't match");
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200785 }
786 }
787 }
788 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200789 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200790 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100791
792 /* send a Update PdP Context Request, expect Response */
793 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 {
794 var Gtp1cUnitdata ud;
795 var default d;
796
797 if (not istemplatekind(new_teid, "omit")) {
798 ctx.teid := valueof(new_teid);
799 }
800 if (not istemplatekind(new_teic, "omit")) {
801 ctx.teic := valueof(new_teic);
802 }
803
804 log("sending UpdatePDP");
805 f_send_gtpc(ts_GTPC_UpdatePDP(g_peer_c, ctx.teic_remote, g_c_seq_nr, ctx.imsi, g_restart_ctr,
806 ctx.teid, ctx.teic, ctx.nsapi, g_sgsn_ip_c, g_sgsn_ip_u,
807 ctx.pco_req, ctx.ratType, ctx.uli));
808 T_default.start;
809 d := activate(pingpong());
810 alt {
811 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, updatePDPContextResponse, ctx.teic)) -> value ud {
812 f_handle_update_req(ctx, ud, exp_cause);
813 }
814 }
815 deactivate(d);
816 T_default.stop;
817 }
818
Harald Welte811651e2017-08-05 15:25:06 +0200819 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
820 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
821 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
822 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200823
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200824 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100825 template (value) PDU_ICMP ts_ICMPv4_ERQ(octetstring data := ''O) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100826 echo := {
827 type_field := 8,
828 code := 0,
829 checksum := '0000'O,
830 identifier := '0345'O,
831 sequence_number := '0001'O,
Pau Espin Pedrol52562c92022-05-23 15:45:46 +0200832 data := data
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100833 }
834 }
835
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200836 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100837 template (present) PDU_ICMP tr_ICMPv4_ERQ := {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100838 echo := {
839 type_field := 8,
840 code := 0,
841 checksum := ?,
842 identifier := ?,
843 sequence_number := ?,
844 data := ?
845 }
846 }
847
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200848 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100849 template (present) PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100850 echo_reply := {
851 type_field := 0,
852 code := 0,
853 checksum := ?,
854 identifier := ?,
855 sequence_number := ?,
856 data := data
857 }
858 }
859
860 /* template for receiving/matching an ICMPv6 Destination Unreachable */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100861 template (present) PDU_ICMP tr_ICMPv4_DU := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100862 destination_unreachable := {
863 type_field := 1,
864 code := ?,
865 checksum := ?,
866 unused := ?,
867 original_ip_msg := ?
868 }
869 }
870
871 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100872 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 +0100873 header := {
874 ver := 4,
875 hlen := 5,
876 tos := 0,
877 tlen := tlen,
878 id := 35902,
879 res := '0'B,
880 dfrag := '1'B,
881 mfrag := '0'B,
882 foffset := 0,
883 ttl := 64,
884 proto := proto,
885 cksum := 0,
886 srcaddr := srcaddr,
887 dstaddr := dstaddr
888 },
889 ext_headers := omit,
890 payload := payload
891 }
892
Harald Welte231b9412017-08-09 17:16:31 +0200893 /* template to generate a 'Prefix Information' ICMPv6 option */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100894 template (value) OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200895 prefixInformation := {
896 typeField := 3,
897 lengthIndicator := 8,
898 prefixLength := prefix_len,
899 reserved1 := '000000'B,
900 a_Bit := '0'B,
901 l_Bit := '0'B,
902 validLifetime := oct2int('FFFFFFFF'O),
903 preferredLifetime := oct2int('FFFFFFFF'O),
904 reserved2 := '00000000'O,
905 prefix := prefix
906 }
907 }
908
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200909 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100910 template (value) PDU_ICMPv6 ts_ICMPv6_ERQ := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100911 echoRequest := {
912 typeField := 128,
913 code := 0,
914 checksum := '0000'O,
915 identifier := 0,
916 sequenceNr := 0,
917 data := ''O
918 }
919 }
920
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200921 /* template for sending an ICMPv6 router solicitation */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100922 template (value) PDU_ICMPv6 ts_ICMPv6_RS := {
Harald Welte231b9412017-08-09 17:16:31 +0200923 routerSolicitation := {
924 typeField := 133,
925 code := 0,
926 checksum := '0000'O,
927 reserved := '00000000'O,
928 /* TODO: do we need 'Source link-layer address' ? */
929 options := omit
930 }
931 }
932
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200933 /* template for sending an ICMPv6 router advertisement */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100934 template (value) PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200935 routerAdvertisement := {
936 typeField := 134,
937 code := 0,
938 checksum := '0000'O,
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100939 curHopLimit := 0,
Harald Welte231b9412017-08-09 17:16:31 +0200940 reserved := '000000'B,
941 o_Bit := '0'B,
942 m_Bit := '0'B,
943 routerLifetime := oct2int('FFFF'O),
944 reachableTime := oct2int('FFFFFFFF'O),
945 retransTimer := oct2int('FFFFFFFF'O),
946 options := {
947 ts_ICMP6_OptPrefix(prefix, prefix_len)
948 }
949 }
950 }
951
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200952 /* template for sending an ICMPv6 neighbor solicitation */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100953 template (value) PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
Harald Welte231b9412017-08-09 17:16:31 +0200954 neighborSolicitation := {
955 typeField := 135,
956 code := 0,
957 checksum := '0000'O,
958 reserved := '00000000'O,
959 targetAddress := target_addr,
960 /* TODO: do we need 'Source link-layer address' ? */
961 options := omit
962 }
963 }
964
965 /* derive ICMPv6 link-local address from lower 64bit of link_id */
966 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100967 template (present) OptionField tr_ICMP6_OptPrefix(template (present) OCT16 prefix, template (present) INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200968 prefixInformation := {
969 typeField := 3,
970 lengthIndicator := 4,
971 prefixLength := prefix_len,
972 reserved1 := ?,
973 a_Bit := ?,
974 l_Bit := ?,
975 validLifetime := ?,
976 preferredLifetime := ?,
977 reserved2 := ?,
978 prefix := prefix
979 }
980 }
981
Pau Espin Pedrolae04c792023-12-05 14:51:42 +0100982 /* template for receiving/matching an ICMPv6 'MTU' option, rfc4861 4.6.4 */
983 template (present) OptionField tr_ICMP6_OptMTU(template (present) integer mtu := ?) := {
984 mTU := {
985 typeField := 5,
986 lengthIndicator := 1,
987 reserved := ?,
988 mTU_Value := mtu
989 }
990 }
991
Harald Welte231b9412017-08-09 17:16:31 +0200992 /* template for receiving/matching an ICMPv6 router advertisement */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100993 template (present) PDU_ICMPv6 tr_ICMPv6_RA(template (present) OCT16 prefix, template (present) INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200994 routerAdvertisement := {
995 typeField := 134,
996 code := 0,
997 checksum := ?,
998 curHopLimit := ?,
999 reserved := ?,
1000 o_Bit := '0'B,
1001 m_Bit := '0'B,
1002 routerLifetime := ?,
1003 reachableTime := ?,
1004 retransTimer := ?,
Pau Espin Pedrolae04c792023-12-05 14:51:42 +01001005 options := ({ tr_ICMP6_OptPrefix(prefix, prefix_len) },
1006 { tr_ICMP6_OptPrefix(prefix, prefix_len), tr_ICMP6_OptMTU }
1007 )
Harald Welte231b9412017-08-09 17:16:31 +02001008 }
1009 }
1010
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001011 /* template for receiving/matching an ICMPv6 Destination Unreachable */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001012 template (present) PDU_ICMPv6 tr_ICMPv6_DU := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001013 destinationUnreachable := {
1014 typeField := 1,
1015 code := ?,
1016 checksum := ?,
1017 unused := ?,
1018 originalIpMsg := ?
1019 }
1020 }
1021
Stefan Sperling6cd217e2018-03-30 15:17:34 +02001022 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001023 template (present) PDU_ICMPv6 tr_ICMPv6_ERQ := {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001024 echoRequest := {
1025 typeField := 128,
1026 code := 0,
1027 checksum := ?,
1028 identifier := ?,
1029 sequenceNr := ?,
1030 data := ?
1031 }
1032 }
1033
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001034 /* template for receiving/matching an ICMPv6 echo reply */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001035 template (present) PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001036 echoReply := {
1037 typeField := 129,
1038 code := 0,
1039 checksum := ?,
1040 identifier := ?,
1041 sequenceNr := ?,
1042 data := data
1043 }
1044 }
1045
Harald Welte231b9412017-08-09 17:16:31 +02001046 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001047 template (value) IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
Harald Welte231b9412017-08-09 17:16:31 +02001048 header := {
1049 ver := 6,
1050 trclass := 0,
1051 flabel := 0,
1052 plen := 0,
1053 nexthead := nexthead,
1054 hlim := hlim,
1055 srcaddr := srcaddr,
1056 dstaddr := dstaddr
1057 },
1058 ext_headers := omit,
1059 payload := payload
1060 }
1061
1062 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
1063 return 'FE80000000000000'O & substr(link_id, 8, 8);
1064 }
1065
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001066 function f_ipv6_global(in OCT16 link_id) return OCT16 {
1067 return substr(link_id, 0, 8) & '1234123412341234'O;
1068 }
1069
1070 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
1071 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
1072 var integer i;
1073 var octetstring res := substr(addr, 0, prefix);
1074 for (i := prefix; i < lengthof(addr); i := i + 1) {
1075 var octetstring a := addr[i] xor4b '11'O;
1076 res := res & a;
1077 }
1078 return res;
1079 }
1080
Harald Welte231b9412017-08-09 17:16:31 +02001081 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
1082 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
1083 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
1084 }
1085
1086 /* generate and encode ICMPv6 router solicitation */
1087 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
1088 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
1089 var OCT16 saddr := f_ipv6_link_local(link_id);
1090
1091 var octetstring tmp;
1092 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
1093 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
1094
1095 return f_IPv6_enc(ip6);
1096 }
1097
Pau Espin Pedrol57604212022-02-14 16:54:18 +01001098 /* Get link-id from PDP Context EUA */
1099 function f_ctx_get_ipv6_interface_id(in PdpContext ctx) return OCT16 {
1100 var OCT16 interface_id;
1101 if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
1102 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1103 } else if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv6)) {
1104 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
1105 } else {
1106 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected request to submit icmpv6 rs in IPv4 PDP context");
1107 }
1108 return interface_id;
1109 }
1110
Harald Welte231b9412017-08-09 17:16:31 +02001111 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
1112 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +01001113 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001114 return f_gen_icmpv6_router_solicitation(interface_id);
1115 }
1116
1117 /* generate and encode ICMPv6 neighbor solicitation */
1118 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
1119 var octetstring tmp;
1120 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
1121 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
1122 return f_IPv6_enc(ip6);
1123 }
1124
1125 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
1126 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +01001127 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001128 var OCT16 link_local := f_ipv6_link_local(interface_id);
1129 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
1130
1131 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
1132 }
1133
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001134 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02001135 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr, octetstring pl := ''O) return octetstring {
1136 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ(pl)));
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001137 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
1138 var octetstring data := f_IPv4_enc(ip4);
1139 var OCT2 cksum := f_IPv4_checksum(data);
1140 data[10] := cksum[0];
1141 data[11] := cksum[1];
1142 return data;
1143 }
1144
1145 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
1146 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
1147 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
1148 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
1149 var octetstring data := f_IPv6_enc(ip6);
1150 return data;
1151 }
1152
1153 /* Wait for ICMPv4 from GTP */
1154 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +02001155 var Gtp1uUnitdata ud;
1156 T_default.start;
1157 alt {
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001158 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ctx.teid)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +02001159 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001160 setverdict(fail);
1161 stop;
1162 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001163 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1164 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
1165 if (ip4.header.ver != 4) {
1166 repeat;
1167 }
1168 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
1169 if (not match(icmp4, expected)) {
1170 repeat;
1171 }
1172 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001173 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
1174 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1175 "Received wrong local TEID");
1176 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001177 [] GTPU.receive { setverdict(fail); }
1178 [] T_default.timeout { setverdict(fail); }
1179 }
1180 T_default.stop;
1181 }
1182
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001183 /* Wait for ICMPv4 echo request from GTP */
1184 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
1185 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
1186 }
1187
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001188 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
1189 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
1190 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
1191 }
1192
1193 /* Wait for ICMPv6 from GTP */
1194 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
1195 var Gtp1uUnitdata ud;
1196 T_default.start;
1197 alt {
Harald Welte231b9412017-08-09 17:16:31 +02001198 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +02001199 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Pau Espin Pedrol9c1c2ae2023-12-05 14:24:49 +01001200 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1201 log2str("Received GTPU with wrong txseq while waiting for ICMPv6: ", expected));
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001202 }
Harald Welte231b9412017-08-09 17:16:31 +02001203 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1204 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001205 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +02001206 repeat;
1207 }
1208 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001209 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +02001210 repeat;
1211 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001212 /* We are waiting for RA, update ctx */
1213 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
1214 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
1215 log("RA with /64 prefix ", ctx.ip6_prefix);
1216 }
Harald Welte231b9412017-08-09 17:16:31 +02001217 }
1218 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
Pau Espin Pedrol9c1c2ae2023-12-05 14:24:49 +01001219 [] GTPU.receive {
1220 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1221 log2str("Received unexpected GTPU while waiting for ICMPv6: ", expected));
1222 }
1223 [] T_default.timeout {
1224 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1225 log2str("Timeout waiting for ICMPv6: ", expected));
1226 }
Harald Welte231b9412017-08-09 17:16:31 +02001227 }
1228 T_default.stop;
1229 }
1230
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001231 /* wait for GGSN to send us an ICMPv6 router advertisement */
1232 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
1233 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
1234 }
1235
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001236 /* Wait for ICMPv6 echo request from GTP */
1237 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
1238 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
1239 }
1240
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001241 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
1242 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
1243 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
1244 }
1245
Oliver Smithee6a0882019-03-08 11:05:46 +01001246 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
1247 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
1248 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1249 return f_gen_icmpv6_router_solicitation(interface_id);
1250 }
1251
1252 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
1253 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
1254 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1255 var OCT16 link_local := f_ipv6_link_local(interface_id);
1256 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
1257
1258 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
1259 }
1260
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001261 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
1262 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
1263 T_default.start;
1264 alt {
1265 [] GTPU.receive { setverdict(fail); }
1266 [] T_default.timeout { }
1267 }
1268 T_default.stop;
1269 }
1270
Harald Welte79737b42019-04-10 10:39:30 +02001271 /* list of protocols where we don't accept duplicates */
1272 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
1273 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
1274 var integer i;
1275 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
1276 if (id == protocol_ids_nodupes[i]) {
1277 return false;
1278 }
1279 }
1280 return true;
1281 }
1282
1283 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
1284 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
1285 var OCT2List protocol_ids := {};
1286 var integer i, j;
1287 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
1288 var OCT2 id := pco.protocols[i].protocolID;
1289 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
1290 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
1291 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
1292 }
1293 }
1294 protocol_ids := protocol_ids & { id };
1295 }
1296 }
1297
Harald Welte0ef285b2017-08-13 20:06:01 +02001298 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +02001299 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +02001300 f_init();
Harald Welte231b9412017-08-09 17:16:31 +02001301
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001302 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welte811651e2017-08-05 15:25:06 +02001303 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +02001304 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001305 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001306 }
1307
Harald Welte0ef285b2017-08-13 20:06:01 +02001308 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001309 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
1310 f_init();
1311
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001312 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001313 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1314 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001315
Harald Welte79737b42019-04-10 10:39:30 +02001316 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001317 /* verify PCO contains both primary and secondary DNS */
1318 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1319 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1320 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1321 }
1322
1323 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1324 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1325 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1326 }
1327
Harald Welteed7a1772017-08-09 20:26:20 +02001328 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001329 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001330 }
1331
Harald Welte0ef285b2017-08-13 20:06:01 +02001332 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +02001333 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
1334 f_init();
1335
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001336 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001337 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1338 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001339
Harald Welte79737b42019-04-10 10:39:30 +02001340 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +02001341 //f_send_gtpu(ctx, c_router_solicit);
1342 //f_send_gtpu(ctx, c_neigh_solicit);
1343
1344 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1345 f_wait_rtr_adv(ctx);
1346 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1347
Harald Welte811651e2017-08-05 15:25:06 +02001348 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001349 f_shutdown_helper();
Harald Welte94ade362017-08-04 00:36:55 +02001350 }
1351
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001352 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
1353 Test we can send ICMPv6 ping over GTPU to DNS server. */
1354 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
1355 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001356 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 +01001357 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1358 f_pdp_ctx_act(ctx);
1359
1360 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1361 f_wait_rtr_adv(ctx);
1362 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1363
1364 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1365
1366 /* Check if we can use valid link-local src addr. */
1367 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1368 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
Pau Espin Pedrolb63d85f2022-02-07 16:11:47 +01001369 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
1370 f_wait_icmp6_echo_reply(ctx);
1371 } else {
1372 f_wait_gtpu_fail(ctx);
1373 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001374
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001375 /* Check if we can use valid global src addr, should work */
1376 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1377 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
1378 f_wait_icmp6_echo_reply(ctx);
1379
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001380 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001381 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001382 }
1383
1384 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1385 testcase TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr() runs on GT_CT {
1386 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001387 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 +01001388 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1389 f_pdp_ctx_act(ctx);
1390
1391 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1392 f_wait_rtr_adv(ctx);
1393 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1394
1395 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1396 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1397 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1398 f_wait_gtpu_fail(ctx);
1399
1400 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001401 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001402 }
1403
1404 /* Assert that packets with wrong global src addr are dropped by GGSN */
1405 testcase TC_pdp6_act_deact_gtpu_access_wrong_global_saddr() runs on GT_CT {
1406 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001407 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 +01001408 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1409 f_pdp_ctx_act(ctx);
1410
1411 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1412 f_wait_rtr_adv(ctx);
1413 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1414
1415 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1416 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001417 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1418 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
1419 f_wait_gtpu_fail(ctx);
1420
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001421 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001422 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001423 }
1424
1425 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped */
1426 testcase TC_pdp6_act_deact_gtpu_access_ipv4_apn6() runs on GT_CT {
1427 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001428 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 +01001429 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1430 f_pdp_ctx_act(ctx);
1431
1432 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1433 f_wait_rtr_adv(ctx);
1434 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1435
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001436 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
1437 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
1438 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
1439 f_wait_gtpu_fail(ctx);
1440
1441 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001442 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001443 }
1444
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001445 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1446 testcase TC_pdp6_clients_interact() runs on GT_CT {
1447 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001448 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1449 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 +01001450 f_pdp_ctx_act(ctxA);
1451 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
1452 f_wait_rtr_adv(ctxA);
1453 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
1454
1455 f_pdp_ctx_act(ctxB);
1456 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
1457 f_wait_rtr_adv(ctxB);
1458 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
1459
1460 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1461 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1462 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1463 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1464
1465 /* Validate if clients can interact using ll addr. */
1466 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1467 f_wait_gtpu_fail(ctxB);
1468
1469 /* Validate if clients can interact using global addr. */
1470 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1471 f_wait_gtpu_fail(ctxB);
1472
1473 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001474 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001475 f_shutdown_helper();
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001476 }
1477
Harald Welte0ef285b2017-08-13 20:06:01 +02001478 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +02001479 testcase TC_pdp4_act_deact() runs on GT_CT {
1480 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001481 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001482 f_pdp_ctx_act(ctx);
1483 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001484 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001485 }
1486
Harald Welte0ef285b2017-08-13 20:06:01 +02001487 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +02001488 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
1489 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001490 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1491 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrolcff72f82024-01-26 16:58:48 +01001492 var uint8_t ipcp_req_id := oct2int(f_rnd_octstring(1));
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001493 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 +01001494 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP(ipcp_req_id));
Harald Welteed7a1772017-08-09 20:26:20 +02001495 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001496 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +01001497 /* verify IPCP is at all contained */
1498 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1499 setverdict(fail, "IPCP not found in PCO");
1500 }
1501 /* verify IPCP contains both primary and secondary DNS */
1502 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolcff72f82024-01-26 16:58:48 +01001503 if (not match(ipcp, tr_IPCP_Ack_DNS(ipcp_req_id, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1504 if (not match(ipcp, tr_IPCP_Ack_DNS(ipcp_req_id))) {
1505 if (not match(ipcp, tr_IPCP_Ack_DNS(?))) {
1506 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1507 } else {
1508 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected identifier");
1509 }
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001510 } else {
1511 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1512 }
Harald Welte71a36022017-12-04 18:55:58 +01001513 }
Harald Welteed7a1772017-08-09 20:26:20 +02001514 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001515 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001516 }
1517
Harald Weltef8298542019-04-10 10:15:28 +02001518 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
1519 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
1520 f_init();
1521 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1522 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001523 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltef8298542019-04-10 10:15:28 +02001524 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1525 f_pdp_ctx_act(ctx);
1526 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1527 /* verify IPCP is at all contained */
1528 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1529 setverdict(fail, "IPCP not found in PCO");
1530 }
1531 /* verify IPCP contains both primary and secondary DNS */
1532 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1533 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1534 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1535 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1536 } else {
1537 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1538 }
1539 }
1540 /* verify that PAP is contained */
1541 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1542 setverdict(fail, "PAP not found in PCO");
1543 }
1544 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1545 if (not match(pap, tr_PAP_AuthAck)) {
1546 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1547 }
1548 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001549 f_shutdown_helper();
Harald Weltef8298542019-04-10 10:15:28 +02001550 }
1551
Harald Welte0ef285b2017-08-13 20:06:01 +02001552 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001553 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1554 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001555 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001556 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001557 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001558
Harald Welte79737b42019-04-10 10:39:30 +02001559 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001560 /* verify PCO contains both primary and secondary DNS */
1561 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1562 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1563 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1564 }
1565
1566 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1567 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1568 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1569 }
1570
Harald Welteed7a1772017-08-09 20:26:20 +02001571 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001572 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001573 }
1574
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001575 /* Test PDP context activation for dynamic IPv4 EUA.
1576 Test we can send ICMPv6 ping over GTPU to DNS server. */
1577 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1578 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001579 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 +01001580 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1581 f_pdp_ctx_act(ctx);
1582
Harald Welte79737b42019-04-10 10:39:30 +02001583 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001584 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1585
1586 /* Check if we can use valid global src addr, should work */
1587 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1588 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1589 f_wait_icmp4_echo_reply(ctx);
1590
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001591 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001592 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001593 }
1594
1595 /* Assert that packets with wrong global src addr are dropped by GGSN */
1596 testcase TC_pdp4_act_deact_gtpu_access_wrong_saddr() runs on GT_CT {
1597 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001598 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 +01001599 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1600 f_pdp_ctx_act(ctx);
1601
1602 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1603 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1604 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001605 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1606 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1607 f_wait_gtpu_fail(ctx);
1608
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001609 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001610 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001611 }
1612
1613 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1614 testcase TC_pdp4_act_deact_gtpu_access_ipv6_apn4() runs on GT_CT {
1615 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001616 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 +01001617 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1618 f_pdp_ctx_act(ctx);
1619
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001620 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1621 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1622 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1623 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001624
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001625 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001626 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001627 }
1628
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001629 /* Helper function for tests below. */
1630 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001631 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001632 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1633 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 +01001634 f_pdp_ctx_act(ctxA);
1635 f_pdp_ctx_act(ctxB);
1636 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1637 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1638 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1639 f_wait_icmp4_echo_request(ctxB);
1640
1641 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001642 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001643 }
1644
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001645 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1646 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001647 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001648 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001649 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001650 }
1651
1652 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1653 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001654 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001655 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001656 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001657 }
1658
Harald Weltedca80052017-08-13 20:01:38 +02001659 testcase TC_echo_req_resp() runs on GT_CT {
1660 f_init();
1661 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1662 T_default.start;
1663 alt {
1664 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1665 [] GTPC.receive { repeat; };
1666 [] T_default.timeout { setverdict(fail); }
1667 }
1668 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001669 f_shutdown_helper();
Harald Weltedca80052017-08-13 20:01:38 +02001670 }
1671
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001672 testcase TC_echo_req_resp_gtpu() runs on GT_CT {
1673 f_init();
1674 GTPU.send(ts_GTPU_PING(g_peer_u, g_d_seq_nr));
1675 T_default.start;
1676 alt {
1677 [] GTPU.receive(tr_GTPU_PONG(g_peer_u)) { setverdict(pass); };
1678 [] GTPU.receive { repeat; };
1679 [] T_default.timeout { setverdict(fail); }
1680 }
1681 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001682 f_shutdown_helper();
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001683 }
1684
Philipp Maier33e52612018-05-30 17:22:02 +02001685 /* Test if the parser can cope with PCO that only contain either a
1686 * single primary DNS or a secondary DNS. */
1687 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1688
1689 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1690 * the test is executed.
1691 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1692
1693 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001694 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001695 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1696 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1697 var octetstring pco_neg_dns;
1698 var octetstring pco_neg_dns_expected;
1699
1700 /* PCO with primary DNS only */
1701 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1702 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001703 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001704 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1705 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1706 /* Note: The prepended hex bytes encode the following information:
1707 * 0x02 = Configuration ACK
1708 * 0x00 = Identifier
1709 * 0x000a = Length
1710 * 0x81 = Type (Primary DNS Server Address)
1711 * 0x06 = Length
1712 * (4 byte IP-Address appended) */
1713 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1714 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1715 }
1716 f_pdp_ctx_del(ctx, '1'B);
1717
1718 /* PCO with secondary DNS only */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001719 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001720 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1721 f_pdp_ctx_act(ctx);
1722 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1723 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1724 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1725 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1726 }
1727 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001728 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001729 }
1730
1731 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1732 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1733 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1734 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1735
1736 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1737 * the test is executed.
1738 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1739
1740 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001741 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001742 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1743 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1744 var octetstring pco_neg_dns;
1745 var octetstring pco_neg_dns_expected;
1746
1747 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1748 f_pdp_ctx_act(ctx);
1749
1750 /* Check if primary DNS is contained */
1751 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1752 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1753 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1754 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1755 }
Philipp Maier33e52612018-05-30 17:22:02 +02001756
1757 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001758 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1759 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001760 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1761 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1762 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1763 }
1764 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001765 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001766 }
1767
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001768 /* Validate that SUT updates remote TEIC when requested through UpdatePDPContextRequest */
1769 testcase TC_pdp4_act_update_teic() runs on GT_CT {
1770 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001771 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 +01001772 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1773 f_pdp_ctx_act(ctx);
1774
1775 /* UpdatePDPContestRequest changing the local TEIC */
1776 var OCT4 new_teic := ctx.teic;
1777 new_teic[3] := new_teic[3] xor4b '11'O;
1778 f_pdp_ctx_update(ctx, new_teic := new_teic);
1779
1780 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001781 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001782 }
1783
1784 /* Validate that SUT updates remote TEID when requested through UpdatePDPContextRequest */
1785 testcase TC_pdp4_act_update_teid() runs on GT_CT {
1786 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001787 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 +01001788 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1789 f_pdp_ctx_act(ctx);
1790
1791 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1792 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1793 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1794
1795 /* Data is sent (back) to the local TEID established during CreatePDPContext */
1796 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1797 f_wait_icmp4_echo_reply(ctx);
1798
1799 /* UpdatePDPContestRequest changing the local TEID */
1800 var OCT4 new_teid := ctx.teid;
1801 new_teid[3] := new_teid[3] xor4b '11'O;
1802 f_pdp_ctx_update(ctx, new_teid := new_teid);
1803
1804 /* Check if we can send data after updating the PDP context. Answer should be sent to the new TEID */
1805 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1806 f_wait_icmp4_echo_reply(ctx);
1807
1808 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001809 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001810 }
1811
Oliver Smithee6a0882019-03-08 11:05:46 +01001812 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1813 testcase TC_pdp46_act_deact() runs on GT_CT {
1814 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001815 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001816 f_pdp_ctx_act(ctx);
1817 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001818 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001819 }
1820
1821 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1822 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1823 f_init();
1824 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1825 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001826 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001827 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1828 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001829 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001830 /* verify IPCP is at all contained */
1831 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1832 setverdict(fail, "IPCP not found in PCO");
1833 }
Harald Welte79737b42019-04-10 10:39:30 +02001834 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001835 /* verify IPCP contains both primary and secondary IPv4 DNS */
1836 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1837 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1838 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1839 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1840 } else {
1841 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1842 }
1843 }
1844 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001845 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001846 }
1847
1848 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1849 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1850 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001851 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001852 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1853 f_pdp_ctx_act(ctx);
1854
1855 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1856 f_wait_rtr_adv(ctx);
1857 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1858
1859 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001860 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001861 }
1862
1863 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1864 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1865 f_init();
1866
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001867 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001868 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1869 f_pdp_ctx_act(ctx);
1870
Harald Welte79737b42019-04-10 10:39:30 +02001871 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001872 /* verify PCO contains both primary and secondary IPv4 DNS */
1873 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1874 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1875 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1876 }
1877
1878 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1879 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1880 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1881 }
1882
1883 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001884 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001885 }
1886
1887 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1888 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1889 f_init();
1890
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001891 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001892 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1893 f_pdp_ctx_act(ctx);
1894
Harald Welte79737b42019-04-10 10:39:30 +02001895 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001896 /* verify PCO contains both primary and secondary IPv6 DNS */
1897 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1898 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1899 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1900 }
1901
1902 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1903 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1904 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1905 }
1906
1907 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001908 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001909 }
1910
1911 /* Test PDP context activation for dynamic IPv4v6 EUA.
1912 Test we can send ICMPv6 ping over GTPU to DNS server. */
1913 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1914 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001915 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001916 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1917 f_pdp_ctx_act(ctx);
1918
1919 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1920
1921 /* Check if we can use valid global src addr, should work */
1922 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1923 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1924 f_wait_icmp4_echo_reply(ctx);
1925
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001926 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001927 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001928 }
1929
1930 /* Assert that packets with wrong ipv4 src addr are dropped by GGSN on APN IPv4v6 */
1931 testcase TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4() runs on GT_CT {
1932 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001933 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 +01001934 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1935 f_pdp_ctx_act(ctx);
1936
1937 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1938 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
Oliver Smithee6a0882019-03-08 11:05:46 +01001939 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1940 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1941 f_wait_gtpu_fail(ctx);
1942
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001943 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001944 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001945 }
1946
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001947 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1948 testcase TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6() runs on GT_CT {
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001949 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001950 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 +01001951 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1952 f_pdp_ctx_act(ctx);
1953
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001954 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1955 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1956 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1957 f_wait_gtpu_fail(ctx);
1958
1959 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001960 f_shutdown_helper();
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001961 }
1962
1963 /* Assert that packets with wrong ipv6 global src addr are dropped by GGSN on APN IPv4v6 */
1964 testcase TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6() runs on GT_CT {
1965 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001966 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 +01001967 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1968 f_pdp_ctx_act(ctx);
1969
1970 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1971 f_wait_rtr_adv(ctx);
1972 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1973
1974 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1975 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1976 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1977 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
Oliver Smithee6a0882019-03-08 11:05:46 +01001978 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001979
Oliver Smithee6a0882019-03-08 11:05:46 +01001980 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001981 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001982 }
1983
1984 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1985 testcase TC_pdp46_clients_interact() runs on GT_CT {
1986 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001987 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1988 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001989 f_pdp_ctx_act(ctxA);
1990 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1991 f_wait_rtr_adv(ctxA);
1992 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1993
1994 f_pdp_ctx_act(ctxB);
1995 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1996 f_wait_rtr_adv(ctxB);
1997 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1998
1999 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
2000 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
2001 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
2002 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
2003
2004 /* Validate if clients can interact using ll addr. */
2005 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
2006 f_wait_gtpu_fail(ctxB);
2007
2008 /* Validate if clients can interact using global addr. */
2009 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
2010 f_wait_gtpu_fail(ctxB);
2011
2012 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02002013 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002014 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01002015 }
2016
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002017 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
2018 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002019 const OCT1 cause_accept := '80'O; /* Normal accept cause */
2020 const OCT1 cause_new_pdp_type := '81'O; /* Cause: New PDP type due to network preference */
2021 const OCT1 cause_unknown_pdp := 'DC'O; /* Cause: Unknown PDP address or PDP type */
2022 var CreatePDPContextResponse cpr;
2023
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002024 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002025 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 +01002026 cpr := f_pdp_ctx_act(ctx46, (cause_unknown_pdp, cause_new_pdp_type));
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002027
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002028 if (cpr.cause.causevalue == cause_new_pdp_type) {
2029 /* 3GPP TS 23.060 sec 9.2.1: "If the MS requests PDP type IPv4v6,
2030 * but the operator preferences dictate the use of a single IP
2031 * version only, the PDP type shall be changed to a single address
2032 * PDP type (IPv4 or IPv6) and a reason cause shall be returned to
2033 * the MS indicating that only the assigned PDP type is allowed. In
2034 * this case, the MS shall not request another PDP context for the
2035 * other PDP type during the existence of the PDP context." */
2036 f_pdp_ctx_del(ctx46, '1'B);
2037 } else {
2038 /* 3GPP TS 23.060 sec 9.2.1 NOTE 5: If the MS requests PDP type
2039 * IPv4v6, and the PDP context is rejected due to "unknown PDP
2040 * type", the MS can attempt to establish dual-stack connectivity
2041 * by performing two PDP context request procedures to activate an
2042 * IPv4 PDP context and an IPv6 PDP context, both to the same APN. A
2043 * typical MS first attempts v4v6, and if rejected, then tries v4
2044 * and v6 separetly */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002045 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 +01002046 f_pdp_ctx_act(ctx4, cause_accept); /* Normal accept cause */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002047
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002048 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 +01002049 f_pdp_ctx_act(ctx6, cause_unknown_pdp); /* Cause: Unknown PDP address or PDP type */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002050
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002051 f_pdp_ctx_del(ctx4, '1'B);
2052 }
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002053 f_shutdown_helper();
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002054 }
2055
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002056 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
2057 testcase TC_pdp_act2_recovery() runs on GT_CT {
2058 var Gtp1cUnitdata ud;
2059 var default d;
2060 var boolean ctxA_deleted := false;
2061 var boolean ctxB_created := false;
2062
2063 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002064 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2065 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 +02002066 f_pdp_ctx_act(ctxA);
2067
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06002068 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002069
2070 log("sending 2nd CreatePDP (recovery increased)");
2071 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
2072 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
2073 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
2074 T_default.start;
2075 d := activate(pingpong());
2076 alt {
2077 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
2078 f_handle_create_req(ctxB, ud);
2079 if (not ctxB_created) {
2080 ctxB_created := true;
2081 setverdict(pass);
2082 } else {
2083 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
2084 }
2085
2086 if (not ctxA_deleted) {
2087 repeat;
2088 }
2089 }
2090 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
2091 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
2092 setverdict(pass);
2093 } else {
2094 setverdict(fail);
2095 }
2096
2097 if (not ctxA_deleted) {
2098 ctxA_deleted := true;
2099 setverdict(pass);
2100 } else {
2101 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
2102 }
2103
2104 if (not ctxB_created) {
2105 repeat;
2106 }
2107 }
2108 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
2109 setverdict(fail, "GGSN dropping still valid pdp ctx");
2110 }
2111 }
2112 deactivate(d);
2113 T_default.stop;
2114
2115 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002116 f_shutdown_helper();
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002117 }
2118
2119
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +01002120 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent responses (T3-RESPONSE * N3-REQUESTS):
2121 * 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 +02002122 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
2123 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002124 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 +02002125 f_pdp_ctx_act(ctx);
2126 f_pdp_ctx_del(ctx, '1'B);
2127 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +01002128 f_sleep(int2float(mp_t3_response));
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002129 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
2130 duplicate. If it was not a duplicate, osmo-ggsn would answer
2131 with a failure since that PDP ctx was already deleted. */
Pau Espin Pedrold6b51332022-05-19 17:47:11 +02002132 if (g_c_seq_nr == 0) {
2133 g_c_seq_nr := 65535;
2134 } else {
2135 g_c_seq_nr := g_c_seq_nr - 1;
2136 }
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01002137 f_pdp_ctx_del(ctx, '1'B, expect_diameter := false);
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002138
2139 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
2140 var OCT1 cause_nonexistent := 'C0'O;
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01002141 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent, expect_diameter := false);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002142 f_shutdown_helper();
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002143 }
2144
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002145 /* Activate PDP context + trigger Recovery procedure through EchoResp */
2146 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
2147 var Gtp1cUnitdata ud;
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002148 g_use_echo_intval := 5;
2149 timer T_echo;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002150 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002151 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 +02002152 f_pdp_ctx_act(ctx);
2153
2154 /* Wait to receive echo request and send initial Restart counter */
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002155 T_echo.start(int2float(g_use_echo_intval) + 1.0);
2156 alt {
2157 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002158 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
2159 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002160 }
2161 [] T_echo.timeout {
2162 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2163 "Timeout waiting for ping");
2164 }
2165 }
2166 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002167
2168 /* Wait to receive second echo request and send incremented Restart
2169 counter. This will fake a restarted SGSN, and pdp ctx allocated
2170 should be released by GGSN */
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06002171 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002172 T_echo.start(int2float(g_use_echo_intval) + 1.0);
2173 alt {
2174 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002175 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
2176 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002177 }
2178 [] T_echo.timeout {
2179 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2180 "Timeout waiting for ping");
2181 }
2182 }
2183 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002184 f_pdp_ctx_exp_del_req(ctx, omit, true);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002185 f_shutdown_helper();
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002186 }
2187
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002188 /* Test creation, user plane and deletion of big amount (1000) of concurrent PDP context */
2189 testcase TC_lots_of_concurrent_pdp_ctx() runs on GT_CT {
2190 var Gtp1cUnitdata udc;
2191 var Gtp1uUnitdata udu;
2192 const integer num_ctx := 1000;
2193 var PdpContext ctx[num_ctx];
2194 timer T_next := 0.01;
2195 var integer next_req_ctx := 0;
2196 var integer rx_resp_ctx := 0;
2197 var integer rx_pong := 0;
2198 var OCT4 dns1_addr;
2199 var OCT4 saddr;
2200 var integer teic;
2201 var integer idx;
2202
2203 f_init();
2204
2205 for (var integer i := 0; i < num_ctx; i := i + 1) {
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002206 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 +01002207 ctx[i].teic := int2oct(i+1, 4); /* +1: skip TEIC=0 */
2208 ctx[i].teid := int2oct(i+1, 4); /* +1: skip TEID=0 */
2209 ctx[i].pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2210 }
2211
2212 T_default.start(60.0);
2213
2214 T_next.start;
2215 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002216 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002217 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, INITIAL_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002218 [] pingpong();
2219 [] T_next.timeout {
2220 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx[next_req_ctx].imsi, g_restart_ctr,
2221 ctx[next_req_ctx].teid, ctx[next_req_ctx].teic, ctx[next_req_ctx].nsapi,
2222 ctx[next_req_ctx].eua, ctx[next_req_ctx].apn, g_sgsn_ip_c, g_sgsn_ip_u,
2223 ctx[next_req_ctx].msisdn, ctx[next_req_ctx].pco_req, ctx[next_req_ctx].ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002224 ctx[next_req_ctx].uli, ctx[next_req_ctx].charging_char, ctx[next_req_ctx].imeisv,
2225 ctx[next_req_ctx].ms_tz));
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002226 next_req_ctx := next_req_ctx + 1;
2227 if (next_req_ctx < num_ctx) {
2228 T_next.start;
2229 }
2230 repeat;
2231 }
2232 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2233 teic := oct2int(udc.gtpc.teid);
2234 if (not match(teic, (1 .. num_ctx))) {
2235 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2236 "Rx Unexpected TEIC");
2237 }
2238 idx := teic - 1;
2239 f_handle_create_req(ctx[idx], udc);
2240 rx_resp_ctx := rx_resp_ctx + 1;
2241
2242 dns1_addr := f_PCO_extract_proto(ctx[idx].pco_neg, '000d'O);
2243 saddr := ctx[idx].eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2244 f_send_gtpu(ctx[idx], f_gen_icmpv4_echo(saddr, dns1_addr));
2245 repeat;
2246 }
2247 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value udu {
2248 var octetstring gpdu := udu.gtpu.gtpu_IEs.g_PDU_IEs.data;
2249 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
2250 if (ip4.header.ver != 4) {
2251 repeat;
2252 }
2253 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
2254 if (not match(icmp4, (tr_ICMPv4_ERP, tr_ICMPv4_DU))) {
2255 repeat;
2256 }
2257 rx_pong := rx_pong + 1;
2258 if (rx_pong < num_ctx) {
2259 repeat;
2260 }
2261 setverdict(pass);
2262 }
2263 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2264 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2265 }
2266
2267 /* Let's close them now: */
2268 next_req_ctx := 0;
2269 rx_resp_ctx := 0;
2270 T_next.start;
2271 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002272 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002273 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002274 [] pingpong();
2275 [] T_next.timeout {
2276 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));
2277 next_req_ctx := next_req_ctx + 1;
2278 if (next_req_ctx < num_ctx) {
2279 T_next.start;
2280 }
2281 repeat;
2282 }
2283 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2284 teic := oct2int(udc.gtpc.teid);
2285 if (not match(teic, (1 .. num_ctx))) {
2286 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2287 "Rx Unexpected TEIC");
2288 }
2289 rx_resp_ctx := rx_resp_ctx + 1;
2290 if (rx_resp_ctx < num_ctx) {
2291 repeat;
2292 }
2293 setverdict(pass);
2294 }
2295 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2296 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2297 }
2298 T_next.stop;
2299
2300 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002301 f_shutdown_helper();
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002302 }
2303
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002304 /* Test callocation of PDP contexts until reaching addr pool exhaustion */
2305 type record of OCT4 TEIClist;
2306 testcase TC_addr_pool_exhaustion() runs on GT_CT {
2307 var Gtp1cUnitdata udc;
2308 var Gtp1uUnitdata udu;
2309 var PdpContext ctx;
2310 timer T_next := 0.005;
2311 var integer next_req_ctx := 0;
2312 var integer rx_resp_ctx := 0;
2313 var integer num_ctx;
2314 var boolean cont_req := true;
2315 var CreatePDPContextResponse cpr;
2316 var TEIClist teic_list := {};
2317 var integer teic;
2318
2319 f_init();
2320
2321 T_default.start(120.0);
2322
2323 T_next.start;
2324 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002325 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002326 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, INITIAL_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002327 [] pingpong();
2328 [] T_next.timeout {
2329 if (cont_req) {
2330 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 +02002331 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 +01002332 ctx.nsapi := '0001'B;
2333 ctx.teic := int2oct(next_req_ctx+1, 4); /* +1: skip TEIC=0 */
2334 ctx.teid := int2oct(next_req_ctx+1, 4); /* +1: skip TEID=0 */
2335 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx.imsi, g_restart_ctr,
2336 ctx.teid, ctx.teic, ctx.nsapi,
2337 ctx.eua, ctx.apn, g_sgsn_ip_c, g_sgsn_ip_u,
2338 ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002339 ctx.uli, ctx.charging_char, ctx.imeisv,
2340 ctx.ms_tz));
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002341 next_req_ctx := next_req_ctx + 1;
2342 }
2343 T_next.start;
2344 }
2345 repeat;
2346 }
2347 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2348 cpr := udc.gtpc.gtpc_pdu.createPDPContextResponse;
2349
2350 if (cpr.cause.causevalue == '80'O) {
2351 teic_list := teic_list & {cpr.teidControlPlane.teidControlPlane};
2352 } else {
2353 if (cont_req == true) {
2354 num_ctx := rx_resp_ctx;
2355 log("Successfully created ", num_ctx, " PDP contexts before exhausting the pool");
2356 setverdict(pass);
2357 }
2358 cont_req := false;
2359 }
2360 rx_resp_ctx := rx_resp_ctx + 1;
2361 if (not cont_req and next_req_ctx == rx_resp_ctx) {
2362 break;
2363 } else {
2364 repeat;
2365 }
2366 }
2367 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2368 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2369 }
2370
2371 /* Let's close them now: */
2372 next_req_ctx := 0;
2373 rx_resp_ctx := 0;
2374 T_next.start;
2375 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002376 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002377 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002378 [] pingpong();
2379 [] T_next.timeout {
2380 f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, teic_list[next_req_ctx], '0001'B, '1'B));
2381 next_req_ctx := next_req_ctx + 1;
2382 if (next_req_ctx < num_ctx) {
2383 T_next.start;
2384 }
2385 repeat;
2386 }
2387 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2388 teic := oct2int(udc.gtpc.teid);
2389 if (not match(teic, (1 .. num_ctx))) {
2390 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2391 "Rx Unexpected TEIC");
2392 }
2393 rx_resp_ctx := rx_resp_ctx + 1;
2394 if (rx_resp_ctx < num_ctx) {
2395 repeat;
2396 }
2397 setverdict(pass);
2398 }
2399 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2400 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2401 }
2402 T_next.stop;
2403
2404 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002405 f_shutdown_helper();
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002406 }
2407
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002408 /* Test charging over Gy interface. */
2409 testcase TC_gy_charging_cc_time() runs on GT_CT {
2410 var default d;
2411
2412 g_gy_validity_time := 3; /* Grant access for 3 seconds, needs to be re-validated afterwards */
2413 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002414 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 +01002415 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2416 f_pdp_ctx_act(ctx);
2417
2418 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2419
2420 /* Send some UL traffic: */
2421 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2422 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2423 f_wait_icmp4_echo_reply(ctx);
2424
2425 T_default.start(10.0);
2426 d := activate(pingpong());
2427
2428 g_gy_validity_time := 2;
2429 /* First update reports octests/pkt on both UL/DL (see icmp ping-pong above) */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002430 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002431 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (3..4), 28, 28);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002432
2433 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002434 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002435 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (2..3), 0, 0);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002436
2437 /* Third update: make sure report contains again octets/pkts for both UL/DL: */
2438 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2439 f_wait_icmp4_echo_reply(ctx);
2440 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2441 f_wait_icmp4_echo_reply(ctx);
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002442 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002443 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (2..3), 56, 56);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002444
2445 /* Let the CCA reach the GGSN */
2446 f_sleep(0.5);
2447 deactivate(d);
2448 T_default.stop;
2449
2450 /* Send some data and validate it is reported in the TERMINATION_REQUEST
2451 * (triggered by PFCP Session Deletion Response): */
2452 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2453 f_wait_icmp4_echo_reply(ctx);
2454
2455 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002456 f_validate_gy_cc_report(g_rx_gy, FINAL, (0..2), 28, 28);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002457
2458
2459 f_shutdown_helper();
2460 }
2461
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002462 /* Test Volume-Quota-Thresold AVP triggers request before Validity-Time */
2463 testcase TC_gy_charging_volume_quota_threshold() runs on GT_CT {
2464 var default d;
2465 timer Tout;
2466 g_gy_volume_threshold := 1000; /* Will make a trigger when we send bigger payload below */
2467 g_gy_validity_time := 8; /* Grant access for 8 seconds, needs to be re-validated afterwards */
2468 f_init();
2469 var float tout_sec := int2float(g_gy_validity_time) / 2.0;
2470 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2471 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2472 f_pdp_ctx_act(ctx);
2473
2474 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2475
2476 T_default.start(40.0);
2477 d := activate(pingpong());
2478
2479 /* Send some UL traffic: */
2480 var octetstring payload := f_rnd_octstring(1200);
2481 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2482 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr, payload));
2483 f_wait_icmp4_echo_reply(ctx);
2484
2485 /* ICMP Req generates one report: */
2486 Tout.start(tout_sec);
2487 alt {
2488 [] as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
2489 [] Tout.timeout {
2490 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2491 "TImeout waiting for Gy UPDATE triggered by Volume-Quota-Threshold");
2492 }
2493 }
Pau Espin Pedrol5fa8f782022-10-03 13:57:54 +02002494 f_validate_gy_cc_report(g_rx_gy, THRESHOLD, (0..6), (1200..1400), 0);
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002495
2496 /* ICMP Resp (echo back) generates one report: */
2497 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol5fa8f782022-10-03 13:57:54 +02002498 f_validate_gy_cc_report(g_rx_gy, THRESHOLD, (0..1), 0, (1200..1400));
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002499
2500 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
2501 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
2502 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (8..9), 0, 0);
2503
2504 /* Let the CCA reach the GGSN */
2505 f_sleep(0.5);
2506 deactivate(d);
2507 T_default.stop;
2508
2509 f_pdp_ctx_del(ctx, '1'B);
2510 f_validate_gy_cc_report(g_rx_gy, FINAL, (0..2), 0, 0);
2511
2512
2513 f_shutdown_helper();
2514 }
2515
Harald Welte94ade362017-08-04 00:36:55 +02002516 control {
Harald Welteed7a1772017-08-09 20:26:20 +02002517 execute(TC_pdp4_act_deact());
2518 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02002519 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02002520 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002521 execute(TC_pdp4_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002522 execute(TC_pdp4_act_deact_gtpu_access_wrong_saddr());
2523 execute(TC_pdp4_act_deact_gtpu_access_ipv6_apn4());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02002524 execute(TC_pdp4_clients_interact_with_txseq());
2525 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02002526 execute(TC_pdp4_act_deact_with_single_dns());
2527 execute(TC_pdp4_act_deact_with_separate_dns());
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01002528 execute(TC_pdp4_act_update_teic());
2529 execute(TC_pdp4_act_update_teid());
Harald Welteed7a1772017-08-09 20:26:20 +02002530
2531 execute(TC_pdp6_act_deact());
2532 execute(TC_pdp6_act_deact_pcodns());
2533 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002534 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002535 execute(TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr());
2536 execute(TC_pdp6_act_deact_gtpu_access_wrong_global_saddr());
2537 execute(TC_pdp6_act_deact_gtpu_access_ipv4_apn6());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01002538 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02002539
Oliver Smithee6a0882019-03-08 11:05:46 +01002540 execute(TC_pdp46_act_deact());
2541 execute(TC_pdp46_act_deact_ipcp());
2542 execute(TC_pdp46_act_deact_icmp6());
2543 execute(TC_pdp46_act_deact_pcodns4());
2544 execute(TC_pdp46_act_deact_pcodns6());
2545 execute(TC_pdp46_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002546 execute(TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4());
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01002547 execute(TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002548 execute(TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6());
Oliver Smithee6a0882019-03-08 11:05:46 +01002549 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002550 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01002551
Harald Weltedca80052017-08-13 20:01:38 +02002552 execute(TC_echo_req_resp());
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01002553 execute(TC_echo_req_resp_gtpu());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002554 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002555 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002556
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01002557 execute(TC_pdp_act_restart_ctr_echo());
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002558
2559 execute(TC_lots_of_concurrent_pdp_ctx());
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002560 /* Keep at the end, crashes older osmo-ggsn versions (OS#5469): */
2561 execute(TC_addr_pool_exhaustion());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002562
2563 /* open5gs specific tests: */
2564 if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
2565 execute(TC_gy_charging_cc_time());
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002566 execute(TC_gy_charging_volume_quota_threshold());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002567 }
Harald Welte94ade362017-08-04 00:36:55 +02002568 }
Harald Welte379d45a2017-08-03 09:55:15 +02002569}