blob: d7de4437434661edce7def44dc1a9b413d5a8630 [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,
331 "pinpong T_default timeout");
332 };
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 Pedrold25095f2022-05-18 16:29:05 +02001492 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001493 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +02001494 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001495 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +01001496 /* verify IPCP is at all contained */
1497 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1498 setverdict(fail, "IPCP not found in PCO");
1499 }
1500 /* verify IPCP contains both primary and secondary DNS */
1501 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001502 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1503 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1504 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1505 } else {
1506 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1507 }
Harald Welte71a36022017-12-04 18:55:58 +01001508 }
Harald Welteed7a1772017-08-09 20:26:20 +02001509 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001510 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001511 }
1512
Harald Weltef8298542019-04-10 10:15:28 +02001513 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
1514 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
1515 f_init();
1516 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1517 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001518 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltef8298542019-04-10 10:15:28 +02001519 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1520 f_pdp_ctx_act(ctx);
1521 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1522 /* verify IPCP is at all contained */
1523 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1524 setverdict(fail, "IPCP not found in PCO");
1525 }
1526 /* verify IPCP contains both primary and secondary DNS */
1527 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1528 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1529 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1530 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1531 } else {
1532 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1533 }
1534 }
1535 /* verify that PAP is contained */
1536 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1537 setverdict(fail, "PAP not found in PCO");
1538 }
1539 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1540 if (not match(pap, tr_PAP_AuthAck)) {
1541 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1542 }
1543 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001544 f_shutdown_helper();
Harald Weltef8298542019-04-10 10:15:28 +02001545 }
1546
Harald Welte0ef285b2017-08-13 20:06:01 +02001547 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001548 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1549 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001550 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001551 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001552 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001553
Harald Welte79737b42019-04-10 10:39:30 +02001554 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001555 /* verify PCO contains both primary and secondary DNS */
1556 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1557 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1558 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1559 }
1560
1561 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1562 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1563 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1564 }
1565
Harald Welteed7a1772017-08-09 20:26:20 +02001566 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001567 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001568 }
1569
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001570 /* Test PDP context activation for dynamic IPv4 EUA.
1571 Test we can send ICMPv6 ping over GTPU to DNS server. */
1572 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1573 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001574 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 +01001575 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1576 f_pdp_ctx_act(ctx);
1577
Harald Welte79737b42019-04-10 10:39:30 +02001578 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001579 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1580
1581 /* Check if we can use valid global src addr, should work */
1582 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1583 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1584 f_wait_icmp4_echo_reply(ctx);
1585
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001586 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001587 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001588 }
1589
1590 /* Assert that packets with wrong global src addr are dropped by GGSN */
1591 testcase TC_pdp4_act_deact_gtpu_access_wrong_saddr() runs on GT_CT {
1592 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001593 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 +01001594 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1595 f_pdp_ctx_act(ctx);
1596
1597 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1598 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1599 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001600 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1601 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1602 f_wait_gtpu_fail(ctx);
1603
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001604 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001605 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001606 }
1607
1608 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1609 testcase TC_pdp4_act_deact_gtpu_access_ipv6_apn4() runs on GT_CT {
1610 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001611 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 +01001612 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1613 f_pdp_ctx_act(ctx);
1614
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001615 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1616 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1617 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1618 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001619
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001620 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001621 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001622 }
1623
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001624 /* Helper function for tests below. */
1625 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001626 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001627 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1628 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 +01001629 f_pdp_ctx_act(ctxA);
1630 f_pdp_ctx_act(ctxB);
1631 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1632 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1633 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1634 f_wait_icmp4_echo_request(ctxB);
1635
1636 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001637 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001638 }
1639
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001640 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1641 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001642 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001643 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001644 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001645 }
1646
1647 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1648 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001649 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001650 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001651 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001652 }
1653
Harald Weltedca80052017-08-13 20:01:38 +02001654 testcase TC_echo_req_resp() runs on GT_CT {
1655 f_init();
1656 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1657 T_default.start;
1658 alt {
1659 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1660 [] GTPC.receive { repeat; };
1661 [] T_default.timeout { setverdict(fail); }
1662 }
1663 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001664 f_shutdown_helper();
Harald Weltedca80052017-08-13 20:01:38 +02001665 }
1666
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001667 testcase TC_echo_req_resp_gtpu() runs on GT_CT {
1668 f_init();
1669 GTPU.send(ts_GTPU_PING(g_peer_u, g_d_seq_nr));
1670 T_default.start;
1671 alt {
1672 [] GTPU.receive(tr_GTPU_PONG(g_peer_u)) { setverdict(pass); };
1673 [] GTPU.receive { repeat; };
1674 [] T_default.timeout { setverdict(fail); }
1675 }
1676 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001677 f_shutdown_helper();
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001678 }
1679
Philipp Maier33e52612018-05-30 17:22:02 +02001680 /* Test if the parser can cope with PCO that only contain either a
1681 * single primary DNS or a secondary DNS. */
1682 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1683
1684 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1685 * the test is executed.
1686 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1687
1688 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001689 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001690 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1691 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1692 var octetstring pco_neg_dns;
1693 var octetstring pco_neg_dns_expected;
1694
1695 /* PCO with primary DNS only */
1696 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1697 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001698 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001699 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1700 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1701 /* Note: The prepended hex bytes encode the following information:
1702 * 0x02 = Configuration ACK
1703 * 0x00 = Identifier
1704 * 0x000a = Length
1705 * 0x81 = Type (Primary DNS Server Address)
1706 * 0x06 = Length
1707 * (4 byte IP-Address appended) */
1708 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1709 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1710 }
1711 f_pdp_ctx_del(ctx, '1'B);
1712
1713 /* PCO with secondary DNS only */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001714 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001715 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1716 f_pdp_ctx_act(ctx);
1717 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1718 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1719 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1720 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1721 }
1722 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001723 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001724 }
1725
1726 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1727 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1728 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1729 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1730
1731 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1732 * the test is executed.
1733 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1734
1735 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001736 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001737 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1738 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1739 var octetstring pco_neg_dns;
1740 var octetstring pco_neg_dns_expected;
1741
1742 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1743 f_pdp_ctx_act(ctx);
1744
1745 /* Check if primary DNS is contained */
1746 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1747 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1748 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1749 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1750 }
Philipp Maier33e52612018-05-30 17:22:02 +02001751
1752 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001753 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1754 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001755 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1756 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1757 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1758 }
1759 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001760 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001761 }
1762
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001763 /* Validate that SUT updates remote TEIC when requested through UpdatePDPContextRequest */
1764 testcase TC_pdp4_act_update_teic() runs on GT_CT {
1765 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001766 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 +01001767 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1768 f_pdp_ctx_act(ctx);
1769
1770 /* UpdatePDPContestRequest changing the local TEIC */
1771 var OCT4 new_teic := ctx.teic;
1772 new_teic[3] := new_teic[3] xor4b '11'O;
1773 f_pdp_ctx_update(ctx, new_teic := new_teic);
1774
1775 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001776 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001777 }
1778
1779 /* Validate that SUT updates remote TEID when requested through UpdatePDPContextRequest */
1780 testcase TC_pdp4_act_update_teid() runs on GT_CT {
1781 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001782 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 +01001783 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1784 f_pdp_ctx_act(ctx);
1785
1786 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1787 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1788 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1789
1790 /* Data is sent (back) to the local TEID established during CreatePDPContext */
1791 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1792 f_wait_icmp4_echo_reply(ctx);
1793
1794 /* UpdatePDPContestRequest changing the local TEID */
1795 var OCT4 new_teid := ctx.teid;
1796 new_teid[3] := new_teid[3] xor4b '11'O;
1797 f_pdp_ctx_update(ctx, new_teid := new_teid);
1798
1799 /* Check if we can send data after updating the PDP context. Answer should be sent to the new TEID */
1800 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1801 f_wait_icmp4_echo_reply(ctx);
1802
1803 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001804 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001805 }
1806
Oliver Smithee6a0882019-03-08 11:05:46 +01001807 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1808 testcase TC_pdp46_act_deact() runs on GT_CT {
1809 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001810 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001811 f_pdp_ctx_act(ctx);
1812 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001813 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001814 }
1815
1816 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1817 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1818 f_init();
1819 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1820 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001821 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001822 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1823 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001824 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001825 /* verify IPCP is at all contained */
1826 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1827 setverdict(fail, "IPCP not found in PCO");
1828 }
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 contains both primary and secondary IPv4 DNS */
1831 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1832 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1833 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1834 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1835 } else {
1836 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1837 }
1838 }
1839 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001840 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001841 }
1842
1843 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1844 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1845 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001846 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001847 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1848 f_pdp_ctx_act(ctx);
1849
1850 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1851 f_wait_rtr_adv(ctx);
1852 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1853
1854 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001855 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001856 }
1857
1858 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1859 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1860 f_init();
1861
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001862 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001863 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1864 f_pdp_ctx_act(ctx);
1865
Harald Welte79737b42019-04-10 10:39:30 +02001866 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001867 /* verify PCO contains both primary and secondary IPv4 DNS */
1868 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1869 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1870 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1871 }
1872
1873 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1874 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1875 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1876 }
1877
1878 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001879 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001880 }
1881
1882 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1883 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1884 f_init();
1885
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001886 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001887 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1888 f_pdp_ctx_act(ctx);
1889
Harald Welte79737b42019-04-10 10:39:30 +02001890 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001891 /* verify PCO contains both primary and secondary IPv6 DNS */
1892 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1893 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1894 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1895 }
1896
1897 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1898 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1899 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1900 }
1901
1902 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001903 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001904 }
1905
1906 /* Test PDP context activation for dynamic IPv4v6 EUA.
1907 Test we can send ICMPv6 ping over GTPU to DNS server. */
1908 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1909 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001910 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001911 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1912 f_pdp_ctx_act(ctx);
1913
1914 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1915
1916 /* Check if we can use valid global src addr, should work */
1917 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1918 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1919 f_wait_icmp4_echo_reply(ctx);
1920
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001921 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001922 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001923 }
1924
1925 /* Assert that packets with wrong ipv4 src addr are dropped by GGSN on APN IPv4v6 */
1926 testcase TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4() runs on GT_CT {
1927 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001928 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 +01001929 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1930 f_pdp_ctx_act(ctx);
1931
1932 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1933 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
Oliver Smithee6a0882019-03-08 11:05:46 +01001934 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1935 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1936 f_wait_gtpu_fail(ctx);
1937
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001938 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001939 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001940 }
1941
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001942 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1943 testcase TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6() runs on GT_CT {
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001944 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001945 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 +01001946 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1947 f_pdp_ctx_act(ctx);
1948
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001949 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1950 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1951 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1952 f_wait_gtpu_fail(ctx);
1953
1954 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001955 f_shutdown_helper();
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001956 }
1957
1958 /* Assert that packets with wrong ipv6 global src addr are dropped by GGSN on APN IPv4v6 */
1959 testcase TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6() runs on GT_CT {
1960 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001961 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 +01001962 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1963 f_pdp_ctx_act(ctx);
1964
1965 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1966 f_wait_rtr_adv(ctx);
1967 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1968
1969 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1970 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1971 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1972 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
Oliver Smithee6a0882019-03-08 11:05:46 +01001973 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001974
Oliver Smithee6a0882019-03-08 11:05:46 +01001975 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001976 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001977 }
1978
1979 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1980 testcase TC_pdp46_clients_interact() runs on GT_CT {
1981 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001982 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1983 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001984 f_pdp_ctx_act(ctxA);
1985 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1986 f_wait_rtr_adv(ctxA);
1987 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1988
1989 f_pdp_ctx_act(ctxB);
1990 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1991 f_wait_rtr_adv(ctxB);
1992 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1993
1994 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1995 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1996 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1997 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1998
1999 /* Validate if clients can interact using ll addr. */
2000 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
2001 f_wait_gtpu_fail(ctxB);
2002
2003 /* Validate if clients can interact using global addr. */
2004 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
2005 f_wait_gtpu_fail(ctxB);
2006
2007 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02002008 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002009 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01002010 }
2011
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002012 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
2013 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002014 const OCT1 cause_accept := '80'O; /* Normal accept cause */
2015 const OCT1 cause_new_pdp_type := '81'O; /* Cause: New PDP type due to network preference */
2016 const OCT1 cause_unknown_pdp := 'DC'O; /* Cause: Unknown PDP address or PDP type */
2017 var CreatePDPContextResponse cpr;
2018
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002019 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002020 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 +01002021 cpr := f_pdp_ctx_act(ctx46, (cause_unknown_pdp, cause_new_pdp_type));
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002022
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002023 if (cpr.cause.causevalue == cause_new_pdp_type) {
2024 /* 3GPP TS 23.060 sec 9.2.1: "If the MS requests PDP type IPv4v6,
2025 * but the operator preferences dictate the use of a single IP
2026 * version only, the PDP type shall be changed to a single address
2027 * PDP type (IPv4 or IPv6) and a reason cause shall be returned to
2028 * the MS indicating that only the assigned PDP type is allowed. In
2029 * this case, the MS shall not request another PDP context for the
2030 * other PDP type during the existence of the PDP context." */
2031 f_pdp_ctx_del(ctx46, '1'B);
2032 } else {
2033 /* 3GPP TS 23.060 sec 9.2.1 NOTE 5: If the MS requests PDP type
2034 * IPv4v6, and the PDP context is rejected due to "unknown PDP
2035 * type", the MS can attempt to establish dual-stack connectivity
2036 * by performing two PDP context request procedures to activate an
2037 * IPv4 PDP context and an IPv6 PDP context, both to the same APN. A
2038 * typical MS first attempts v4v6, and if rejected, then tries v4
2039 * and v6 separetly */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002040 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 +01002041 f_pdp_ctx_act(ctx4, cause_accept); /* Normal accept cause */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002042
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002043 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 +01002044 f_pdp_ctx_act(ctx6, cause_unknown_pdp); /* Cause: Unknown PDP address or PDP type */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002045
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002046 f_pdp_ctx_del(ctx4, '1'B);
2047 }
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002048 f_shutdown_helper();
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002049 }
2050
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002051 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
2052 testcase TC_pdp_act2_recovery() runs on GT_CT {
2053 var Gtp1cUnitdata ud;
2054 var default d;
2055 var boolean ctxA_deleted := false;
2056 var boolean ctxB_created := false;
2057
2058 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002059 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2060 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 +02002061 f_pdp_ctx_act(ctxA);
2062
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06002063 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002064
2065 log("sending 2nd CreatePDP (recovery increased)");
2066 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
2067 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
2068 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
2069 T_default.start;
2070 d := activate(pingpong());
2071 alt {
2072 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
2073 f_handle_create_req(ctxB, ud);
2074 if (not ctxB_created) {
2075 ctxB_created := true;
2076 setverdict(pass);
2077 } else {
2078 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
2079 }
2080
2081 if (not ctxA_deleted) {
2082 repeat;
2083 }
2084 }
2085 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
2086 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
2087 setverdict(pass);
2088 } else {
2089 setverdict(fail);
2090 }
2091
2092 if (not ctxA_deleted) {
2093 ctxA_deleted := true;
2094 setverdict(pass);
2095 } else {
2096 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
2097 }
2098
2099 if (not ctxB_created) {
2100 repeat;
2101 }
2102 }
2103 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
2104 setverdict(fail, "GGSN dropping still valid pdp ctx");
2105 }
2106 }
2107 deactivate(d);
2108 T_default.stop;
2109
2110 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002111 f_shutdown_helper();
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002112 }
2113
2114
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +01002115 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent responses (T3-RESPONSE * N3-REQUESTS):
2116 * 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 +02002117 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
2118 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002119 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 +02002120 f_pdp_ctx_act(ctx);
2121 f_pdp_ctx_del(ctx, '1'B);
2122 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +01002123 f_sleep(int2float(mp_t3_response));
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002124 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
2125 duplicate. If it was not a duplicate, osmo-ggsn would answer
2126 with a failure since that PDP ctx was already deleted. */
Pau Espin Pedrold6b51332022-05-19 17:47:11 +02002127 if (g_c_seq_nr == 0) {
2128 g_c_seq_nr := 65535;
2129 } else {
2130 g_c_seq_nr := g_c_seq_nr - 1;
2131 }
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01002132 f_pdp_ctx_del(ctx, '1'B, expect_diameter := false);
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002133
2134 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
2135 var OCT1 cause_nonexistent := 'C0'O;
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01002136 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent, expect_diameter := false);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002137 f_shutdown_helper();
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002138 }
2139
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002140 /* Activate PDP context + trigger Recovery procedure through EchoResp */
2141 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
2142 var Gtp1cUnitdata ud;
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002143 g_use_echo_intval := 5;
2144 timer T_echo;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002145 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002146 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 +02002147 f_pdp_ctx_act(ctx);
2148
2149 /* Wait to receive echo request and send initial Restart counter */
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002150 T_echo.start(int2float(g_use_echo_intval) + 1.0);
2151 alt {
2152 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002153 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
2154 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002155 }
2156 [] T_echo.timeout {
2157 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2158 "Timeout waiting for ping");
2159 }
2160 }
2161 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002162
2163 /* Wait to receive second echo request and send incremented Restart
2164 counter. This will fake a restarted SGSN, and pdp ctx allocated
2165 should be released by GGSN */
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06002166 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002167 T_echo.start(int2float(g_use_echo_intval) + 1.0);
2168 alt {
2169 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002170 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
2171 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002172 }
2173 [] T_echo.timeout {
2174 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2175 "Timeout waiting for ping");
2176 }
2177 }
2178 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002179 f_pdp_ctx_exp_del_req(ctx, omit, true);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002180 f_shutdown_helper();
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002181 }
2182
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002183 /* Test creation, user plane and deletion of big amount (1000) of concurrent PDP context */
2184 testcase TC_lots_of_concurrent_pdp_ctx() runs on GT_CT {
2185 var Gtp1cUnitdata udc;
2186 var Gtp1uUnitdata udu;
2187 const integer num_ctx := 1000;
2188 var PdpContext ctx[num_ctx];
2189 timer T_next := 0.01;
2190 var integer next_req_ctx := 0;
2191 var integer rx_resp_ctx := 0;
2192 var integer rx_pong := 0;
2193 var OCT4 dns1_addr;
2194 var OCT4 saddr;
2195 var integer teic;
2196 var integer idx;
2197
2198 f_init();
2199
2200 for (var integer i := 0; i < num_ctx; i := i + 1) {
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002201 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 +01002202 ctx[i].teic := int2oct(i+1, 4); /* +1: skip TEIC=0 */
2203 ctx[i].teid := int2oct(i+1, 4); /* +1: skip TEID=0 */
2204 ctx[i].pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2205 }
2206
2207 T_default.start(60.0);
2208
2209 T_next.start;
2210 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002211 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002212 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, INITIAL_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002213 [] pingpong();
2214 [] T_next.timeout {
2215 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx[next_req_ctx].imsi, g_restart_ctr,
2216 ctx[next_req_ctx].teid, ctx[next_req_ctx].teic, ctx[next_req_ctx].nsapi,
2217 ctx[next_req_ctx].eua, ctx[next_req_ctx].apn, g_sgsn_ip_c, g_sgsn_ip_u,
2218 ctx[next_req_ctx].msisdn, ctx[next_req_ctx].pco_req, ctx[next_req_ctx].ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002219 ctx[next_req_ctx].uli, ctx[next_req_ctx].charging_char, ctx[next_req_ctx].imeisv,
2220 ctx[next_req_ctx].ms_tz));
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002221 next_req_ctx := next_req_ctx + 1;
2222 if (next_req_ctx < num_ctx) {
2223 T_next.start;
2224 }
2225 repeat;
2226 }
2227 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2228 teic := oct2int(udc.gtpc.teid);
2229 if (not match(teic, (1 .. num_ctx))) {
2230 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2231 "Rx Unexpected TEIC");
2232 }
2233 idx := teic - 1;
2234 f_handle_create_req(ctx[idx], udc);
2235 rx_resp_ctx := rx_resp_ctx + 1;
2236
2237 dns1_addr := f_PCO_extract_proto(ctx[idx].pco_neg, '000d'O);
2238 saddr := ctx[idx].eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2239 f_send_gtpu(ctx[idx], f_gen_icmpv4_echo(saddr, dns1_addr));
2240 repeat;
2241 }
2242 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value udu {
2243 var octetstring gpdu := udu.gtpu.gtpu_IEs.g_PDU_IEs.data;
2244 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
2245 if (ip4.header.ver != 4) {
2246 repeat;
2247 }
2248 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
2249 if (not match(icmp4, (tr_ICMPv4_ERP, tr_ICMPv4_DU))) {
2250 repeat;
2251 }
2252 rx_pong := rx_pong + 1;
2253 if (rx_pong < num_ctx) {
2254 repeat;
2255 }
2256 setverdict(pass);
2257 }
2258 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2259 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2260 }
2261
2262 /* Let's close them now: */
2263 next_req_ctx := 0;
2264 rx_resp_ctx := 0;
2265 T_next.start;
2266 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002267 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002268 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002269 [] pingpong();
2270 [] T_next.timeout {
2271 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));
2272 next_req_ctx := next_req_ctx + 1;
2273 if (next_req_ctx < num_ctx) {
2274 T_next.start;
2275 }
2276 repeat;
2277 }
2278 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2279 teic := oct2int(udc.gtpc.teid);
2280 if (not match(teic, (1 .. num_ctx))) {
2281 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2282 "Rx Unexpected TEIC");
2283 }
2284 rx_resp_ctx := rx_resp_ctx + 1;
2285 if (rx_resp_ctx < num_ctx) {
2286 repeat;
2287 }
2288 setverdict(pass);
2289 }
2290 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2291 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2292 }
2293 T_next.stop;
2294
2295 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002296 f_shutdown_helper();
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002297 }
2298
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002299 /* Test callocation of PDP contexts until reaching addr pool exhaustion */
2300 type record of OCT4 TEIClist;
2301 testcase TC_addr_pool_exhaustion() runs on GT_CT {
2302 var Gtp1cUnitdata udc;
2303 var Gtp1uUnitdata udu;
2304 var PdpContext ctx;
2305 timer T_next := 0.005;
2306 var integer next_req_ctx := 0;
2307 var integer rx_resp_ctx := 0;
2308 var integer num_ctx;
2309 var boolean cont_req := true;
2310 var CreatePDPContextResponse cpr;
2311 var TEIClist teic_list := {};
2312 var integer teic;
2313
2314 f_init();
2315
2316 T_default.start(120.0);
2317
2318 T_next.start;
2319 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002320 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002321 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, INITIAL_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002322 [] pingpong();
2323 [] T_next.timeout {
2324 if (cont_req) {
2325 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 +02002326 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 +01002327 ctx.nsapi := '0001'B;
2328 ctx.teic := int2oct(next_req_ctx+1, 4); /* +1: skip TEIC=0 */
2329 ctx.teid := int2oct(next_req_ctx+1, 4); /* +1: skip TEID=0 */
2330 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx.imsi, g_restart_ctr,
2331 ctx.teid, ctx.teic, ctx.nsapi,
2332 ctx.eua, ctx.apn, g_sgsn_ip_c, g_sgsn_ip_u,
2333 ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002334 ctx.uli, ctx.charging_char, ctx.imeisv,
2335 ctx.ms_tz));
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002336 next_req_ctx := next_req_ctx + 1;
2337 }
2338 T_next.start;
2339 }
2340 repeat;
2341 }
2342 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2343 cpr := udc.gtpc.gtpc_pdu.createPDPContextResponse;
2344
2345 if (cpr.cause.causevalue == '80'O) {
2346 teic_list := teic_list & {cpr.teidControlPlane.teidControlPlane};
2347 } else {
2348 if (cont_req == true) {
2349 num_ctx := rx_resp_ctx;
2350 log("Successfully created ", num_ctx, " PDP contexts before exhausting the pool");
2351 setverdict(pass);
2352 }
2353 cont_req := false;
2354 }
2355 rx_resp_ctx := rx_resp_ctx + 1;
2356 if (not cont_req and next_req_ctx == rx_resp_ctx) {
2357 break;
2358 } else {
2359 repeat;
2360 }
2361 }
2362 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2363 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2364 }
2365
2366 /* Let's close them now: */
2367 next_req_ctx := 0;
2368 rx_resp_ctx := 0;
2369 T_next.start;
2370 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002371 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002372 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002373 [] pingpong();
2374 [] T_next.timeout {
2375 f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, teic_list[next_req_ctx], '0001'B, '1'B));
2376 next_req_ctx := next_req_ctx + 1;
2377 if (next_req_ctx < num_ctx) {
2378 T_next.start;
2379 }
2380 repeat;
2381 }
2382 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2383 teic := oct2int(udc.gtpc.teid);
2384 if (not match(teic, (1 .. num_ctx))) {
2385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2386 "Rx Unexpected TEIC");
2387 }
2388 rx_resp_ctx := rx_resp_ctx + 1;
2389 if (rx_resp_ctx < num_ctx) {
2390 repeat;
2391 }
2392 setverdict(pass);
2393 }
2394 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2395 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2396 }
2397 T_next.stop;
2398
2399 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002400 f_shutdown_helper();
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002401 }
2402
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002403 /* Test charging over Gy interface. */
2404 testcase TC_gy_charging_cc_time() runs on GT_CT {
2405 var default d;
2406
2407 g_gy_validity_time := 3; /* Grant access for 3 seconds, needs to be re-validated afterwards */
2408 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002409 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 +01002410 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2411 f_pdp_ctx_act(ctx);
2412
2413 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2414
2415 /* Send some UL traffic: */
2416 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2417 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2418 f_wait_icmp4_echo_reply(ctx);
2419
2420 T_default.start(10.0);
2421 d := activate(pingpong());
2422
2423 g_gy_validity_time := 2;
2424 /* First update reports octests/pkt on both UL/DL (see icmp ping-pong above) */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002425 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002426 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (3..4), 28, 28);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002427
2428 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002429 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002430 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (2..3), 0, 0);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002431
2432 /* Third update: make sure report contains again octets/pkts for both UL/DL: */
2433 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2434 f_wait_icmp4_echo_reply(ctx);
2435 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2436 f_wait_icmp4_echo_reply(ctx);
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002437 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002438 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (2..3), 56, 56);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002439
2440 /* Let the CCA reach the GGSN */
2441 f_sleep(0.5);
2442 deactivate(d);
2443 T_default.stop;
2444
2445 /* Send some data and validate it is reported in the TERMINATION_REQUEST
2446 * (triggered by PFCP Session Deletion Response): */
2447 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2448 f_wait_icmp4_echo_reply(ctx);
2449
2450 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002451 f_validate_gy_cc_report(g_rx_gy, FINAL, (0..2), 28, 28);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002452
2453
2454 f_shutdown_helper();
2455 }
2456
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002457 /* Test Volume-Quota-Thresold AVP triggers request before Validity-Time */
2458 testcase TC_gy_charging_volume_quota_threshold() runs on GT_CT {
2459 var default d;
2460 timer Tout;
2461 g_gy_volume_threshold := 1000; /* Will make a trigger when we send bigger payload below */
2462 g_gy_validity_time := 8; /* Grant access for 8 seconds, needs to be re-validated afterwards */
2463 f_init();
2464 var float tout_sec := int2float(g_gy_validity_time) / 2.0;
2465 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2466 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2467 f_pdp_ctx_act(ctx);
2468
2469 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2470
2471 T_default.start(40.0);
2472 d := activate(pingpong());
2473
2474 /* Send some UL traffic: */
2475 var octetstring payload := f_rnd_octstring(1200);
2476 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2477 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr, payload));
2478 f_wait_icmp4_echo_reply(ctx);
2479
2480 /* ICMP Req generates one report: */
2481 Tout.start(tout_sec);
2482 alt {
2483 [] as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
2484 [] Tout.timeout {
2485 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2486 "TImeout waiting for Gy UPDATE triggered by Volume-Quota-Threshold");
2487 }
2488 }
Pau Espin Pedrol5fa8f782022-10-03 13:57:54 +02002489 f_validate_gy_cc_report(g_rx_gy, THRESHOLD, (0..6), (1200..1400), 0);
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002490
2491 /* ICMP Resp (echo back) generates one report: */
2492 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol5fa8f782022-10-03 13:57:54 +02002493 f_validate_gy_cc_report(g_rx_gy, THRESHOLD, (0..1), 0, (1200..1400));
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002494
2495 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
2496 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
2497 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (8..9), 0, 0);
2498
2499 /* Let the CCA reach the GGSN */
2500 f_sleep(0.5);
2501 deactivate(d);
2502 T_default.stop;
2503
2504 f_pdp_ctx_del(ctx, '1'B);
2505 f_validate_gy_cc_report(g_rx_gy, FINAL, (0..2), 0, 0);
2506
2507
2508 f_shutdown_helper();
2509 }
2510
Harald Welte94ade362017-08-04 00:36:55 +02002511 control {
Harald Welteed7a1772017-08-09 20:26:20 +02002512 execute(TC_pdp4_act_deact());
2513 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02002514 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02002515 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002516 execute(TC_pdp4_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002517 execute(TC_pdp4_act_deact_gtpu_access_wrong_saddr());
2518 execute(TC_pdp4_act_deact_gtpu_access_ipv6_apn4());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02002519 execute(TC_pdp4_clients_interact_with_txseq());
2520 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02002521 execute(TC_pdp4_act_deact_with_single_dns());
2522 execute(TC_pdp4_act_deact_with_separate_dns());
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01002523 execute(TC_pdp4_act_update_teic());
2524 execute(TC_pdp4_act_update_teid());
Harald Welteed7a1772017-08-09 20:26:20 +02002525
2526 execute(TC_pdp6_act_deact());
2527 execute(TC_pdp6_act_deact_pcodns());
2528 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002529 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002530 execute(TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr());
2531 execute(TC_pdp6_act_deact_gtpu_access_wrong_global_saddr());
2532 execute(TC_pdp6_act_deact_gtpu_access_ipv4_apn6());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01002533 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02002534
Oliver Smithee6a0882019-03-08 11:05:46 +01002535 execute(TC_pdp46_act_deact());
2536 execute(TC_pdp46_act_deact_ipcp());
2537 execute(TC_pdp46_act_deact_icmp6());
2538 execute(TC_pdp46_act_deact_pcodns4());
2539 execute(TC_pdp46_act_deact_pcodns6());
2540 execute(TC_pdp46_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002541 execute(TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4());
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01002542 execute(TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002543 execute(TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6());
Oliver Smithee6a0882019-03-08 11:05:46 +01002544 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002545 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01002546
Harald Weltedca80052017-08-13 20:01:38 +02002547 execute(TC_echo_req_resp());
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01002548 execute(TC_echo_req_resp_gtpu());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002549 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002550 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002551
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01002552 execute(TC_pdp_act_restart_ctr_echo());
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002553
2554 execute(TC_lots_of_concurrent_pdp_ctx());
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002555 /* Keep at the end, crashes older osmo-ggsn versions (OS#5469): */
2556 execute(TC_addr_pool_exhaustion());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002557
2558 /* open5gs specific tests: */
2559 if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
2560 execute(TC_gy_charging_cc_time());
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002561 execute(TC_gy_charging_volume_quota_threshold());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002562 }
Harald Welte94ade362017-08-04 00:36:55 +02002563 }
Harald Welte379d45a2017-08-03 09:55:15 +02002564}