blob: c18e78e36812671ef9c469f5a4b1d37b1a9fd966 [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
14
Harald Welte94ade362017-08-04 00:36:55 +020015 import from General_Types all;
Harald Welte811651e2017-08-05 15:25:06 +020016 import from Osmocom_Types all;
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +010017 import from Misc_Helpers all;
Harald Welte94ade362017-08-04 00:36:55 +020018 import from IPL4asp_PortType all;
19 import from IPL4asp_Types all;
20 import from GTP_CodecPort all;
21 import from GTP_CodecPort_CtrlFunct all;
Harald Weltec69cf4e2018-02-17 20:57:02 +010022 import from GTP_Templates all;
Harald Welte94ade362017-08-04 00:36:55 +020023 import from GTPC_Types all;
24 import from GTPU_Types all;
Harald Welte71a36022017-12-04 18:55:58 +010025 import from IPCP_Types all;
Harald Weltef8298542019-04-10 10:15:28 +020026 import from PAP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020027 import from IP_Types all;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +010028 import from ICMP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020029 import from ICMPv6_Types all;
Harald Welteddeecbb2017-08-18 22:53:30 +020030 import from Native_Functions all;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +020031 import from Osmocom_VTY_Functions all;
32 import from TELNETasp_PortType all;
Harald Welte94ade362017-08-04 00:36:55 +020033
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010034 import from DIAMETER_Types all;
35 import from DIAMETER_Templates all;
36 import from DIAMETER_Emulation all;
37
Harald Welte94ade362017-08-04 00:36:55 +020038 const integer GTP0_PORT := 3386;
39 const integer GTP1C_PORT := 2123;
40 const integer GTP1U_PORT := 2152;
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010041 const integer PCRF_PORT := 3868;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +010042 const integer OCS_PORT := 3869;
Harald Welteddeecbb2017-08-18 22:53:30 +020043
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010044 type enumerated GGSN_Impl {
45 GGSN_IMPL_OSMOCOM,
46 GGSN_IMPL_OPEN5GS
47 };
48
Harald Welteddeecbb2017-08-18 22:53:30 +020049 modulepar {
Stefan Sperlingcb782b92018-04-03 16:03:15 +020050 /* Default IP addresses. May be overridden by GGSN_Tests configuration files. */
51
52 /* The SGSN simulated by TTCN3 will bind to these addresses for GTP control and GTP user planes. */
Harald Welteddeecbb2017-08-18 22:53:30 +020053 charstring m_bind_ip_gtpc := "127.23.42.1";
54 charstring m_bind_ip_gtpu := "127.23.42.1";
55
Stefan Sperlingcb782b92018-04-03 16:03:15 +020056 /* Addresses the GGSN which is being tested is listening on for SGSN connections. */
Harald Welteddeecbb2017-08-18 22:53:30 +020057 charstring m_ggsn_ip_gtpc := "127.0.0.6";
58 charstring m_ggsn_ip_gtpu := "127.0.0.6";
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010059
Stefan Sperlingcb782b92018-04-03 16:03:15 +020060 /*
61 * Our tests expect to see these DNS servers in 'Create PDP context responses' sent by the GGSN.
62 * These addresses must therefore match 'ip[v6] dns' options configured in osmo-ggsn.conf.
63 *
64 * These addresses are not expected to serve actual DNS requests. However, tests may expect to be
65 * able to ping these addresses (currently, IPv4 addresses must respond with an ICMP 'echo reply',
66 * and IPv6 addresses may respond with either ICMPv6 'echo reply' or 'destination unreachable').
67 */
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010068 charstring m_ggsn_ip4_dns1 := "192.168.100.1"
69 charstring m_ggsn_ip4_dns2 := "8.8.8.8"
Pau Espin Pedrol363ba482018-01-29 18:42:00 +010070 charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888"
71 charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844"
Stefan Sperlingcb782b92018-04-03 16:03:15 +020072
73 /*
74 * Additional address ranges are defined in osmo-ggsn.conf from which addresses are assigned
75 * to MS "behind" the simulated SGSN. These addresses appear on tun devices used by osmo-ggsn.
76 * The tests expect to be able to send ping packets between any two simulated MS within the same
77 * address range. This requires IP forwarding to be enabled on the corresponding tun interfaces.
78 */
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010079
80 GGSN_Impl m_ggsn_impl := GGSN_IMPL_OSMOCOM;
Harald Welteddeecbb2017-08-18 22:53:30 +020081 }
Harald Welte94ade362017-08-04 00:36:55 +020082
Harald Welte811651e2017-08-05 15:25:06 +020083 type set PdpContext {
84 hexstring imsi,
85 octetstring msisdn optional,
86 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020087 ProtConfigOptions pco_req optional,
88 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020089 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020090 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020091 BIT4 nsapi,
92 /* TEI (Data) local side */
93 OCT4 teid,
94 /* TEI (Control) local side */
95 OCT4 teic,
96 /* TEI (Data) remote side */
97 OCT4 teid_remote,
98 /* TEI (Control) remote side */
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +010099 OCT4 teic_remote,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100100 OCT1 ratType optional,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200101 UserLocationInformation uli optional,
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200102 OCT2 charging_char optional,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200103 OCT8 imeisv optional,
104 MS_TimeZone ms_tz optional
Harald Welte811651e2017-08-05 15:25:06 +0200105 }
106
Harald Welte94ade362017-08-04 00:36:55 +0200107 type component GT_CT {
108 port GTPC_PT GTPC;
109 port GTPU_PT GTPU;
110
Harald Welte0be142b2017-08-13 13:28:10 +0200111 var boolean g_initialized := false;
112
Harald Welte94ade362017-08-04 00:36:55 +0200113 var OCT1 g_restart_ctr := '01'O;
114 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200115 var OCT4 g_sgsn_ip_c;
116 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +0200117 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200118 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
119 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200120 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200121
122 /* next to-be-sent GTP-C sequence number */
123 var uint16_t g_c_seq_nr;
124 /* next to-be-sent GTP-U sequence number */
125 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200126
127 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200128 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100129 var integer g_use_echo_intval := 0; /* 0 = disabled */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100130
131 /* emulated PCRF, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100132 var DIAMETER_Emulation_CT vc_Gx;
133 port DIAMETER_PT Gx_UNIT;
134 port DIAMETEREM_PROC_PT Gx_PROC;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100135 var DIAMETER_Emulation_CT vc_Gy;
136 port DIAMETER_PT Gy_UNIT;
137 port DIAMETEREM_PROC_PT Gy_PROC;
138 var integer g_gy_validity_time := 0; /* In seconds. 0 => disabled, !0 => grant over CC-Time period */
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200139 }
140
141 private function f_init_vty() runs on GT_CT {
142 map(self:GGSNVTY, system:GGSNVTY);
143 f_vty_set_prompts(GGSNVTY);
144 f_vty_transceive(GGSNVTY, "enable");
145 }
146
147 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
148 f_vty_enter_config(GGSNVTY);
149 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200150
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200151 f_vty_transceive(GGSNVTY, "apn internet");
152 if (enable) {
153 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
154 } else {
155 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
156 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200157 f_vty_transceive(GGSNVTY, "exit");
158
159 f_vty_transceive(GGSNVTY, "apn inet6");
160 if (enable) {
161 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
162 } else {
163 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
164 }
165 f_vty_transceive(GGSNVTY, "exit");
166
167 f_vty_transceive(GGSNVTY, "apn inet46");
168 if (enable) {
169 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
170 } else {
171 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
172 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200173 f_vty_transceive(GGSNVTY, "end");
174 }
175
176 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
177 if (expect_gptu_txseq) {
178 if (gtpu.s_bit != '1'B) {
179 log("GTPU sequence number expected but not present")
180 return false;
181 }
182 } else {
183 if (gtpu.s_bit != '0'B) {
184 log("GTPU sequence number not expected but present")
185 return false;
186 }
187 }
188 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200189 }
190
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100191 private function f_vty_enable_echo_interval(integer intval_sec) runs on GT_CT {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200192 f_vty_enter_config(GGSNVTY);
193 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100194 if (intval_sec > 0) {
195 f_vty_transceive(GGSNVTY, "echo-interval " & int2str(intval_sec));
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200196 } else {
197 f_vty_transceive(GGSNVTY, "no echo-interval");
198 }
199 f_vty_transceive(GGSNVTY, "end");
200 }
201
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100202 private function DiameterForwardUnitdataCallback(PDU_DIAMETER msg)
203 runs on DIAMETER_Emulation_CT return template PDU_DIAMETER {
204 DIAMETER_UNIT.send(msg);
205 return omit;
206 }
207
208 private function f_init_diameter(charstring id) runs on GT_CT {
209 var DIAMETEROps ops := {
210 create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback),
211 unitdata_cb := refers(DiameterForwardUnitdataCallback),
212 raw := true /* handler mode (single component for all IMSI)) */
213 };
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100214 var DIAMETER_conn_parameters pars;
215
216 /* Gx setup: */
217 pars := {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100218 remote_ip := m_ggsn_ip_gtpc,
219 remote_sctp_port := -1,
220 local_ip := m_bind_ip_gtpc,
221 local_sctp_port := PCRF_PORT,
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100222 origin_host := "pcrf.localdomain",
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100223 origin_realm := "localdomain",
Pau Espin Pedrol33b47492022-03-08 17:43:01 +0100224 auth_app_id := omit,
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100225 vendor_app_id := c_DIAMETER_3GPP_Gx_AID
226 };
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100227 vc_Gx := DIAMETER_Emulation_CT.create(id);
228 map(vc_Gx:DIAMETER, system:DIAMETER_CODEC_PT);
229 connect(vc_Gx:DIAMETER_UNIT, self:Gx_UNIT);
230 connect(vc_Gx:DIAMETER_PROC, self:Gx_PROC);
231 vc_Gx.start(DIAMETER_Emulation.main(ops, pars, id));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100232
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100233 /* Gy setup: */
234 pars := {
235 remote_ip := m_ggsn_ip_gtpc,
236 remote_sctp_port := -1,
237 local_ip := m_bind_ip_gtpc,
238 local_sctp_port := OCS_PORT,
239 origin_host := "ocs.localdomain",
240 origin_realm := "localdomain",
241 auth_app_id := c_DIAMETER_CREDIT_CONTROL_AID,
242 vendor_app_id := omit
243 };
244 vc_Gy := DIAMETER_Emulation_CT.create(id);
245 map(vc_Gy:DIAMETER, system:DIAMETER_CODEC_PT);
246 connect(vc_Gy:DIAMETER_UNIT, self:Gy_UNIT);
247 connect(vc_Gy:DIAMETER_PROC, self:Gy_PROC);
248 vc_Gy.start(DIAMETER_Emulation.main(ops, pars, id));
249
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100250 f_diameter_wait_capability(Gx_UNIT);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100251 f_diameter_wait_capability(Gy_UNIT);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100252 /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdong ping-pongs):
253 * RFC6733 sec 5.1
254 * RFC3539 sec 3.4.1 [5]
255 * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49
256 */
257 f_sleep(1.0);
258 }
259
Harald Welte94ade362017-08-04 00:36:55 +0200260 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200261 if (g_initialized == true) {
262 return;
263 }
264 g_initialized := true;
265
Harald Welteddeecbb2017-08-18 22:53:30 +0200266 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
267 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
268
Harald Welte94ade362017-08-04 00:36:55 +0200269 var Result res;
270 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +0200271 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200272 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200273 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200274
275 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +0200276 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200277 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200278
279 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200280 g_c_seq_nr := f_rnd_int(65535);
281 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200282
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100283 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
284 f_init_vty();
285 f_vty_set_gpdu_txseq(use_gtpu_txseq);
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100286 f_vty_enable_echo_interval(g_use_echo_intval);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100287 } else if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
288 f_init_diameter(testcasename());
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100289 }
Harald Welte94ade362017-08-04 00:36:55 +0200290 }
291
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100292 function f_shutdown_helper() runs on GT_CT {
293 /* Sleep N3_REQUESTS * T3_REQUEST seconds, nowadays 5*3=15s.
294 * This ensures all retransmit queues are cleared before jumping
295 * into next tests, hence avoding situation where a test resuses
296 * a seqnum still in the GGSN's resp queue (dup req detector).
297 * See OS#5485 avout decreasing time. We could also add a new
298 * VTY command that calls gtp_clear_queues() */
299 f_sleep(15.0);
300 setverdict(pass);
301 }
302
Harald Welte94ade362017-08-04 00:36:55 +0200303 /* Altstep implementing responses to any incoming echo requests */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100304 private altstep pingpong() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200305 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200306 var Gtp1uUnitdata udu;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100307 [g_use_echo_intval > 0] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200308 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200309 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200310 repeat;
311 };
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100312 [g_use_echo_intval == 0] GTPC.receive(tr_GTPC_PING(?)) {
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100313 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
314 "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200315 };
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100316 [] T_default.timeout {
317 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
318 "pinpong T_default timeout");
319 };
Harald Welte94ade362017-08-04 00:36:55 +0200320 }
321
Harald Welte811651e2017-08-05 15:25:06 +0200322 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200323 const octetstring c_ApnInternet := '08696E7465726E6574'O;
324 const octetstring c_ApnInet6 := '05696E657436'O;
325 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200326
Harald Welte811651e2017-08-05 15:25:06 +0200327 /* return random NSAPI */
328 function f_rnd_nsapi() return BIT4 {
329 return int2bit(f_rnd_int(16), 4);
330 }
331
332 /* return random TEI[DC] */
333 function f_rnd_tei() return OCT4 {
334 return int2oct(f_rnd_int(4294967296), 4);
335 }
336
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200337 /* return random IMEI(SV) */
338 function f_rnd_imeisv() return OCT8 {
339 return hex2oct(f_rnd_hexstring(16, 10));
340 }
341
Harald Welte811651e2017-08-05 15:25:06 +0200342 /* define an (internal) representation of a PDP context */
343 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100344 EndUserAddress eua, OCT1 ratType := '02'O /* GERAN */) := {
Harald Welte811651e2017-08-05 15:25:06 +0200345 imsi := imsi,
346 msisdn := msisdn,
347 nsapi := f_rnd_nsapi(),
348 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200349 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200350 eua := eua,
351 teid := f_rnd_tei(),
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100352 teic := f_rnd_tei(),
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100353 ratType := ratType,
354 uli := {
355 type_gtpc := '98'O,
356 lengthf := 0 /* filled in by encoder */,
357 geographicLocationType := '00'O /* CGI */,
358 geographicLocation := {
359 geographicLocationCGI := ts_GeographicLocationCGI('262'H, '42F'H, '0001'O, '0002'O)
360 }
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200361 },
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200362 charging_char := '0000'O,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200363 imeisv := f_rnd_imeisv(),
364 ms_tz := f_ts_MS_TimeZone('03'O, '01'B)
Harald Welte811651e2017-08-05 15:25:06 +0200365 }
366
367 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200368 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200369 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200370 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200371 }
372
373 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200374 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200375 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200376 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
377 g_d_seq_nr := g_d_seq_nr + 1;
378 } else {
379 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
380 }
Harald Welte811651e2017-08-05 15:25:06 +0200381 }
382
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100383 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 +0200384 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100385
386 if (not match(cpr.cause.causevalue, exp_cause)) {
387 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
388 "CreatePDPContextResp: cause expectancies didn't match");
389 }
390
391 if (cpr.cause.causevalue == '80'O) { /* Accepted */
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200392 /* Check if EUA type corresponds to requested type */
393 if (match(ctx.eua, t_EuaIPv4(?)) and
394 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100395 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
396 "EUAv4 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200397 }
398 if (match(ctx.eua, t_EuaIPv6(?)) and
399 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100400 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
401 "EUAv6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200402 }
403 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
404 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
406 "EUAv4v6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200407 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100408 } else if (cpr.cause.causevalue == '81'O) { /* Cause: New PDP type due to network preference */
409 /* ETSI TS 129 060 7.3.2 Create PDP Context Response. OS#5449 */
410 /* This should only happen if EUA requested type is v4v6: */
411 if (not ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
412 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
413 "Cause not expected when requesting a non v4v6 EUA");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200414 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100415 if (not match(cpr.endUserAddress, (tr_EuaIPv4(?), tr_EuaIPv6(?)))) {
416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
417 "Cause not expected when requesting+receiving EUAv4v6");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200418 }
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200419 } else {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100420 if (ispresent(cpr.endUserAddress)) {
421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
422 "EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
423 }
424 setverdict(pass);
425 return;
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200426 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100427
428 /* Check if PCO response corresponds to request */
429 if (ispresent(ctx.pco_req)) {
430 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
431 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
433 "IPv4 DNS Container requested, but missing");
434 }
435 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
436 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
437 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
438 "IPv6 DNS Container requested, but missing");
439 }
440 }
441 ctx.teid_remote := cpr.teidDataI.teidDataI;
442 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
443 ctx.eua := cpr.endUserAddress;
444 ctx.pco_neg := cpr.protConfigOptions;
445 setverdict(pass);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200446 }
447
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100448 function f_handle_update_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
449 var UpdatePDPContextResponseGGSN upr := ud.gtpc.gtpc_pdu.updatePDPContextResponse.updatePDPContextResponseGGSN;
450 if (exp_cause == '80'O and exp_cause == upr.cause.causevalue) {
451 ctx.teid_remote := upr.teidDataI.teidDataI;
452 ctx.teic_remote := upr.teidControlPlane.teidControlPlane;
453 if (ispresent(upr.protConfigOptions)) {
454 ctx.pco_neg := upr.protConfigOptions;
455 }
456 setverdict(pass);
457 } else if (exp_cause != '80'O and exp_cause == upr.cause.causevalue) {
458 setverdict(pass);
459 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100460 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
461 "UpdatePDPContextResp: cause expectancies didn't match");
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100462 }
463 }
464
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100465 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 +0100466 var PDU_DIAMETER rx_dia;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100467 [] Gx_UNIT.receive(tr_DIA_Gx_CCR(req_type := req_type)) -> value rx_dia {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100468 var template (omit) AVP avp;
469 var octetstring sess_id;
470 var AVP_Unsigned32 req_num;
471
472 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
473 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
474
475 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
476 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
477
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100478 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 +0100479 req_type, req_num));
480 }
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100481 [] Gx_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
483 log2str("Received unexpected DIAMETER ", rx_dia));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100484 }
485 }
486
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100487 private altstep as_DIA_Gy_CCR(DCC_NONE_CC_Request_Type req_type) runs on GT_CT {
488 var PDU_DIAMETER rx_dia;
489 [] Gy_UNIT.receive(tr_DIA_Gy_CCR(req_type := req_type)) -> value rx_dia {
490 var template (value) PDU_DIAMETER tx_dia;
491 var template (omit) AVP avp;
492 var octetstring sess_id;
493 var AVP_Unsigned32 req_num;
494
495 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
496 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
497
498 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
499 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
500 if (g_gy_validity_time > 0) {
501 tx_dia := ts_DIA_Gy_CCA_ValidityTime(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id,
502 req_type, req_num, g_gy_validity_time);
503 } else {
504 tx_dia := ts_DIA_Gy_CCA(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id,
505 req_type, req_num);
506 }
507 Gy_UNIT.send(tx_dia);
508 }
509 [] Gy_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
510 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
511 log2str("Received unexpected DIAMETER Gy", rx_dia));
512 }
513 }
514
Harald Welte811651e2017-08-05 15:25:06 +0200515 /* send a PDP context activation */
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100516 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 +0200517 var Gtp1cUnitdata ud;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100518 var CreatePDPContextResponse cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200519 var default d;
520
521 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200522 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 +0200523 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200524 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200525 ctx.uli, ctx.charging_char, ctx.imeisv, ctx.ms_tz));
Harald Welte94ade362017-08-04 00:36:55 +0200526 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200527 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100528 if (Gx_PROC.checkstate("Connected")) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100529 as_DIA_Gx_CCR(INITIAL_REQUEST);
530 }
531 if (Gy_PROC.checkstate("Connected")) {
532 as_DIA_Gy_CCR(INITIAL_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100533 }
Harald Welte94ade362017-08-04 00:36:55 +0200534 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200535 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200536 f_handle_create_req(ctx, ud, exp_cause);
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100537 cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Harald Welte94ade362017-08-04 00:36:55 +0200538 }
539 }
540 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200541 T_default.stop;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100542 return cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200543 }
544
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200545 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
546 var Gtp1cUnitdata ud;
547 var default d;
548
549 T_default.start;
550 d := activate(pingpong());
551 alt {
552 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
553 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
554 setverdict(pass);
555 } else if (not istemplatekind(expect_cause, "omit") and
556 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
557 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
558 setverdict(pass);
559 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100560 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
561 "DeletePDPContextReq: cause expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200562 }
563
564 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
565 setverdict(pass);
566 } else {
567 setverdict(fail);
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100568 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
569 "DeletePDPContextReq: tearDownIndicator expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200570 }
571 }
572 }
573 deactivate(d);
574 T_default.stop;
575 }
576
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +0100577 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 +0200578 var Gtp1cUnitdata ud;
579 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200580 var OCT4 expect_teid;
581
582 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
583 message with cause value "Non existent" shall be zero. */
584 if (expect_causevalue == 'C0'O) {
585 expect_teid := '00000000'O;
586 } else {
587 expect_teid := ctx.teic;
588 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200589
Harald Welte41575e92017-08-13 13:49:57 +0200590 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 +0200591 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200592 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100593 if (Gx_PROC.checkstate("Connected") and expect_diameter) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100594 as_DIA_Gx_CCR(TERMINATION_REQUEST);
595 }
596 if (Gy_PROC.checkstate("Connected") and expect_diameter) {
597 as_DIA_Gy_CCR(TERMINATION_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100598 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200599 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200600 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
601 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200602 setverdict(pass);
603 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100604 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
605 "DeletePDPContextResp: cause expectancies didn't match");
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200606 }
607 }
608 }
609 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200610 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200611 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100612
613 /* send a Update PdP Context Request, expect Response */
614 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 {
615 var Gtp1cUnitdata ud;
616 var default d;
617
618 if (not istemplatekind(new_teid, "omit")) {
619 ctx.teid := valueof(new_teid);
620 }
621 if (not istemplatekind(new_teic, "omit")) {
622 ctx.teic := valueof(new_teic);
623 }
624
625 log("sending UpdatePDP");
626 f_send_gtpc(ts_GTPC_UpdatePDP(g_peer_c, ctx.teic_remote, g_c_seq_nr, ctx.imsi, g_restart_ctr,
627 ctx.teid, ctx.teic, ctx.nsapi, g_sgsn_ip_c, g_sgsn_ip_u,
628 ctx.pco_req, ctx.ratType, ctx.uli));
629 T_default.start;
630 d := activate(pingpong());
631 alt {
632 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, updatePDPContextResponse, ctx.teic)) -> value ud {
633 f_handle_update_req(ctx, ud, exp_cause);
634 }
635 }
636 deactivate(d);
637 T_default.stop;
638 }
639
Harald Welte811651e2017-08-05 15:25:06 +0200640 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
641 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
642 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
643 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200644
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200645 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100646 template PDU_ICMP ts_ICMPv4_ERQ := {
647 echo := {
648 type_field := 8,
649 code := 0,
650 checksum := '0000'O,
651 identifier := '0345'O,
652 sequence_number := '0001'O,
653 data := ''O
654 }
655 }
656
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200657 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100658 template PDU_ICMP tr_ICMPv4_ERQ := {
659 echo := {
660 type_field := 8,
661 code := 0,
662 checksum := ?,
663 identifier := ?,
664 sequence_number := ?,
665 data := ?
666 }
667 }
668
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200669 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100670 template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
671 echo_reply := {
672 type_field := 0,
673 code := 0,
674 checksum := ?,
675 identifier := ?,
676 sequence_number := ?,
677 data := data
678 }
679 }
680
681 /* template for receiving/matching an ICMPv6 Destination Unreachable */
682 template PDU_ICMP tr_ICMPv4_DU := {
683 destination_unreachable := {
684 type_field := 1,
685 code := ?,
686 checksum := ?,
687 unused := ?,
688 original_ip_msg := ?
689 }
690 }
691
692 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
693 template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
694 header := {
695 ver := 4,
696 hlen := 5,
697 tos := 0,
698 tlen := tlen,
699 id := 35902,
700 res := '0'B,
701 dfrag := '1'B,
702 mfrag := '0'B,
703 foffset := 0,
704 ttl := 64,
705 proto := proto,
706 cksum := 0,
707 srcaddr := srcaddr,
708 dstaddr := dstaddr
709 },
710 ext_headers := omit,
711 payload := payload
712 }
713
Harald Welte231b9412017-08-09 17:16:31 +0200714 /* template to generate a 'Prefix Information' ICMPv6 option */
715 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
716 prefixInformation := {
717 typeField := 3,
718 lengthIndicator := 8,
719 prefixLength := prefix_len,
720 reserved1 := '000000'B,
721 a_Bit := '0'B,
722 l_Bit := '0'B,
723 validLifetime := oct2int('FFFFFFFF'O),
724 preferredLifetime := oct2int('FFFFFFFF'O),
725 reserved2 := '00000000'O,
726 prefix := prefix
727 }
728 }
729
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200730 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100731 template PDU_ICMPv6 ts_ICMPv6_ERQ := {
732 echoRequest := {
733 typeField := 128,
734 code := 0,
735 checksum := '0000'O,
736 identifier := 0,
737 sequenceNr := 0,
738 data := ''O
739 }
740 }
741
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200742 /* template for sending an ICMPv6 router solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200743 template PDU_ICMPv6 ts_ICMPv6_RS := {
744 routerSolicitation := {
745 typeField := 133,
746 code := 0,
747 checksum := '0000'O,
748 reserved := '00000000'O,
749 /* TODO: do we need 'Source link-layer address' ? */
750 options := omit
751 }
752 }
753
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200754 /* template for sending an ICMPv6 router advertisement */
Harald Welte231b9412017-08-09 17:16:31 +0200755 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
756 routerAdvertisement := {
757 typeField := 134,
758 code := 0,
759 checksum := '0000'O,
760 curHopLimit := ?,
761 reserved := '000000'B,
762 o_Bit := '0'B,
763 m_Bit := '0'B,
764 routerLifetime := oct2int('FFFF'O),
765 reachableTime := oct2int('FFFFFFFF'O),
766 retransTimer := oct2int('FFFFFFFF'O),
767 options := {
768 ts_ICMP6_OptPrefix(prefix, prefix_len)
769 }
770 }
771 }
772
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200773 /* template for sending an ICMPv6 neighbor solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200774 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
775 neighborSolicitation := {
776 typeField := 135,
777 code := 0,
778 checksum := '0000'O,
779 reserved := '00000000'O,
780 targetAddress := target_addr,
781 /* TODO: do we need 'Source link-layer address' ? */
782 options := omit
783 }
784 }
785
786 /* derive ICMPv6 link-local address from lower 64bit of link_id */
787 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
788 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
789 prefixInformation := {
790 typeField := 3,
791 lengthIndicator := 4,
792 prefixLength := prefix_len,
793 reserved1 := ?,
794 a_Bit := ?,
795 l_Bit := ?,
796 validLifetime := ?,
797 preferredLifetime := ?,
798 reserved2 := ?,
799 prefix := prefix
800 }
801 }
802
803 /* template for receiving/matching an ICMPv6 router advertisement */
804 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
805 routerAdvertisement := {
806 typeField := 134,
807 code := 0,
808 checksum := ?,
809 curHopLimit := ?,
810 reserved := ?,
811 o_Bit := '0'B,
812 m_Bit := '0'B,
813 routerLifetime := ?,
814 reachableTime := ?,
815 retransTimer := ?,
816 options := {
817 tr_ICMP6_OptPrefix(prefix, prefix_len)
818 }
819 }
820 }
821
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100822 /* template for receiving/matching an ICMPv6 Destination Unreachable */
823 template PDU_ICMPv6 tr_ICMPv6_DU := {
824 destinationUnreachable := {
825 typeField := 1,
826 code := ?,
827 checksum := ?,
828 unused := ?,
829 originalIpMsg := ?
830 }
831 }
832
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200833 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100834 template PDU_ICMPv6 tr_ICMPv6_ERQ := {
835 echoRequest := {
836 typeField := 128,
837 code := 0,
838 checksum := ?,
839 identifier := ?,
840 sequenceNr := ?,
841 data := ?
842 }
843 }
844
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100845 /* template for receiving/matching an ICMPv6 echo reply */
846 template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
847 echoReply := {
848 typeField := 129,
849 code := 0,
850 checksum := ?,
851 identifier := ?,
852 sequenceNr := ?,
853 data := data
854 }
855 }
856
Harald Welte231b9412017-08-09 17:16:31 +0200857 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
858 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
859 header := {
860 ver := 6,
861 trclass := 0,
862 flabel := 0,
863 plen := 0,
864 nexthead := nexthead,
865 hlim := hlim,
866 srcaddr := srcaddr,
867 dstaddr := dstaddr
868 },
869 ext_headers := omit,
870 payload := payload
871 }
872
873 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
874 return 'FE80000000000000'O & substr(link_id, 8, 8);
875 }
876
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100877 function f_ipv6_global(in OCT16 link_id) return OCT16 {
878 return substr(link_id, 0, 8) & '1234123412341234'O;
879 }
880
881 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
882 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
883 var integer i;
884 var octetstring res := substr(addr, 0, prefix);
885 for (i := prefix; i < lengthof(addr); i := i + 1) {
886 var octetstring a := addr[i] xor4b '11'O;
887 res := res & a;
888 }
889 return res;
890 }
891
Harald Welte231b9412017-08-09 17:16:31 +0200892 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
893 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
894 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
895 }
896
897 /* generate and encode ICMPv6 router solicitation */
898 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
899 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
900 var OCT16 saddr := f_ipv6_link_local(link_id);
901
902 var octetstring tmp;
903 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
904 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
905
906 return f_IPv6_enc(ip6);
907 }
908
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100909 /* Get link-id from PDP Context EUA */
910 function f_ctx_get_ipv6_interface_id(in PdpContext ctx) return OCT16 {
911 var OCT16 interface_id;
912 if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
913 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
914 } else if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv6)) {
915 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
916 } else {
917 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected request to submit icmpv6 rs in IPv4 PDP context");
918 }
919 return interface_id;
920 }
921
Harald Welte231b9412017-08-09 17:16:31 +0200922 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
923 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100924 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200925 return f_gen_icmpv6_router_solicitation(interface_id);
926 }
927
928 /* generate and encode ICMPv6 neighbor solicitation */
929 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
930 var octetstring tmp;
931 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
932 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
933 return f_IPv6_enc(ip6);
934 }
935
936 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
937 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100938 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200939 var OCT16 link_local := f_ipv6_link_local(interface_id);
940 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
941
942 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
943 }
944
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100945 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
946 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring {
947 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ));
948 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
949 var octetstring data := f_IPv4_enc(ip4);
950 var OCT2 cksum := f_IPv4_checksum(data);
951 data[10] := cksum[0];
952 data[11] := cksum[1];
953 return data;
954 }
955
956 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
957 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
958 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
959 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
960 var octetstring data := f_IPv6_enc(ip6);
961 return data;
962 }
963
964 /* Wait for ICMPv4 from GTP */
965 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +0200966 var Gtp1uUnitdata ud;
967 T_default.start;
968 alt {
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100969 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ctx.teid)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200970 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200971 setverdict(fail);
972 stop;
973 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100974 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
975 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
976 if (ip4.header.ver != 4) {
977 repeat;
978 }
979 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
980 if (not match(icmp4, expected)) {
981 repeat;
982 }
983 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100984 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
985 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
986 "Received wrong local TEID");
987 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100988 [] GTPU.receive { setverdict(fail); }
989 [] T_default.timeout { setverdict(fail); }
990 }
991 T_default.stop;
992 }
993
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100994 /* Wait for ICMPv4 echo request from GTP */
995 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
996 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
997 }
998
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100999 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
1000 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
1001 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
1002 }
1003
1004 /* Wait for ICMPv6 from GTP */
1005 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
1006 var Gtp1uUnitdata ud;
1007 T_default.start;
1008 alt {
Harald Welte231b9412017-08-09 17:16:31 +02001009 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +02001010 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001011 setverdict(fail);
1012 stop;
1013 }
Harald Welte231b9412017-08-09 17:16:31 +02001014 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1015 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001016 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +02001017 repeat;
1018 }
1019 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001020 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +02001021 repeat;
1022 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001023 /* We are waiting for RA, update ctx */
1024 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
1025 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
1026 log("RA with /64 prefix ", ctx.ip6_prefix);
1027 }
Harald Welte231b9412017-08-09 17:16:31 +02001028 }
1029 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
1030 [] GTPU.receive { setverdict(fail); }
1031 [] T_default.timeout { setverdict(fail); }
1032 }
1033 T_default.stop;
1034 }
1035
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001036 /* wait for GGSN to send us an ICMPv6 router advertisement */
1037 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
1038 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
1039 }
1040
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001041 /* Wait for ICMPv6 echo request from GTP */
1042 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
1043 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
1044 }
1045
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001046 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
1047 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
1048 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
1049 }
1050
Oliver Smithee6a0882019-03-08 11:05:46 +01001051 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
1052 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
1053 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1054 return f_gen_icmpv6_router_solicitation(interface_id);
1055 }
1056
1057 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
1058 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
1059 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1060 var OCT16 link_local := f_ipv6_link_local(interface_id);
1061 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
1062
1063 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
1064 }
1065
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001066 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
1067 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
1068 T_default.start;
1069 alt {
1070 [] GTPU.receive { setverdict(fail); }
1071 [] T_default.timeout { }
1072 }
1073 T_default.stop;
1074 }
1075
Harald Welte79737b42019-04-10 10:39:30 +02001076 /* list of protocols where we don't accept duplicates */
1077 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
1078 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
1079 var integer i;
1080 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
1081 if (id == protocol_ids_nodupes[i]) {
1082 return false;
1083 }
1084 }
1085 return true;
1086 }
1087
1088 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
1089 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
1090 var OCT2List protocol_ids := {};
1091 var integer i, j;
1092 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
1093 var OCT2 id := pco.protocols[i].protocolID;
1094 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
1095 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
1096 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
1097 }
1098 }
1099 protocol_ids := protocol_ids & { id };
1100 }
1101 }
1102
Harald Welte0ef285b2017-08-13 20:06:01 +02001103 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +02001104 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +02001105 f_init();
Harald Welte231b9412017-08-09 17:16:31 +02001106
Harald Welteed097432017-08-13 13:28:49 +02001107 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welte811651e2017-08-05 15:25:06 +02001108 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +02001109 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001110 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001111 }
1112
Harald Welte0ef285b2017-08-13 20:06:01 +02001113 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001114 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
1115 f_init();
1116
Harald Welteed097432017-08-13 13:28:49 +02001117 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001118 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1119 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001120
Harald Welte79737b42019-04-10 10:39:30 +02001121 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001122 /* verify PCO contains both primary and secondary DNS */
1123 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1124 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1125 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1126 }
1127
1128 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1129 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1130 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1131 }
1132
Harald Welteed7a1772017-08-09 20:26:20 +02001133 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001134 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001135 }
1136
Harald Welte0ef285b2017-08-13 20:06:01 +02001137 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +02001138 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
1139 f_init();
1140
Harald Welteed097432017-08-13 13:28:49 +02001141 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001142 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1143 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001144
Harald Welte79737b42019-04-10 10:39:30 +02001145 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +02001146 //f_send_gtpu(ctx, c_router_solicit);
1147 //f_send_gtpu(ctx, c_neigh_solicit);
1148
1149 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1150 f_wait_rtr_adv(ctx);
1151 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1152
Harald Welte811651e2017-08-05 15:25:06 +02001153 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001154 f_shutdown_helper();
Harald Welte94ade362017-08-04 00:36:55 +02001155 }
1156
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001157 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
1158 Test we can send ICMPv6 ping over GTPU to DNS server. */
1159 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
1160 f_init();
1161 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1162 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1163 f_pdp_ctx_act(ctx);
1164
1165 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1166 f_wait_rtr_adv(ctx);
1167 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1168
1169 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1170
1171 /* Check if we can use valid link-local src addr. */
1172 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1173 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
Pau Espin Pedrolb63d85f2022-02-07 16:11:47 +01001174 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
1175 f_wait_icmp6_echo_reply(ctx);
1176 } else {
1177 f_wait_gtpu_fail(ctx);
1178 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001179
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001180 /* Check if we can use valid global src addr, should work */
1181 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1182 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
1183 f_wait_icmp6_echo_reply(ctx);
1184
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001185 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001186 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001187 }
1188
1189 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1190 testcase TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr() runs on GT_CT {
1191 f_init();
1192 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1193 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1194 f_pdp_ctx_act(ctx);
1195
1196 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1197 f_wait_rtr_adv(ctx);
1198 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1199
1200 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1201 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1202 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1203 f_wait_gtpu_fail(ctx);
1204
1205 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001206 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001207 }
1208
1209 /* Assert that packets with wrong global src addr are dropped by GGSN */
1210 testcase TC_pdp6_act_deact_gtpu_access_wrong_global_saddr() runs on GT_CT {
1211 f_init();
1212 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1213 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1214 f_pdp_ctx_act(ctx);
1215
1216 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1217 f_wait_rtr_adv(ctx);
1218 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1219
1220 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1221 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001222 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1223 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
1224 f_wait_gtpu_fail(ctx);
1225
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001226 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001227 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001228 }
1229
1230 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped */
1231 testcase TC_pdp6_act_deact_gtpu_access_ipv4_apn6() runs on GT_CT {
1232 f_init();
1233 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1234 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1235 f_pdp_ctx_act(ctx);
1236
1237 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1238 f_wait_rtr_adv(ctx);
1239 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1240
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001241 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
1242 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
1243 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
1244 f_wait_gtpu_fail(ctx);
1245
1246 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001247 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001248 }
1249
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001250 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1251 testcase TC_pdp6_clients_interact() runs on GT_CT {
1252 f_init();
1253 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1254 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1255 f_pdp_ctx_act(ctxA);
1256 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
1257 f_wait_rtr_adv(ctxA);
1258 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
1259
1260 f_pdp_ctx_act(ctxB);
1261 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
1262 f_wait_rtr_adv(ctxB);
1263 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
1264
1265 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1266 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1267 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1268 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1269
1270 /* Validate if clients can interact using ll addr. */
1271 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1272 f_wait_gtpu_fail(ctxB);
1273
1274 /* Validate if clients can interact using global addr. */
1275 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1276 f_wait_gtpu_fail(ctxB);
1277
1278 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001279 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001280 f_shutdown_helper();
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001281 }
1282
Harald Welte0ef285b2017-08-13 20:06:01 +02001283 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +02001284 testcase TC_pdp4_act_deact() runs on GT_CT {
1285 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001286 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001287 f_pdp_ctx_act(ctx);
1288 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001289 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001290 }
1291
Harald Welte0ef285b2017-08-13 20:06:01 +02001292 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +02001293 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
1294 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001295 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1296 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +02001297 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001298 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +02001299 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001300 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +01001301 /* verify IPCP is at all contained */
1302 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1303 setverdict(fail, "IPCP not found in PCO");
1304 }
1305 /* verify IPCP contains both primary and secondary DNS */
1306 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001307 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1308 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1309 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1310 } else {
1311 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1312 }
Harald Welte71a36022017-12-04 18:55:58 +01001313 }
Harald Welteed7a1772017-08-09 20:26:20 +02001314 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001315 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001316 }
1317
Harald Weltef8298542019-04-10 10:15:28 +02001318 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
1319 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
1320 f_init();
1321 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1322 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1323 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1324 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1325 f_pdp_ctx_act(ctx);
1326 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1327 /* verify IPCP is at all contained */
1328 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1329 setverdict(fail, "IPCP not found in PCO");
1330 }
1331 /* verify IPCP contains both primary and secondary DNS */
1332 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1333 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1334 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1335 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1336 } else {
1337 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1338 }
1339 }
1340 /* verify that PAP is contained */
1341 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1342 setverdict(fail, "PAP not found in PCO");
1343 }
1344 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1345 if (not match(pap, tr_PAP_AuthAck)) {
1346 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1347 }
1348 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001349 f_shutdown_helper();
Harald Weltef8298542019-04-10 10:15:28 +02001350 }
1351
Harald Welte0ef285b2017-08-13 20:06:01 +02001352 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001353 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1354 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001355 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001356 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001357 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001358
Harald Welte79737b42019-04-10 10:39:30 +02001359 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001360 /* verify PCO contains both primary and secondary DNS */
1361 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1362 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1363 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1364 }
1365
1366 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1367 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1368 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1369 }
1370
Harald Welteed7a1772017-08-09 20:26:20 +02001371 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001372 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001373 }
1374
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001375 /* Test PDP context activation for dynamic IPv4 EUA.
1376 Test we can send ICMPv6 ping over GTPU to DNS server. */
1377 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1378 f_init();
1379 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1380 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1381 f_pdp_ctx_act(ctx);
1382
Harald Welte79737b42019-04-10 10:39:30 +02001383 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001384 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1385
1386 /* Check if we can use valid global src addr, should work */
1387 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1388 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1389 f_wait_icmp4_echo_reply(ctx);
1390
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001391 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001392 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001393 }
1394
1395 /* Assert that packets with wrong global src addr are dropped by GGSN */
1396 testcase TC_pdp4_act_deact_gtpu_access_wrong_saddr() runs on GT_CT {
1397 f_init();
1398 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1399 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1400 f_pdp_ctx_act(ctx);
1401
1402 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1403 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1404 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001405 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1406 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1407 f_wait_gtpu_fail(ctx);
1408
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001409 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001410 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001411 }
1412
1413 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1414 testcase TC_pdp4_act_deact_gtpu_access_ipv6_apn4() runs on GT_CT {
1415 f_init();
1416 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1417 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1418 f_pdp_ctx_act(ctx);
1419
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001420 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1421 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1422 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1423 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001424
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001425 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001426 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001427 }
1428
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001429 /* Helper function for tests below. */
1430 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001431 f_init();
1432 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1433 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1434 f_pdp_ctx_act(ctxA);
1435 f_pdp_ctx_act(ctxB);
1436 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1437 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1438 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1439 f_wait_icmp4_echo_request(ctxB);
1440
1441 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001442 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001443 }
1444
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001445 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1446 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001447 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001448 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001449 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001450 }
1451
1452 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1453 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001454 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001455 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001456 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001457 }
1458
Harald Weltedca80052017-08-13 20:01:38 +02001459 testcase TC_echo_req_resp() runs on GT_CT {
1460 f_init();
1461 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1462 T_default.start;
1463 alt {
1464 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1465 [] GTPC.receive { repeat; };
1466 [] T_default.timeout { setverdict(fail); }
1467 }
1468 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001469 f_shutdown_helper();
Harald Weltedca80052017-08-13 20:01:38 +02001470 }
1471
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001472 testcase TC_echo_req_resp_gtpu() runs on GT_CT {
1473 f_init();
1474 GTPU.send(ts_GTPU_PING(g_peer_u, g_d_seq_nr));
1475 T_default.start;
1476 alt {
1477 [] GTPU.receive(tr_GTPU_PONG(g_peer_u)) { setverdict(pass); };
1478 [] GTPU.receive { repeat; };
1479 [] T_default.timeout { setverdict(fail); }
1480 }
1481 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001482 f_shutdown_helper();
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001483 }
1484
Philipp Maier33e52612018-05-30 17:22:02 +02001485 /* Test if the parser can cope with PCO that only contain either a
1486 * single primary DNS or a secondary DNS. */
1487 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1488
1489 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1490 * the test is executed.
1491 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1492
1493 f_init();
1494 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1495 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1496 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1497 var octetstring pco_neg_dns;
1498 var octetstring pco_neg_dns_expected;
1499
1500 /* PCO with primary DNS only */
1501 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1502 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001503 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001504 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1505 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1506 /* Note: The prepended hex bytes encode the following information:
1507 * 0x02 = Configuration ACK
1508 * 0x00 = Identifier
1509 * 0x000a = Length
1510 * 0x81 = Type (Primary DNS Server Address)
1511 * 0x06 = Length
1512 * (4 byte IP-Address appended) */
1513 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1514 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1515 }
1516 f_pdp_ctx_del(ctx, '1'B);
1517
1518 /* PCO with secondary DNS only */
Harald Welte7ef6d102021-04-01 21:24:35 +02001519 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001520 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1521 f_pdp_ctx_act(ctx);
1522 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1523 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1524 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1525 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1526 }
1527 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001528 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001529 }
1530
1531 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1532 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1533 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1534 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1535
1536 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1537 * the test is executed.
1538 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1539
1540 f_init();
1541 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1542 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1543 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1544 var octetstring pco_neg_dns;
1545 var octetstring pco_neg_dns_expected;
1546
1547 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1548 f_pdp_ctx_act(ctx);
1549
1550 /* Check if primary DNS is contained */
1551 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1552 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1553 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1554 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1555 }
Philipp Maier33e52612018-05-30 17:22:02 +02001556
1557 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001558 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1559 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001560 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1561 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1562 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1563 }
1564 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001565 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001566 }
1567
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001568 /* Validate that SUT updates remote TEIC when requested through UpdatePDPContextRequest */
1569 testcase TC_pdp4_act_update_teic() runs on GT_CT {
1570 f_init();
1571 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1572 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1573 f_pdp_ctx_act(ctx);
1574
1575 /* UpdatePDPContestRequest changing the local TEIC */
1576 var OCT4 new_teic := ctx.teic;
1577 new_teic[3] := new_teic[3] xor4b '11'O;
1578 f_pdp_ctx_update(ctx, new_teic := new_teic);
1579
1580 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001581 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001582 }
1583
1584 /* Validate that SUT updates remote TEID when requested through UpdatePDPContextRequest */
1585 testcase TC_pdp4_act_update_teid() runs on GT_CT {
1586 f_init();
1587 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1588 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1589 f_pdp_ctx_act(ctx);
1590
1591 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1592 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1593 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1594
1595 /* Data is sent (back) to the local TEID established during CreatePDPContext */
1596 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1597 f_wait_icmp4_echo_reply(ctx);
1598
1599 /* UpdatePDPContestRequest changing the local TEID */
1600 var OCT4 new_teid := ctx.teid;
1601 new_teid[3] := new_teid[3] xor4b '11'O;
1602 f_pdp_ctx_update(ctx, new_teid := new_teid);
1603
1604 /* Check if we can send data after updating the PDP context. Answer should be sent to the new TEID */
1605 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1606 f_wait_icmp4_echo_reply(ctx);
1607
1608 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001609 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001610 }
1611
Oliver Smithee6a0882019-03-08 11:05:46 +01001612 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1613 testcase TC_pdp46_act_deact() runs on GT_CT {
1614 f_init();
1615 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1616 f_pdp_ctx_act(ctx);
1617 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001618 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001619 }
1620
1621 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1622 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1623 f_init();
1624 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1625 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1626 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1627 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1628 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001629 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001630 /* verify IPCP is at all contained */
1631 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1632 setverdict(fail, "IPCP not found in PCO");
1633 }
Harald Welte79737b42019-04-10 10:39:30 +02001634 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001635 /* verify IPCP contains both primary and secondary IPv4 DNS */
1636 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1637 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1638 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1639 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1640 } else {
1641 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1642 }
1643 }
1644 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001645 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001646 }
1647
1648 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1649 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1650 f_init();
1651 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1652 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1653 f_pdp_ctx_act(ctx);
1654
1655 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1656 f_wait_rtr_adv(ctx);
1657 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1658
1659 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001660 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001661 }
1662
1663 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1664 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1665 f_init();
1666
1667 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1668 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1669 f_pdp_ctx_act(ctx);
1670
Harald Welte79737b42019-04-10 10:39:30 +02001671 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001672 /* verify PCO contains both primary and secondary IPv4 DNS */
1673 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1674 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1675 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1676 }
1677
1678 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1679 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1680 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1681 }
1682
1683 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001684 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001685 }
1686
1687 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1688 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1689 f_init();
1690
1691 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1692 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1693 f_pdp_ctx_act(ctx);
1694
Harald Welte79737b42019-04-10 10:39:30 +02001695 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001696 /* verify PCO contains both primary and secondary IPv6 DNS */
1697 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1698 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1699 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1700 }
1701
1702 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1703 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1704 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1705 }
1706
1707 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001708 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001709 }
1710
1711 /* Test PDP context activation for dynamic IPv4v6 EUA.
1712 Test we can send ICMPv6 ping over GTPU to DNS server. */
1713 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1714 f_init();
1715 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1716 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1717 f_pdp_ctx_act(ctx);
1718
1719 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1720
1721 /* Check if we can use valid global src addr, should work */
1722 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1723 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1724 f_wait_icmp4_echo_reply(ctx);
1725
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001726 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001727 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001728 }
1729
1730 /* Assert that packets with wrong ipv4 src addr are dropped by GGSN on APN IPv4v6 */
1731 testcase TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4() runs on GT_CT {
1732 f_init();
1733 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1734 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1735 f_pdp_ctx_act(ctx);
1736
1737 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1738 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
Oliver Smithee6a0882019-03-08 11:05:46 +01001739 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1740 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1741 f_wait_gtpu_fail(ctx);
1742
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001743 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001744 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001745 }
1746
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001747 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1748 testcase TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6() runs on GT_CT {
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001749 f_init();
1750 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1751 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1752 f_pdp_ctx_act(ctx);
1753
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001754 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1755 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1756 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1757 f_wait_gtpu_fail(ctx);
1758
1759 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001760 f_shutdown_helper();
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001761 }
1762
1763 /* Assert that packets with wrong ipv6 global src addr are dropped by GGSN on APN IPv4v6 */
1764 testcase TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6() runs on GT_CT {
1765 f_init();
1766 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1767 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1768 f_pdp_ctx_act(ctx);
1769
1770 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1771 f_wait_rtr_adv(ctx);
1772 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1773
1774 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1775 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1776 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1777 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
Oliver Smithee6a0882019-03-08 11:05:46 +01001778 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001779
Oliver Smithee6a0882019-03-08 11:05:46 +01001780 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001781 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001782 }
1783
1784 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1785 testcase TC_pdp46_clients_interact() runs on GT_CT {
1786 f_init();
1787 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1788 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1789 f_pdp_ctx_act(ctxA);
1790 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1791 f_wait_rtr_adv(ctxA);
1792 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1793
1794 f_pdp_ctx_act(ctxB);
1795 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1796 f_wait_rtr_adv(ctxB);
1797 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1798
1799 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1800 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1801 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1802 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1803
1804 /* Validate if clients can interact using ll addr. */
1805 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1806 f_wait_gtpu_fail(ctxB);
1807
1808 /* Validate if clients can interact using global addr. */
1809 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1810 f_wait_gtpu_fail(ctxB);
1811
1812 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001813 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001814 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001815 }
1816
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001817 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
1818 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001819 const OCT1 cause_accept := '80'O; /* Normal accept cause */
1820 const OCT1 cause_new_pdp_type := '81'O; /* Cause: New PDP type due to network preference */
1821 const OCT1 cause_unknown_pdp := 'DC'O; /* Cause: Unknown PDP address or PDP type */
1822 var CreatePDPContextResponse cpr;
1823
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001824 f_init();
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001825 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001826 cpr := f_pdp_ctx_act(ctx46, (cause_unknown_pdp, cause_new_pdp_type));
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001827
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001828 if (cpr.cause.causevalue == cause_new_pdp_type) {
1829 /* 3GPP TS 23.060 sec 9.2.1: "If the MS requests PDP type IPv4v6,
1830 * but the operator preferences dictate the use of a single IP
1831 * version only, the PDP type shall be changed to a single address
1832 * PDP type (IPv4 or IPv6) and a reason cause shall be returned to
1833 * the MS indicating that only the assigned PDP type is allowed. In
1834 * this case, the MS shall not request another PDP context for the
1835 * other PDP type during the existence of the PDP context." */
1836 f_pdp_ctx_del(ctx46, '1'B);
1837 } else {
1838 /* 3GPP TS 23.060 sec 9.2.1 NOTE 5: If the MS requests PDP type
1839 * IPv4v6, and the PDP context is rejected due to "unknown PDP
1840 * type", the MS can attempt to establish dual-stack connectivity
1841 * by performing two PDP context request procedures to activate an
1842 * IPv4 PDP context and an IPv6 PDP context, both to the same APN. A
1843 * typical MS first attempts v4v6, and if rejected, then tries v4
1844 * and v6 separetly */
1845 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1846 f_pdp_ctx_act(ctx4, cause_accept); /* Normal accept cause */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001847
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001848 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv6Dyn)));
1849 f_pdp_ctx_act(ctx6, cause_unknown_pdp); /* Cause: Unknown PDP address or PDP type */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001850
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001851 f_pdp_ctx_del(ctx4, '1'B);
1852 }
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001853 f_shutdown_helper();
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001854 }
1855
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001856 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
1857 testcase TC_pdp_act2_recovery() runs on GT_CT {
1858 var Gtp1cUnitdata ud;
1859 var default d;
1860 var boolean ctxA_deleted := false;
1861 var boolean ctxB_created := false;
1862
1863 f_init();
1864 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1865 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1866 f_pdp_ctx_act(ctxA);
1867
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06001868 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001869
1870 log("sending 2nd CreatePDP (recovery increased)");
1871 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
1872 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
1873 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
1874 T_default.start;
1875 d := activate(pingpong());
1876 alt {
1877 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
1878 f_handle_create_req(ctxB, ud);
1879 if (not ctxB_created) {
1880 ctxB_created := true;
1881 setverdict(pass);
1882 } else {
1883 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
1884 }
1885
1886 if (not ctxA_deleted) {
1887 repeat;
1888 }
1889 }
1890 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
1891 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
1892 setverdict(pass);
1893 } else {
1894 setverdict(fail);
1895 }
1896
1897 if (not ctxA_deleted) {
1898 ctxA_deleted := true;
1899 setverdict(pass);
1900 } else {
1901 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
1902 }
1903
1904 if (not ctxB_created) {
1905 repeat;
1906 }
1907 }
1908 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
1909 setverdict(fail, "GGSN dropping still valid pdp ctx");
1910 }
1911 }
1912 deactivate(d);
1913 T_default.stop;
1914
1915 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001916 f_shutdown_helper();
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001917 }
1918
1919
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001920 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent
1921 responses (60 seconds): If same delete req is sent and duplicate is
1922 detected, saved duplicate response should be sent back. */
1923 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
1924 f_init();
1925 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1926 f_pdp_ctx_act(ctx);
1927 f_pdp_ctx_del(ctx, '1'B);
1928 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
1929 f_sleep(1.0);
1930 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
1931 duplicate. If it was not a duplicate, osmo-ggsn would answer
1932 with a failure since that PDP ctx was already deleted. */
1933 g_c_seq_nr := g_c_seq_nr - 1;
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01001934 f_pdp_ctx_del(ctx, '1'B, expect_diameter := false);
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001935
1936 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
1937 var OCT1 cause_nonexistent := 'C0'O;
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01001938 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent, expect_diameter := false);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001939 f_shutdown_helper();
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001940 }
1941
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001942 /* Activate PDP context + trigger Recovery procedure through EchoResp */
1943 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
1944 var Gtp1cUnitdata ud;
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001945 g_use_echo_intval := 5;
1946 timer T_echo;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001947 f_init();
1948 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1949 f_pdp_ctx_act(ctx);
1950
1951 /* Wait to receive echo request and send initial Restart counter */
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001952 T_echo.start(int2float(g_use_echo_intval) + 1.0);
1953 alt {
1954 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001955 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1956 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001957 }
1958 [] T_echo.timeout {
1959 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1960 "Timeout waiting for ping");
1961 }
1962 }
1963 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001964
1965 /* Wait to receive second echo request and send incremented Restart
1966 counter. This will fake a restarted SGSN, and pdp ctx allocated
1967 should be released by GGSN */
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06001968 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001969 T_echo.start(int2float(g_use_echo_intval) + 1.0);
1970 alt {
1971 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001972 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1973 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001974 }
1975 [] T_echo.timeout {
1976 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1977 "Timeout waiting for ping");
1978 }
1979 }
1980 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001981 f_pdp_ctx_exp_del_req(ctx, omit, true);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001982 f_shutdown_helper();
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001983 }
1984
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01001985 /* Test creation, user plane and deletion of big amount (1000) of concurrent PDP context */
1986 testcase TC_lots_of_concurrent_pdp_ctx() runs on GT_CT {
1987 var Gtp1cUnitdata udc;
1988 var Gtp1uUnitdata udu;
1989 const integer num_ctx := 1000;
1990 var PdpContext ctx[num_ctx];
1991 timer T_next := 0.01;
1992 var integer next_req_ctx := 0;
1993 var integer rx_resp_ctx := 0;
1994 var integer rx_pong := 0;
1995 var OCT4 dns1_addr;
1996 var OCT4 saddr;
1997 var integer teic;
1998 var integer idx;
1999
2000 f_init();
2001
2002 for (var integer i := 0; i < num_ctx; i := i + 1) {
2003 ctx[i] := valueof(t_DefinePDP(f_rnd_imsi('26242'H), f_rnd_msisdn('1234'O), c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2004 ctx[i].teic := int2oct(i+1, 4); /* +1: skip TEIC=0 */
2005 ctx[i].teid := int2oct(i+1, 4); /* +1: skip TEID=0 */
2006 ctx[i].pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2007 }
2008
2009 T_default.start(60.0);
2010
2011 T_next.start;
2012 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002013 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
2014 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002015 [] pingpong();
2016 [] T_next.timeout {
2017 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx[next_req_ctx].imsi, g_restart_ctr,
2018 ctx[next_req_ctx].teid, ctx[next_req_ctx].teic, ctx[next_req_ctx].nsapi,
2019 ctx[next_req_ctx].eua, ctx[next_req_ctx].apn, g_sgsn_ip_c, g_sgsn_ip_u,
2020 ctx[next_req_ctx].msisdn, ctx[next_req_ctx].pco_req, ctx[next_req_ctx].ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002021 ctx[next_req_ctx].uli, ctx[next_req_ctx].charging_char, ctx[next_req_ctx].imeisv,
2022 ctx[next_req_ctx].ms_tz));
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002023 next_req_ctx := next_req_ctx + 1;
2024 if (next_req_ctx < num_ctx) {
2025 T_next.start;
2026 }
2027 repeat;
2028 }
2029 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2030 teic := oct2int(udc.gtpc.teid);
2031 if (not match(teic, (1 .. num_ctx))) {
2032 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2033 "Rx Unexpected TEIC");
2034 }
2035 idx := teic - 1;
2036 f_handle_create_req(ctx[idx], udc);
2037 rx_resp_ctx := rx_resp_ctx + 1;
2038
2039 dns1_addr := f_PCO_extract_proto(ctx[idx].pco_neg, '000d'O);
2040 saddr := ctx[idx].eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2041 f_send_gtpu(ctx[idx], f_gen_icmpv4_echo(saddr, dns1_addr));
2042 repeat;
2043 }
2044 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value udu {
2045 var octetstring gpdu := udu.gtpu.gtpu_IEs.g_PDU_IEs.data;
2046 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
2047 if (ip4.header.ver != 4) {
2048 repeat;
2049 }
2050 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
2051 if (not match(icmp4, (tr_ICMPv4_ERP, tr_ICMPv4_DU))) {
2052 repeat;
2053 }
2054 rx_pong := rx_pong + 1;
2055 if (rx_pong < num_ctx) {
2056 repeat;
2057 }
2058 setverdict(pass);
2059 }
2060 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2061 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2062 }
2063
2064 /* Let's close them now: */
2065 next_req_ctx := 0;
2066 rx_resp_ctx := 0;
2067 T_next.start;
2068 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002069 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
2070 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002071 [] pingpong();
2072 [] T_next.timeout {
2073 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));
2074 next_req_ctx := next_req_ctx + 1;
2075 if (next_req_ctx < num_ctx) {
2076 T_next.start;
2077 }
2078 repeat;
2079 }
2080 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2081 teic := oct2int(udc.gtpc.teid);
2082 if (not match(teic, (1 .. num_ctx))) {
2083 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2084 "Rx Unexpected TEIC");
2085 }
2086 rx_resp_ctx := rx_resp_ctx + 1;
2087 if (rx_resp_ctx < num_ctx) {
2088 repeat;
2089 }
2090 setverdict(pass);
2091 }
2092 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2093 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2094 }
2095 T_next.stop;
2096
2097 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002098 f_shutdown_helper();
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002099 }
2100
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002101 /* Test callocation of PDP contexts until reaching addr pool exhaustion */
2102 type record of OCT4 TEIClist;
2103 testcase TC_addr_pool_exhaustion() runs on GT_CT {
2104 var Gtp1cUnitdata udc;
2105 var Gtp1uUnitdata udu;
2106 var PdpContext ctx;
2107 timer T_next := 0.005;
2108 var integer next_req_ctx := 0;
2109 var integer rx_resp_ctx := 0;
2110 var integer num_ctx;
2111 var boolean cont_req := true;
2112 var CreatePDPContextResponse cpr;
2113 var TEIClist teic_list := {};
2114 var integer teic;
2115
2116 f_init();
2117
2118 T_default.start(120.0);
2119
2120 T_next.start;
2121 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002122 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
2123 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002124 [] pingpong();
2125 [] T_next.timeout {
2126 if (cont_req) {
2127 if (next_req_ctx - rx_resp_ctx < 100) { /* if we have too many in progress, wait a bit to continue */
2128 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), f_rnd_msisdn('1234'O), c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2129 ctx.nsapi := '0001'B;
2130 ctx.teic := int2oct(next_req_ctx+1, 4); /* +1: skip TEIC=0 */
2131 ctx.teid := int2oct(next_req_ctx+1, 4); /* +1: skip TEID=0 */
2132 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx.imsi, g_restart_ctr,
2133 ctx.teid, ctx.teic, ctx.nsapi,
2134 ctx.eua, ctx.apn, g_sgsn_ip_c, g_sgsn_ip_u,
2135 ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002136 ctx.uli, ctx.charging_char, ctx.imeisv,
2137 ctx.ms_tz));
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002138 next_req_ctx := next_req_ctx + 1;
2139 }
2140 T_next.start;
2141 }
2142 repeat;
2143 }
2144 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2145 cpr := udc.gtpc.gtpc_pdu.createPDPContextResponse;
2146
2147 if (cpr.cause.causevalue == '80'O) {
2148 teic_list := teic_list & {cpr.teidControlPlane.teidControlPlane};
2149 } else {
2150 if (cont_req == true) {
2151 num_ctx := rx_resp_ctx;
2152 log("Successfully created ", num_ctx, " PDP contexts before exhausting the pool");
2153 setverdict(pass);
2154 }
2155 cont_req := false;
2156 }
2157 rx_resp_ctx := rx_resp_ctx + 1;
2158 if (not cont_req and next_req_ctx == rx_resp_ctx) {
2159 break;
2160 } else {
2161 repeat;
2162 }
2163 }
2164 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2165 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2166 }
2167
2168 /* Let's close them now: */
2169 next_req_ctx := 0;
2170 rx_resp_ctx := 0;
2171 T_next.start;
2172 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002173 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrolcb1e8272022-04-20 14:43:43 +02002174 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002175 [] pingpong();
2176 [] T_next.timeout {
2177 f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, teic_list[next_req_ctx], '0001'B, '1'B));
2178 next_req_ctx := next_req_ctx + 1;
2179 if (next_req_ctx < num_ctx) {
2180 T_next.start;
2181 }
2182 repeat;
2183 }
2184 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2185 teic := oct2int(udc.gtpc.teid);
2186 if (not match(teic, (1 .. num_ctx))) {
2187 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2188 "Rx Unexpected TEIC");
2189 }
2190 rx_resp_ctx := rx_resp_ctx + 1;
2191 if (rx_resp_ctx < num_ctx) {
2192 repeat;
2193 }
2194 setverdict(pass);
2195 }
2196 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2197 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2198 }
2199 T_next.stop;
2200
2201 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002202 f_shutdown_helper();
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002203 }
2204
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002205 /* Test charging over Gy interface. */
2206 testcase TC_gy_charging_cc_time() runs on GT_CT {
2207 var default d;
2208
2209 g_gy_validity_time := 3; /* Grant access for 3 seconds, needs to be re-validated afterwards */
2210 f_init();
Pau Espin Pedrol2fe88952022-05-03 14:56:15 +02002211 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234567890'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002212 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2213 f_pdp_ctx_act(ctx);
2214
2215 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2216
2217 /* Send some UL traffic: */
2218 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2219 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2220 f_wait_icmp4_echo_reply(ctx);
2221
2222 T_default.start(10.0);
2223 d := activate(pingpong());
2224
2225 g_gy_validity_time := 2;
2226 /* First update reports octests/pkt on both UL/DL (see icmp ping-pong above) */
2227 as_DIA_Gy_CCR(UPDATE_REQUEST);
2228
2229 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
2230 as_DIA_Gy_CCR(UPDATE_REQUEST);
2231
2232 /* Third update: make sure report contains again octets/pkts for both UL/DL: */
2233 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2234 f_wait_icmp4_echo_reply(ctx);
2235 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2236 f_wait_icmp4_echo_reply(ctx);
2237 as_DIA_Gy_CCR(UPDATE_REQUEST);
2238
2239 /* Let the CCA reach the GGSN */
2240 f_sleep(0.5);
2241 deactivate(d);
2242 T_default.stop;
2243
2244 /* Send some data and validate it is reported in the TERMINATION_REQUEST
2245 * (triggered by PFCP Session Deletion Response): */
2246 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2247 f_wait_icmp4_echo_reply(ctx);
2248
2249 f_pdp_ctx_del(ctx, '1'B);
2250
2251
2252 f_shutdown_helper();
2253 }
2254
Harald Welte94ade362017-08-04 00:36:55 +02002255 control {
Harald Welteed7a1772017-08-09 20:26:20 +02002256 execute(TC_pdp4_act_deact());
2257 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02002258 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02002259 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002260 execute(TC_pdp4_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002261 execute(TC_pdp4_act_deact_gtpu_access_wrong_saddr());
2262 execute(TC_pdp4_act_deact_gtpu_access_ipv6_apn4());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02002263 execute(TC_pdp4_clients_interact_with_txseq());
2264 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02002265 execute(TC_pdp4_act_deact_with_single_dns());
2266 execute(TC_pdp4_act_deact_with_separate_dns());
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01002267 execute(TC_pdp4_act_update_teic());
2268 execute(TC_pdp4_act_update_teid());
Harald Welteed7a1772017-08-09 20:26:20 +02002269
2270 execute(TC_pdp6_act_deact());
2271 execute(TC_pdp6_act_deact_pcodns());
2272 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002273 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002274 execute(TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr());
2275 execute(TC_pdp6_act_deact_gtpu_access_wrong_global_saddr());
2276 execute(TC_pdp6_act_deact_gtpu_access_ipv4_apn6());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01002277 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02002278
Oliver Smithee6a0882019-03-08 11:05:46 +01002279 execute(TC_pdp46_act_deact());
2280 execute(TC_pdp46_act_deact_ipcp());
2281 execute(TC_pdp46_act_deact_icmp6());
2282 execute(TC_pdp46_act_deact_pcodns4());
2283 execute(TC_pdp46_act_deact_pcodns6());
2284 execute(TC_pdp46_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002285 execute(TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4());
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01002286 execute(TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002287 execute(TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6());
Oliver Smithee6a0882019-03-08 11:05:46 +01002288 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002289 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01002290
Harald Weltedca80052017-08-13 20:01:38 +02002291 execute(TC_echo_req_resp());
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01002292 execute(TC_echo_req_resp_gtpu());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002293 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002294 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002295
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01002296 execute(TC_pdp_act_restart_ctr_echo());
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002297
2298 execute(TC_lots_of_concurrent_pdp_ctx());
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002299 /* Keep at the end, crashes older osmo-ggsn versions (OS#5469): */
2300 execute(TC_addr_pool_exhaustion());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002301
2302 /* open5gs specific tests: */
2303 if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
2304 execute(TC_gy_charging_cc_time());
2305 }
Harald Welte94ade362017-08-04 00:36:55 +02002306 }
Harald Welte379d45a2017-08-03 09:55:15 +02002307}