blob: 965dcbe711a899447a34520020895f09a66c0f2e [file] [log] [blame]
Harald Welte379d45a2017-08-03 09:55:15 +02001module GGSN_Tests {
2
Harald Welte34b5a952019-05-27 11:54:11 +02003/* GGSN test suite in TTCN-3
4 * (C) 2017-2019 Harald Welte <laforge@gnumonks.org>
5 * (C) 2018-2019 sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
Pau Espin Pedrold25095f2022-05-18 16:29:05 +020014 import from TCCEncoding_Functions all;
Harald Welte34b5a952019-05-27 11:54:11 +020015
Harald Welte94ade362017-08-04 00:36:55 +020016 import from General_Types all;
Harald Welte811651e2017-08-05 15:25:06 +020017 import from Osmocom_Types all;
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +010018 import from Misc_Helpers all;
Harald Welte94ade362017-08-04 00:36:55 +020019 import from IPL4asp_PortType all;
20 import from IPL4asp_Types all;
21 import from GTP_CodecPort all;
22 import from GTP_CodecPort_CtrlFunct all;
Harald Weltec69cf4e2018-02-17 20:57:02 +010023 import from GTP_Templates all;
Harald Welte94ade362017-08-04 00:36:55 +020024 import from GTPC_Types all;
25 import from GTPU_Types all;
Harald Welte71a36022017-12-04 18:55:58 +010026 import from IPCP_Types all;
Harald Weltef8298542019-04-10 10:15:28 +020027 import from PAP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020028 import from IP_Types all;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +010029 import from ICMP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020030 import from ICMPv6_Types all;
Harald Welteddeecbb2017-08-18 22:53:30 +020031 import from Native_Functions all;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +020032 import from Osmocom_VTY_Functions all;
33 import from TELNETasp_PortType all;
Harald Welte94ade362017-08-04 00:36:55 +020034
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010035 import from DIAMETER_Types all;
36 import from DIAMETER_Templates all;
37 import from DIAMETER_Emulation all;
38
Harald Welte94ade362017-08-04 00:36:55 +020039 const integer GTP0_PORT := 3386;
40 const integer GTP1C_PORT := 2123;
41 const integer GTP1U_PORT := 2152;
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010042 const integer PCRF_PORT := 3868;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +010043 const integer OCS_PORT := 3869;
Harald Welteddeecbb2017-08-18 22:53:30 +020044
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010045 type enumerated GGSN_Impl {
46 GGSN_IMPL_OSMOCOM,
47 GGSN_IMPL_OPEN5GS
48 };
49
Harald Welteddeecbb2017-08-18 22:53:30 +020050 modulepar {
Stefan Sperlingcb782b92018-04-03 16:03:15 +020051 /* Default IP addresses. May be overridden by GGSN_Tests configuration files. */
52
53 /* The SGSN simulated by TTCN3 will bind to these addresses for GTP control and GTP user planes. */
Harald Welteddeecbb2017-08-18 22:53:30 +020054 charstring m_bind_ip_gtpc := "127.23.42.1";
55 charstring m_bind_ip_gtpu := "127.23.42.1";
56
Stefan Sperlingcb782b92018-04-03 16:03:15 +020057 /* Addresses the GGSN which is being tested is listening on for SGSN connections. */
Harald Welteddeecbb2017-08-18 22:53:30 +020058 charstring m_ggsn_ip_gtpc := "127.0.0.6";
59 charstring m_ggsn_ip_gtpu := "127.0.0.6";
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010060
Stefan Sperlingcb782b92018-04-03 16:03:15 +020061 /*
62 * Our tests expect to see these DNS servers in 'Create PDP context responses' sent by the GGSN.
63 * These addresses must therefore match 'ip[v6] dns' options configured in osmo-ggsn.conf.
64 *
65 * These addresses are not expected to serve actual DNS requests. However, tests may expect to be
66 * able to ping these addresses (currently, IPv4 addresses must respond with an ICMP 'echo reply',
67 * and IPv6 addresses may respond with either ICMPv6 'echo reply' or 'destination unreachable').
68 */
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010069 charstring m_ggsn_ip4_dns1 := "192.168.100.1"
70 charstring m_ggsn_ip4_dns2 := "8.8.8.8"
Pau Espin Pedrol363ba482018-01-29 18:42:00 +010071 charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888"
72 charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844"
Stefan Sperlingcb782b92018-04-03 16:03:15 +020073
74 /*
75 * Additional address ranges are defined in osmo-ggsn.conf from which addresses are assigned
76 * to MS "behind" the simulated SGSN. These addresses appear on tun devices used by osmo-ggsn.
77 * The tests expect to be able to send ping packets between any two simulated MS within the same
78 * address range. This requires IP forwarding to be enabled on the corresponding tun interfaces.
79 */
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010080
81 GGSN_Impl m_ggsn_impl := GGSN_IMPL_OSMOCOM;
Harald Welteddeecbb2017-08-18 22:53:30 +020082 }
Harald Welte94ade362017-08-04 00:36:55 +020083
Harald Welte811651e2017-08-05 15:25:06 +020084 type set PdpContext {
85 hexstring imsi,
86 octetstring msisdn optional,
87 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020088 ProtConfigOptions pco_req optional,
89 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020090 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020091 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020092 BIT4 nsapi,
93 /* TEI (Data) local side */
94 OCT4 teid,
95 /* TEI (Control) local side */
96 OCT4 teic,
97 /* TEI (Data) remote side */
98 OCT4 teid_remote,
99 /* TEI (Control) remote side */
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100100 OCT4 teic_remote,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100101 OCT1 ratType optional,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200102 UserLocationInformation uli optional,
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200103 OCT2 charging_char optional,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200104 OCT8 imeisv optional,
105 MS_TimeZone ms_tz optional
Harald Welte811651e2017-08-05 15:25:06 +0200106 }
107
Harald Welte94ade362017-08-04 00:36:55 +0200108 type component GT_CT {
109 port GTPC_PT GTPC;
110 port GTPU_PT GTPU;
111
Harald Welte0be142b2017-08-13 13:28:10 +0200112 var boolean g_initialized := false;
113
Harald Welte94ade362017-08-04 00:36:55 +0200114 var OCT1 g_restart_ctr := '01'O;
115 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200116 var OCT4 g_sgsn_ip_c;
117 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +0200118 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200119 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
120 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200121 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200122
123 /* next to-be-sent GTP-C sequence number */
124 var uint16_t g_c_seq_nr;
125 /* next to-be-sent GTP-U sequence number */
126 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200127
128 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200129 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100130 var integer g_use_echo_intval := 0; /* 0 = disabled */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100131
132 /* emulated PCRF, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100133 var DIAMETER_Emulation_CT vc_Gx;
134 port DIAMETER_PT Gx_UNIT;
135 port DIAMETEREM_PROC_PT Gx_PROC;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100136 var DIAMETER_Emulation_CT vc_Gy;
137 port DIAMETER_PT Gy_UNIT;
138 port DIAMETEREM_PROC_PT Gy_PROC;
139 var integer g_gy_validity_time := 0; /* In seconds. 0 => disabled, !0 => grant over CC-Time period */
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200140 }
141
142 private function f_init_vty() runs on GT_CT {
143 map(self:GGSNVTY, system:GGSNVTY);
144 f_vty_set_prompts(GGSNVTY);
145 f_vty_transceive(GGSNVTY, "enable");
146 }
147
148 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
149 f_vty_enter_config(GGSNVTY);
150 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200151
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200152 f_vty_transceive(GGSNVTY, "apn internet");
153 if (enable) {
154 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
155 } else {
156 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
157 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200158 f_vty_transceive(GGSNVTY, "exit");
159
160 f_vty_transceive(GGSNVTY, "apn inet6");
161 if (enable) {
162 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
163 } else {
164 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
165 }
166 f_vty_transceive(GGSNVTY, "exit");
167
168 f_vty_transceive(GGSNVTY, "apn inet46");
169 if (enable) {
170 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
171 } else {
172 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
173 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200174 f_vty_transceive(GGSNVTY, "end");
175 }
176
177 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
178 if (expect_gptu_txseq) {
179 if (gtpu.s_bit != '1'B) {
180 log("GTPU sequence number expected but not present")
181 return false;
182 }
183 } else {
184 if (gtpu.s_bit != '0'B) {
185 log("GTPU sequence number not expected but present")
186 return false;
187 }
188 }
189 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200190 }
191
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100192 private function f_vty_enable_echo_interval(integer intval_sec) runs on GT_CT {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200193 f_vty_enter_config(GGSNVTY);
194 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100195 if (intval_sec > 0) {
196 f_vty_transceive(GGSNVTY, "echo-interval " & int2str(intval_sec));
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200197 } else {
198 f_vty_transceive(GGSNVTY, "no echo-interval");
199 }
200 f_vty_transceive(GGSNVTY, "end");
201 }
202
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100203 private function DiameterForwardUnitdataCallback(PDU_DIAMETER msg)
204 runs on DIAMETER_Emulation_CT return template PDU_DIAMETER {
205 DIAMETER_UNIT.send(msg);
206 return omit;
207 }
208
209 private function f_init_diameter(charstring id) runs on GT_CT {
210 var DIAMETEROps ops := {
211 create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback),
212 unitdata_cb := refers(DiameterForwardUnitdataCallback),
213 raw := true /* handler mode (single component for all IMSI)) */
214 };
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100215 var DIAMETER_conn_parameters pars;
216
217 /* Gx setup: */
218 pars := {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100219 remote_ip := m_ggsn_ip_gtpc,
220 remote_sctp_port := -1,
221 local_ip := m_bind_ip_gtpc,
222 local_sctp_port := PCRF_PORT,
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100223 origin_host := "pcrf.localdomain",
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100224 origin_realm := "localdomain",
Pau Espin Pedrol33b47492022-03-08 17:43:01 +0100225 auth_app_id := omit,
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100226 vendor_app_id := c_DIAMETER_3GPP_Gx_AID
227 };
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100228 vc_Gx := DIAMETER_Emulation_CT.create(id);
229 map(vc_Gx:DIAMETER, system:DIAMETER_CODEC_PT);
230 connect(vc_Gx:DIAMETER_UNIT, self:Gx_UNIT);
231 connect(vc_Gx:DIAMETER_PROC, self:Gx_PROC);
232 vc_Gx.start(DIAMETER_Emulation.main(ops, pars, id));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100233
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100234 /* Gy setup: */
235 pars := {
236 remote_ip := m_ggsn_ip_gtpc,
237 remote_sctp_port := -1,
238 local_ip := m_bind_ip_gtpc,
239 local_sctp_port := OCS_PORT,
240 origin_host := "ocs.localdomain",
241 origin_realm := "localdomain",
242 auth_app_id := c_DIAMETER_CREDIT_CONTROL_AID,
243 vendor_app_id := omit
244 };
245 vc_Gy := DIAMETER_Emulation_CT.create(id);
246 map(vc_Gy:DIAMETER, system:DIAMETER_CODEC_PT);
247 connect(vc_Gy:DIAMETER_UNIT, self:Gy_UNIT);
248 connect(vc_Gy:DIAMETER_PROC, self:Gy_PROC);
249 vc_Gy.start(DIAMETER_Emulation.main(ops, pars, id));
250
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100251 f_diameter_wait_capability(Gx_UNIT);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100252 f_diameter_wait_capability(Gy_UNIT);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100253 /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdong ping-pongs):
254 * RFC6733 sec 5.1
255 * RFC3539 sec 3.4.1 [5]
256 * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49
257 */
258 f_sleep(1.0);
259 }
260
Harald Welte94ade362017-08-04 00:36:55 +0200261 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200262 if (g_initialized == true) {
263 return;
264 }
265 g_initialized := true;
266
Harald Welteddeecbb2017-08-18 22:53:30 +0200267 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
268 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
269
Harald Welte94ade362017-08-04 00:36:55 +0200270 var Result res;
271 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +0200272 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200273 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200274 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200275
276 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +0200277 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200278 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200279
280 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200281 g_c_seq_nr := f_rnd_int(65535);
282 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200283
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100284 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
285 f_init_vty();
286 f_vty_set_gpdu_txseq(use_gtpu_txseq);
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100287 f_vty_enable_echo_interval(g_use_echo_intval);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100288 } else if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
289 f_init_diameter(testcasename());
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100290 }
Harald Welte94ade362017-08-04 00:36:55 +0200291 }
292
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100293 function f_shutdown_helper() runs on GT_CT {
294 /* Sleep N3_REQUESTS * T3_REQUEST seconds, nowadays 5*3=15s.
295 * This ensures all retransmit queues are cleared before jumping
296 * into next tests, hence avoding situation where a test resuses
297 * a seqnum still in the GGSN's resp queue (dup req detector).
298 * See OS#5485 avout decreasing time. We could also add a new
299 * VTY command that calls gtp_clear_queues() */
300 f_sleep(15.0);
301 setverdict(pass);
302 }
303
Harald Welte94ade362017-08-04 00:36:55 +0200304 /* Altstep implementing responses to any incoming echo requests */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100305 private altstep pingpong() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200306 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200307 var Gtp1uUnitdata udu;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100308 [g_use_echo_intval > 0] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200309 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200310 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200311 repeat;
312 };
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100313 [g_use_echo_intval == 0] GTPC.receive(tr_GTPC_PING(?)) {
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100314 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
315 "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200316 };
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100317 [] T_default.timeout {
318 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
319 "pinpong T_default timeout");
320 };
Harald Welte94ade362017-08-04 00:36:55 +0200321 }
322
Harald Welte811651e2017-08-05 15:25:06 +0200323 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200324 const octetstring c_ApnInternet := '08696E7465726E6574'O;
325 const octetstring c_ApnInet6 := '05696E657436'O;
326 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200327
Harald Welte811651e2017-08-05 15:25:06 +0200328 /* return random NSAPI */
329 function f_rnd_nsapi() return BIT4 {
330 return int2bit(f_rnd_int(16), 4);
331 }
332
333 /* return random TEI[DC] */
334 function f_rnd_tei() return OCT4 {
335 return int2oct(f_rnd_int(4294967296), 4);
336 }
337
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200338 /* return random IMEI(SV) */
339 function f_rnd_imeisv() return OCT8 {
340 return hex2oct(f_rnd_hexstring(16, 10));
341 }
342
Harald Welte811651e2017-08-05 15:25:06 +0200343 /* define an (internal) representation of a PDP context */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +0200344 template PdpContext t_DefinePDP(hexstring imsi, charstring msisdn, octetstring apn,
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100345 EndUserAddress eua, OCT1 ratType := '02'O /* GERAN */) := {
Harald Welte811651e2017-08-05 15:25:06 +0200346 imsi := imsi,
Pau Espin Pedrold25095f2022-05-18 16:29:05 +0200347 msisdn := '11'O & f_enc_TBCD(msisdn), /* encoded as TS 29.060 7.7.33, TS 29.002 */
Harald Welte811651e2017-08-05 15:25:06 +0200348 nsapi := f_rnd_nsapi(),
349 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200350 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200351 eua := eua,
352 teid := f_rnd_tei(),
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100353 teic := f_rnd_tei(),
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100354 ratType := ratType,
355 uli := {
356 type_gtpc := '98'O,
357 lengthf := 0 /* filled in by encoder */,
358 geographicLocationType := '00'O /* CGI */,
359 geographicLocation := {
360 geographicLocationCGI := ts_GeographicLocationCGI('262'H, '42F'H, '0001'O, '0002'O)
361 }
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200362 },
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200363 charging_char := '0000'O,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200364 imeisv := f_rnd_imeisv(),
365 ms_tz := f_ts_MS_TimeZone('03'O, '01'B)
Harald Welte811651e2017-08-05 15:25:06 +0200366 }
367
368 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200369 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200370 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200371 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200372 }
373
374 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200375 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200376 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200377 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
378 g_d_seq_nr := g_d_seq_nr + 1;
379 } else {
380 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
381 }
Harald Welte811651e2017-08-05 15:25:06 +0200382 }
383
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100384 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 +0200385 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100386
387 if (not match(cpr.cause.causevalue, exp_cause)) {
388 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
389 "CreatePDPContextResp: cause expectancies didn't match");
390 }
391
392 if (cpr.cause.causevalue == '80'O) { /* Accepted */
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200393 /* Check if EUA type corresponds to requested type */
394 if (match(ctx.eua, t_EuaIPv4(?)) and
395 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100396 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
397 "EUAv4 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200398 }
399 if (match(ctx.eua, t_EuaIPv6(?)) and
400 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
402 "EUAv6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200403 }
404 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
405 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
407 "EUAv4v6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200408 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100409 } else if (cpr.cause.causevalue == '81'O) { /* Cause: New PDP type due to network preference */
410 /* ETSI TS 129 060 7.3.2 Create PDP Context Response. OS#5449 */
411 /* This should only happen if EUA requested type is v4v6: */
412 if (not ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
413 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
414 "Cause not expected when requesting a non v4v6 EUA");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200415 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100416 if (not match(cpr.endUserAddress, (tr_EuaIPv4(?), tr_EuaIPv6(?)))) {
417 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
418 "Cause not expected when requesting+receiving EUAv4v6");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200419 }
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200420 } else {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100421 if (ispresent(cpr.endUserAddress)) {
422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
423 "EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
424 }
425 setverdict(pass);
426 return;
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200427 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100428
429 /* Check if PCO response corresponds to request */
430 if (ispresent(ctx.pco_req)) {
431 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
432 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
433 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
434 "IPv4 DNS Container requested, but missing");
435 }
436 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
437 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
438 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
439 "IPv6 DNS Container requested, but missing");
440 }
441 }
442 ctx.teid_remote := cpr.teidDataI.teidDataI;
443 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
444 ctx.eua := cpr.endUserAddress;
445 ctx.pco_neg := cpr.protConfigOptions;
446 setverdict(pass);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200447 }
448
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100449 function f_handle_update_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
450 var UpdatePDPContextResponseGGSN upr := ud.gtpc.gtpc_pdu.updatePDPContextResponse.updatePDPContextResponseGGSN;
451 if (exp_cause == '80'O and exp_cause == upr.cause.causevalue) {
452 ctx.teid_remote := upr.teidDataI.teidDataI;
453 ctx.teic_remote := upr.teidControlPlane.teidControlPlane;
454 if (ispresent(upr.protConfigOptions)) {
455 ctx.pco_neg := upr.protConfigOptions;
456 }
457 setverdict(pass);
458 } else if (exp_cause != '80'O and exp_cause == upr.cause.causevalue) {
459 setverdict(pass);
460 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100461 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
462 "UpdatePDPContextResp: cause expectancies didn't match");
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100463 }
464 }
465
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100466 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 +0100467 var PDU_DIAMETER rx_dia;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100468 [] Gx_UNIT.receive(tr_DIA_Gx_CCR(req_type := req_type)) -> value rx_dia {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100469 var template (omit) AVP avp;
470 var octetstring sess_id;
471 var AVP_Unsigned32 req_num;
472
473 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
474 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
475
476 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
477 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
478
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100479 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 +0100480 req_type, req_num));
481 }
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100482 [] Gx_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
484 log2str("Received unexpected DIAMETER ", rx_dia));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100485 }
486 }
487
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100488 private altstep as_DIA_Gy_CCR(DCC_NONE_CC_Request_Type req_type) runs on GT_CT {
489 var PDU_DIAMETER rx_dia;
490 [] Gy_UNIT.receive(tr_DIA_Gy_CCR(req_type := req_type)) -> value rx_dia {
491 var template (value) PDU_DIAMETER tx_dia;
492 var template (omit) AVP avp;
493 var octetstring sess_id;
494 var AVP_Unsigned32 req_num;
495
496 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
497 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
498
499 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
500 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
501 if (g_gy_validity_time > 0) {
502 tx_dia := ts_DIA_Gy_CCA_ValidityTime(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id,
503 req_type, req_num, g_gy_validity_time);
504 } else {
505 tx_dia := ts_DIA_Gy_CCA(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id,
506 req_type, req_num);
507 }
508 Gy_UNIT.send(tx_dia);
509 }
510 [] Gy_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
511 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
512 log2str("Received unexpected DIAMETER Gy", rx_dia));
513 }
514 }
515
Harald Welte811651e2017-08-05 15:25:06 +0200516 /* send a PDP context activation */
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100517 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 +0200518 var Gtp1cUnitdata ud;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100519 var CreatePDPContextResponse cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200520 var default d;
521
522 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200523 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 +0200524 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200525 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200526 ctx.uli, ctx.charging_char, ctx.imeisv, ctx.ms_tz));
Harald Welte94ade362017-08-04 00:36:55 +0200527 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200528 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100529 if (Gx_PROC.checkstate("Connected")) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100530 as_DIA_Gx_CCR(INITIAL_REQUEST);
531 }
532 if (Gy_PROC.checkstate("Connected")) {
533 as_DIA_Gy_CCR(INITIAL_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100534 }
Harald Welte94ade362017-08-04 00:36:55 +0200535 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200536 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200537 f_handle_create_req(ctx, ud, exp_cause);
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100538 cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Harald Welte94ade362017-08-04 00:36:55 +0200539 }
540 }
541 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200542 T_default.stop;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100543 return cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200544 }
545
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200546 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
547 var Gtp1cUnitdata ud;
548 var default d;
549
550 T_default.start;
551 d := activate(pingpong());
552 alt {
553 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
554 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
555 setverdict(pass);
556 } else if (not istemplatekind(expect_cause, "omit") and
557 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
558 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
559 setverdict(pass);
560 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100561 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
562 "DeletePDPContextReq: cause expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200563 }
564
565 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
566 setverdict(pass);
567 } else {
568 setverdict(fail);
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100569 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
570 "DeletePDPContextReq: tearDownIndicator expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200571 }
572 }
573 }
574 deactivate(d);
575 T_default.stop;
576 }
577
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +0100578 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 +0200579 var Gtp1cUnitdata ud;
580 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200581 var OCT4 expect_teid;
582
583 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
584 message with cause value "Non existent" shall be zero. */
585 if (expect_causevalue == 'C0'O) {
586 expect_teid := '00000000'O;
587 } else {
588 expect_teid := ctx.teic;
589 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200590
Harald Welte41575e92017-08-13 13:49:57 +0200591 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 +0200592 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200593 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100594 if (Gx_PROC.checkstate("Connected") and expect_diameter) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100595 as_DIA_Gx_CCR(TERMINATION_REQUEST);
596 }
597 if (Gy_PROC.checkstate("Connected") and expect_diameter) {
598 as_DIA_Gy_CCR(TERMINATION_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100599 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200600 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200601 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
602 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200603 setverdict(pass);
604 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100605 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
606 "DeletePDPContextResp: cause expectancies didn't match");
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200607 }
608 }
609 }
610 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200611 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200612 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100613
614 /* send a Update PdP Context Request, expect Response */
615 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 {
616 var Gtp1cUnitdata ud;
617 var default d;
618
619 if (not istemplatekind(new_teid, "omit")) {
620 ctx.teid := valueof(new_teid);
621 }
622 if (not istemplatekind(new_teic, "omit")) {
623 ctx.teic := valueof(new_teic);
624 }
625
626 log("sending UpdatePDP");
627 f_send_gtpc(ts_GTPC_UpdatePDP(g_peer_c, ctx.teic_remote, g_c_seq_nr, ctx.imsi, g_restart_ctr,
628 ctx.teid, ctx.teic, ctx.nsapi, g_sgsn_ip_c, g_sgsn_ip_u,
629 ctx.pco_req, ctx.ratType, ctx.uli));
630 T_default.start;
631 d := activate(pingpong());
632 alt {
633 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, updatePDPContextResponse, ctx.teic)) -> value ud {
634 f_handle_update_req(ctx, ud, exp_cause);
635 }
636 }
637 deactivate(d);
638 T_default.stop;
639 }
640
Harald Welte811651e2017-08-05 15:25:06 +0200641 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
642 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
643 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
644 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200645
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200646 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100647 template PDU_ICMP ts_ICMPv4_ERQ := {
648 echo := {
649 type_field := 8,
650 code := 0,
651 checksum := '0000'O,
652 identifier := '0345'O,
653 sequence_number := '0001'O,
654 data := ''O
655 }
656 }
657
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200658 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100659 template PDU_ICMP tr_ICMPv4_ERQ := {
660 echo := {
661 type_field := 8,
662 code := 0,
663 checksum := ?,
664 identifier := ?,
665 sequence_number := ?,
666 data := ?
667 }
668 }
669
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200670 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100671 template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
672 echo_reply := {
673 type_field := 0,
674 code := 0,
675 checksum := ?,
676 identifier := ?,
677 sequence_number := ?,
678 data := data
679 }
680 }
681
682 /* template for receiving/matching an ICMPv6 Destination Unreachable */
683 template PDU_ICMP tr_ICMPv4_DU := {
684 destination_unreachable := {
685 type_field := 1,
686 code := ?,
687 checksum := ?,
688 unused := ?,
689 original_ip_msg := ?
690 }
691 }
692
693 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
694 template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
695 header := {
696 ver := 4,
697 hlen := 5,
698 tos := 0,
699 tlen := tlen,
700 id := 35902,
701 res := '0'B,
702 dfrag := '1'B,
703 mfrag := '0'B,
704 foffset := 0,
705 ttl := 64,
706 proto := proto,
707 cksum := 0,
708 srcaddr := srcaddr,
709 dstaddr := dstaddr
710 },
711 ext_headers := omit,
712 payload := payload
713 }
714
Harald Welte231b9412017-08-09 17:16:31 +0200715 /* template to generate a 'Prefix Information' ICMPv6 option */
716 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
717 prefixInformation := {
718 typeField := 3,
719 lengthIndicator := 8,
720 prefixLength := prefix_len,
721 reserved1 := '000000'B,
722 a_Bit := '0'B,
723 l_Bit := '0'B,
724 validLifetime := oct2int('FFFFFFFF'O),
725 preferredLifetime := oct2int('FFFFFFFF'O),
726 reserved2 := '00000000'O,
727 prefix := prefix
728 }
729 }
730
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200731 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100732 template PDU_ICMPv6 ts_ICMPv6_ERQ := {
733 echoRequest := {
734 typeField := 128,
735 code := 0,
736 checksum := '0000'O,
737 identifier := 0,
738 sequenceNr := 0,
739 data := ''O
740 }
741 }
742
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200743 /* template for sending an ICMPv6 router solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200744 template PDU_ICMPv6 ts_ICMPv6_RS := {
745 routerSolicitation := {
746 typeField := 133,
747 code := 0,
748 checksum := '0000'O,
749 reserved := '00000000'O,
750 /* TODO: do we need 'Source link-layer address' ? */
751 options := omit
752 }
753 }
754
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200755 /* template for sending an ICMPv6 router advertisement */
Harald Welte231b9412017-08-09 17:16:31 +0200756 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
757 routerAdvertisement := {
758 typeField := 134,
759 code := 0,
760 checksum := '0000'O,
761 curHopLimit := ?,
762 reserved := '000000'B,
763 o_Bit := '0'B,
764 m_Bit := '0'B,
765 routerLifetime := oct2int('FFFF'O),
766 reachableTime := oct2int('FFFFFFFF'O),
767 retransTimer := oct2int('FFFFFFFF'O),
768 options := {
769 ts_ICMP6_OptPrefix(prefix, prefix_len)
770 }
771 }
772 }
773
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200774 /* template for sending an ICMPv6 neighbor solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200775 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
776 neighborSolicitation := {
777 typeField := 135,
778 code := 0,
779 checksum := '0000'O,
780 reserved := '00000000'O,
781 targetAddress := target_addr,
782 /* TODO: do we need 'Source link-layer address' ? */
783 options := omit
784 }
785 }
786
787 /* derive ICMPv6 link-local address from lower 64bit of link_id */
788 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
789 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
790 prefixInformation := {
791 typeField := 3,
792 lengthIndicator := 4,
793 prefixLength := prefix_len,
794 reserved1 := ?,
795 a_Bit := ?,
796 l_Bit := ?,
797 validLifetime := ?,
798 preferredLifetime := ?,
799 reserved2 := ?,
800 prefix := prefix
801 }
802 }
803
804 /* template for receiving/matching an ICMPv6 router advertisement */
805 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
806 routerAdvertisement := {
807 typeField := 134,
808 code := 0,
809 checksum := ?,
810 curHopLimit := ?,
811 reserved := ?,
812 o_Bit := '0'B,
813 m_Bit := '0'B,
814 routerLifetime := ?,
815 reachableTime := ?,
816 retransTimer := ?,
817 options := {
818 tr_ICMP6_OptPrefix(prefix, prefix_len)
819 }
820 }
821 }
822
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100823 /* template for receiving/matching an ICMPv6 Destination Unreachable */
824 template PDU_ICMPv6 tr_ICMPv6_DU := {
825 destinationUnreachable := {
826 typeField := 1,
827 code := ?,
828 checksum := ?,
829 unused := ?,
830 originalIpMsg := ?
831 }
832 }
833
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200834 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100835 template PDU_ICMPv6 tr_ICMPv6_ERQ := {
836 echoRequest := {
837 typeField := 128,
838 code := 0,
839 checksum := ?,
840 identifier := ?,
841 sequenceNr := ?,
842 data := ?
843 }
844 }
845
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100846 /* template for receiving/matching an ICMPv6 echo reply */
847 template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
848 echoReply := {
849 typeField := 129,
850 code := 0,
851 checksum := ?,
852 identifier := ?,
853 sequenceNr := ?,
854 data := data
855 }
856 }
857
Harald Welte231b9412017-08-09 17:16:31 +0200858 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
859 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
860 header := {
861 ver := 6,
862 trclass := 0,
863 flabel := 0,
864 plen := 0,
865 nexthead := nexthead,
866 hlim := hlim,
867 srcaddr := srcaddr,
868 dstaddr := dstaddr
869 },
870 ext_headers := omit,
871 payload := payload
872 }
873
874 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
875 return 'FE80000000000000'O & substr(link_id, 8, 8);
876 }
877
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100878 function f_ipv6_global(in OCT16 link_id) return OCT16 {
879 return substr(link_id, 0, 8) & '1234123412341234'O;
880 }
881
882 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
883 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
884 var integer i;
885 var octetstring res := substr(addr, 0, prefix);
886 for (i := prefix; i < lengthof(addr); i := i + 1) {
887 var octetstring a := addr[i] xor4b '11'O;
888 res := res & a;
889 }
890 return res;
891 }
892
Harald Welte231b9412017-08-09 17:16:31 +0200893 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
894 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
895 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
896 }
897
898 /* generate and encode ICMPv6 router solicitation */
899 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
900 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
901 var OCT16 saddr := f_ipv6_link_local(link_id);
902
903 var octetstring tmp;
904 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
905 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
906
907 return f_IPv6_enc(ip6);
908 }
909
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100910 /* Get link-id from PDP Context EUA */
911 function f_ctx_get_ipv6_interface_id(in PdpContext ctx) return OCT16 {
912 var OCT16 interface_id;
913 if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
914 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
915 } else if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv6)) {
916 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
917 } else {
918 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected request to submit icmpv6 rs in IPv4 PDP context");
919 }
920 return interface_id;
921 }
922
Harald Welte231b9412017-08-09 17:16:31 +0200923 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
924 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100925 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200926 return f_gen_icmpv6_router_solicitation(interface_id);
927 }
928
929 /* generate and encode ICMPv6 neighbor solicitation */
930 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
931 var octetstring tmp;
932 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
933 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
934 return f_IPv6_enc(ip6);
935 }
936
937 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
938 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100939 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200940 var OCT16 link_local := f_ipv6_link_local(interface_id);
941 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
942
943 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
944 }
945
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100946 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
947 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring {
948 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ));
949 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
950 var octetstring data := f_IPv4_enc(ip4);
951 var OCT2 cksum := f_IPv4_checksum(data);
952 data[10] := cksum[0];
953 data[11] := cksum[1];
954 return data;
955 }
956
957 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
958 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
959 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
960 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
961 var octetstring data := f_IPv6_enc(ip6);
962 return data;
963 }
964
965 /* Wait for ICMPv4 from GTP */
966 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +0200967 var Gtp1uUnitdata ud;
968 T_default.start;
969 alt {
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100970 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ctx.teid)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200971 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200972 setverdict(fail);
973 stop;
974 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100975 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
976 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
977 if (ip4.header.ver != 4) {
978 repeat;
979 }
980 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
981 if (not match(icmp4, expected)) {
982 repeat;
983 }
984 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100985 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
986 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
987 "Received wrong local TEID");
988 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100989 [] GTPU.receive { setverdict(fail); }
990 [] T_default.timeout { setverdict(fail); }
991 }
992 T_default.stop;
993 }
994
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100995 /* Wait for ICMPv4 echo request from GTP */
996 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
997 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
998 }
999
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001000 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
1001 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
1002 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
1003 }
1004
1005 /* Wait for ICMPv6 from GTP */
1006 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
1007 var Gtp1uUnitdata ud;
1008 T_default.start;
1009 alt {
Harald Welte231b9412017-08-09 17:16:31 +02001010 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +02001011 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001012 setverdict(fail);
1013 stop;
1014 }
Harald Welte231b9412017-08-09 17:16:31 +02001015 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1016 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001017 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +02001018 repeat;
1019 }
1020 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001021 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +02001022 repeat;
1023 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001024 /* We are waiting for RA, update ctx */
1025 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
1026 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
1027 log("RA with /64 prefix ", ctx.ip6_prefix);
1028 }
Harald Welte231b9412017-08-09 17:16:31 +02001029 }
1030 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
1031 [] GTPU.receive { setverdict(fail); }
1032 [] T_default.timeout { setverdict(fail); }
1033 }
1034 T_default.stop;
1035 }
1036
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001037 /* wait for GGSN to send us an ICMPv6 router advertisement */
1038 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
1039 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
1040 }
1041
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001042 /* Wait for ICMPv6 echo request from GTP */
1043 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
1044 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
1045 }
1046
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001047 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
1048 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
1049 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
1050 }
1051
Oliver Smithee6a0882019-03-08 11:05:46 +01001052 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
1053 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
1054 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1055 return f_gen_icmpv6_router_solicitation(interface_id);
1056 }
1057
1058 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
1059 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
1060 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1061 var OCT16 link_local := f_ipv6_link_local(interface_id);
1062 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
1063
1064 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
1065 }
1066
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001067 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
1068 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
1069 T_default.start;
1070 alt {
1071 [] GTPU.receive { setverdict(fail); }
1072 [] T_default.timeout { }
1073 }
1074 T_default.stop;
1075 }
1076
Harald Welte79737b42019-04-10 10:39:30 +02001077 /* list of protocols where we don't accept duplicates */
1078 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
1079 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
1080 var integer i;
1081 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
1082 if (id == protocol_ids_nodupes[i]) {
1083 return false;
1084 }
1085 }
1086 return true;
1087 }
1088
1089 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
1090 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
1091 var OCT2List protocol_ids := {};
1092 var integer i, j;
1093 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
1094 var OCT2 id := pco.protocols[i].protocolID;
1095 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
1096 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
1097 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
1098 }
1099 }
1100 protocol_ids := protocol_ids & { id };
1101 }
1102 }
1103
Harald Welte0ef285b2017-08-13 20:06:01 +02001104 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +02001105 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +02001106 f_init();
Harald Welte231b9412017-08-09 17:16:31 +02001107
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001108 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welte811651e2017-08-05 15:25:06 +02001109 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +02001110 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001111 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001112 }
1113
Harald Welte0ef285b2017-08-13 20:06:01 +02001114 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001115 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
1116 f_init();
1117
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001118 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001119 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1120 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001121
Harald Welte79737b42019-04-10 10:39:30 +02001122 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001123 /* verify PCO contains both primary and secondary DNS */
1124 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1125 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1126 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1127 }
1128
1129 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1130 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1131 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1132 }
1133
Harald Welteed7a1772017-08-09 20:26:20 +02001134 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001135 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001136 }
1137
Harald Welte0ef285b2017-08-13 20:06:01 +02001138 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +02001139 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
1140 f_init();
1141
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001142 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001143 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1144 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001145
Harald Welte79737b42019-04-10 10:39:30 +02001146 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +02001147 //f_send_gtpu(ctx, c_router_solicit);
1148 //f_send_gtpu(ctx, c_neigh_solicit);
1149
1150 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1151 f_wait_rtr_adv(ctx);
1152 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1153
Harald Welte811651e2017-08-05 15:25:06 +02001154 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001155 f_shutdown_helper();
Harald Welte94ade362017-08-04 00:36:55 +02001156 }
1157
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001158 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
1159 Test we can send ICMPv6 ping over GTPU to DNS server. */
1160 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
1161 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001162 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001163 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1164 f_pdp_ctx_act(ctx);
1165
1166 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1167 f_wait_rtr_adv(ctx);
1168 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1169
1170 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1171
1172 /* Check if we can use valid link-local src addr. */
1173 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1174 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
Pau Espin Pedrolb63d85f2022-02-07 16:11:47 +01001175 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
1176 f_wait_icmp6_echo_reply(ctx);
1177 } else {
1178 f_wait_gtpu_fail(ctx);
1179 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001180
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001181 /* Check if we can use valid global src addr, should work */
1182 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1183 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
1184 f_wait_icmp6_echo_reply(ctx);
1185
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001186 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001187 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001188 }
1189
1190 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1191 testcase TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr() runs on GT_CT {
1192 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001193 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001194 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1195 f_pdp_ctx_act(ctx);
1196
1197 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1198 f_wait_rtr_adv(ctx);
1199 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1200
1201 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1202 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1203 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1204 f_wait_gtpu_fail(ctx);
1205
1206 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001207 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001208 }
1209
1210 /* Assert that packets with wrong global src addr are dropped by GGSN */
1211 testcase TC_pdp6_act_deact_gtpu_access_wrong_global_saddr() runs on GT_CT {
1212 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001213 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001214 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1215 f_pdp_ctx_act(ctx);
1216
1217 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1218 f_wait_rtr_adv(ctx);
1219 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1220
1221 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1222 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001223 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1224 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
1225 f_wait_gtpu_fail(ctx);
1226
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001227 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001228 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001229 }
1230
1231 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped */
1232 testcase TC_pdp6_act_deact_gtpu_access_ipv4_apn6() runs on GT_CT {
1233 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001234 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001235 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1236 f_pdp_ctx_act(ctx);
1237
1238 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1239 f_wait_rtr_adv(ctx);
1240 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1241
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001242 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
1243 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
1244 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
1245 f_wait_gtpu_fail(ctx);
1246
1247 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001248 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001249 }
1250
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001251 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1252 testcase TC_pdp6_clients_interact() runs on GT_CT {
1253 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001254 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1255 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001256 f_pdp_ctx_act(ctxA);
1257 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
1258 f_wait_rtr_adv(ctxA);
1259 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
1260
1261 f_pdp_ctx_act(ctxB);
1262 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
1263 f_wait_rtr_adv(ctxB);
1264 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
1265
1266 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1267 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1268 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1269 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1270
1271 /* Validate if clients can interact using ll addr. */
1272 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1273 f_wait_gtpu_fail(ctxB);
1274
1275 /* Validate if clients can interact using global addr. */
1276 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1277 f_wait_gtpu_fail(ctxB);
1278
1279 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001280 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001281 f_shutdown_helper();
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001282 }
1283
Harald Welte0ef285b2017-08-13 20:06:01 +02001284 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +02001285 testcase TC_pdp4_act_deact() runs on GT_CT {
1286 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001287 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001288 f_pdp_ctx_act(ctx);
1289 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001290 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001291 }
1292
Harald Welte0ef285b2017-08-13 20:06:01 +02001293 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +02001294 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
1295 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001296 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1297 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001298 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001299 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +02001300 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001301 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +01001302 /* verify IPCP is at all contained */
1303 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1304 setverdict(fail, "IPCP not found in PCO");
1305 }
1306 /* verify IPCP contains both primary and secondary DNS */
1307 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001308 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1309 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1310 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1311 } else {
1312 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1313 }
Harald Welte71a36022017-12-04 18:55:58 +01001314 }
Harald Welteed7a1772017-08-09 20:26:20 +02001315 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001316 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001317 }
1318
Harald Weltef8298542019-04-10 10:15:28 +02001319 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
1320 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
1321 f_init();
1322 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1323 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001324 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltef8298542019-04-10 10:15:28 +02001325 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1326 f_pdp_ctx_act(ctx);
1327 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1328 /* verify IPCP is at all contained */
1329 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1330 setverdict(fail, "IPCP not found in PCO");
1331 }
1332 /* verify IPCP contains both primary and secondary DNS */
1333 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1334 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1335 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1336 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1337 } else {
1338 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1339 }
1340 }
1341 /* verify that PAP is contained */
1342 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1343 setverdict(fail, "PAP not found in PCO");
1344 }
1345 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1346 if (not match(pap, tr_PAP_AuthAck)) {
1347 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1348 }
1349 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001350 f_shutdown_helper();
Harald Weltef8298542019-04-10 10:15:28 +02001351 }
1352
Harald Welte0ef285b2017-08-13 20:06:01 +02001353 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001354 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1355 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001356 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001357 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001358 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001359
Harald Welte79737b42019-04-10 10:39:30 +02001360 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001361 /* verify PCO contains both primary and secondary DNS */
1362 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1363 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1364 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1365 }
1366
1367 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1368 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1369 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1370 }
1371
Harald Welteed7a1772017-08-09 20:26:20 +02001372 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001373 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001374 }
1375
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001376 /* Test PDP context activation for dynamic IPv4 EUA.
1377 Test we can send ICMPv6 ping over GTPU to DNS server. */
1378 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1379 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001380 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001381 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1382 f_pdp_ctx_act(ctx);
1383
Harald Welte79737b42019-04-10 10:39:30 +02001384 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001385 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1386
1387 /* Check if we can use valid global src addr, should work */
1388 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1389 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1390 f_wait_icmp4_echo_reply(ctx);
1391
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001392 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001393 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001394 }
1395
1396 /* Assert that packets with wrong global src addr are dropped by GGSN */
1397 testcase TC_pdp4_act_deact_gtpu_access_wrong_saddr() runs on GT_CT {
1398 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001399 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001400 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1401 f_pdp_ctx_act(ctx);
1402
1403 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1404 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1405 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001406 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1407 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1408 f_wait_gtpu_fail(ctx);
1409
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001410 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001411 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001412 }
1413
1414 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1415 testcase TC_pdp4_act_deact_gtpu_access_ipv6_apn4() runs on GT_CT {
1416 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001417 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001418 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1419 f_pdp_ctx_act(ctx);
1420
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001421 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1422 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1423 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1424 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001425
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001426 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001427 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001428 }
1429
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001430 /* Helper function for tests below. */
1431 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001432 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001433 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1434 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001435 f_pdp_ctx_act(ctxA);
1436 f_pdp_ctx_act(ctxB);
1437 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1438 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1439 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1440 f_wait_icmp4_echo_request(ctxB);
1441
1442 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001443 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001444 }
1445
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001446 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1447 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001448 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001449 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001450 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001451 }
1452
1453 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1454 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001455 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001456 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001457 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001458 }
1459
Harald Weltedca80052017-08-13 20:01:38 +02001460 testcase TC_echo_req_resp() runs on GT_CT {
1461 f_init();
1462 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1463 T_default.start;
1464 alt {
1465 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1466 [] GTPC.receive { repeat; };
1467 [] T_default.timeout { setverdict(fail); }
1468 }
1469 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001470 f_shutdown_helper();
Harald Weltedca80052017-08-13 20:01:38 +02001471 }
1472
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001473 testcase TC_echo_req_resp_gtpu() runs on GT_CT {
1474 f_init();
1475 GTPU.send(ts_GTPU_PING(g_peer_u, g_d_seq_nr));
1476 T_default.start;
1477 alt {
1478 [] GTPU.receive(tr_GTPU_PONG(g_peer_u)) { setverdict(pass); };
1479 [] GTPU.receive { repeat; };
1480 [] T_default.timeout { setverdict(fail); }
1481 }
1482 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001483 f_shutdown_helper();
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001484 }
1485
Philipp Maier33e52612018-05-30 17:22:02 +02001486 /* Test if the parser can cope with PCO that only contain either a
1487 * single primary DNS or a secondary DNS. */
1488 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1489
1490 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1491 * the test is executed.
1492 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1493
1494 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001495 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001496 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1497 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1498 var octetstring pco_neg_dns;
1499 var octetstring pco_neg_dns_expected;
1500
1501 /* PCO with primary DNS only */
1502 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1503 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001504 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001505 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1506 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1507 /* Note: The prepended hex bytes encode the following information:
1508 * 0x02 = Configuration ACK
1509 * 0x00 = Identifier
1510 * 0x000a = Length
1511 * 0x81 = Type (Primary DNS Server Address)
1512 * 0x06 = Length
1513 * (4 byte IP-Address appended) */
1514 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1515 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1516 }
1517 f_pdp_ctx_del(ctx, '1'B);
1518
1519 /* PCO with secondary DNS only */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001520 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001521 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1522 f_pdp_ctx_act(ctx);
1523 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1524 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1525 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1526 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1527 }
1528 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001529 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001530 }
1531
1532 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1533 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1534 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1535 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1536
1537 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1538 * the test is executed.
1539 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1540
1541 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001542 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001543 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1544 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1545 var octetstring pco_neg_dns;
1546 var octetstring pco_neg_dns_expected;
1547
1548 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1549 f_pdp_ctx_act(ctx);
1550
1551 /* Check if primary DNS is contained */
1552 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1553 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1554 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1555 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1556 }
Philipp Maier33e52612018-05-30 17:22:02 +02001557
1558 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001559 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1560 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001561 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1562 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1563 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1564 }
1565 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001566 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001567 }
1568
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001569 /* Validate that SUT updates remote TEIC when requested through UpdatePDPContextRequest */
1570 testcase TC_pdp4_act_update_teic() runs on GT_CT {
1571 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001572 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001573 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1574 f_pdp_ctx_act(ctx);
1575
1576 /* UpdatePDPContestRequest changing the local TEIC */
1577 var OCT4 new_teic := ctx.teic;
1578 new_teic[3] := new_teic[3] xor4b '11'O;
1579 f_pdp_ctx_update(ctx, new_teic := new_teic);
1580
1581 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001582 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001583 }
1584
1585 /* Validate that SUT updates remote TEID when requested through UpdatePDPContextRequest */
1586 testcase TC_pdp4_act_update_teid() runs on GT_CT {
1587 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001588 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001589 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1590 f_pdp_ctx_act(ctx);
1591
1592 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1593 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1594 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1595
1596 /* Data is sent (back) to the local TEID established during CreatePDPContext */
1597 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1598 f_wait_icmp4_echo_reply(ctx);
1599
1600 /* UpdatePDPContestRequest changing the local TEID */
1601 var OCT4 new_teid := ctx.teid;
1602 new_teid[3] := new_teid[3] xor4b '11'O;
1603 f_pdp_ctx_update(ctx, new_teid := new_teid);
1604
1605 /* Check if we can send data after updating the PDP context. Answer should be sent to the new TEID */
1606 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1607 f_wait_icmp4_echo_reply(ctx);
1608
1609 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001610 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001611 }
1612
Oliver Smithee6a0882019-03-08 11:05:46 +01001613 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1614 testcase TC_pdp46_act_deact() runs on GT_CT {
1615 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001616 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001617 f_pdp_ctx_act(ctx);
1618 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001619 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001620 }
1621
1622 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1623 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1624 f_init();
1625 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1626 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001627 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001628 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1629 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001630 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001631 /* verify IPCP is at all contained */
1632 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1633 setverdict(fail, "IPCP not found in PCO");
1634 }
Harald Welte79737b42019-04-10 10:39:30 +02001635 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001636 /* verify IPCP contains both primary and secondary IPv4 DNS */
1637 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1638 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1639 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1640 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1641 } else {
1642 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1643 }
1644 }
1645 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001646 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001647 }
1648
1649 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1650 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1651 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001652 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001653 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1654 f_pdp_ctx_act(ctx);
1655
1656 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1657 f_wait_rtr_adv(ctx);
1658 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1659
1660 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001661 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001662 }
1663
1664 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1665 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1666 f_init();
1667
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001668 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001669 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1670 f_pdp_ctx_act(ctx);
1671
Harald Welte79737b42019-04-10 10:39:30 +02001672 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001673 /* verify PCO contains both primary and secondary IPv4 DNS */
1674 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1675 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1676 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1677 }
1678
1679 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1680 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1681 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1682 }
1683
1684 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001685 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001686 }
1687
1688 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1689 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1690 f_init();
1691
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001692 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001693 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1694 f_pdp_ctx_act(ctx);
1695
Harald Welte79737b42019-04-10 10:39:30 +02001696 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001697 /* verify PCO contains both primary and secondary IPv6 DNS */
1698 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1699 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1700 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1701 }
1702
1703 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1704 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1705 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1706 }
1707
1708 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001709 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001710 }
1711
1712 /* Test PDP context activation for dynamic IPv4v6 EUA.
1713 Test we can send ICMPv6 ping over GTPU to DNS server. */
1714 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1715 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001716 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001717 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1718 f_pdp_ctx_act(ctx);
1719
1720 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1721
1722 /* Check if we can use valid global src addr, should work */
1723 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1724 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1725 f_wait_icmp4_echo_reply(ctx);
1726
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001727 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001728 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001729 }
1730
1731 /* Assert that packets with wrong ipv4 src addr are dropped by GGSN on APN IPv4v6 */
1732 testcase TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4() runs on GT_CT {
1733 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001734 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001735 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1736 f_pdp_ctx_act(ctx);
1737
1738 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1739 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
Oliver Smithee6a0882019-03-08 11:05:46 +01001740 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1741 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1742 f_wait_gtpu_fail(ctx);
1743
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001744 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001745 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001746 }
1747
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001748 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1749 testcase TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6() runs on GT_CT {
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001750 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001751 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001752 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1753 f_pdp_ctx_act(ctx);
1754
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001755 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1756 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1757 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1758 f_wait_gtpu_fail(ctx);
1759
1760 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001761 f_shutdown_helper();
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001762 }
1763
1764 /* Assert that packets with wrong ipv6 global src addr are dropped by GGSN on APN IPv4v6 */
1765 testcase TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6() runs on GT_CT {
1766 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001767 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001768 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1769 f_pdp_ctx_act(ctx);
1770
1771 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1772 f_wait_rtr_adv(ctx);
1773 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1774
1775 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1776 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1777 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1778 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
Oliver Smithee6a0882019-03-08 11:05:46 +01001779 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001780
Oliver Smithee6a0882019-03-08 11:05:46 +01001781 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001782 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001783 }
1784
1785 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1786 testcase TC_pdp46_clients_interact() runs on GT_CT {
1787 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001788 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1789 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001790 f_pdp_ctx_act(ctxA);
1791 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1792 f_wait_rtr_adv(ctxA);
1793 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1794
1795 f_pdp_ctx_act(ctxB);
1796 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1797 f_wait_rtr_adv(ctxB);
1798 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1799
1800 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1801 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1802 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1803 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1804
1805 /* Validate if clients can interact using ll addr. */
1806 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1807 f_wait_gtpu_fail(ctxB);
1808
1809 /* Validate if clients can interact using global addr. */
1810 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1811 f_wait_gtpu_fail(ctxB);
1812
1813 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001814 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001815 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001816 }
1817
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001818 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
1819 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001820 const OCT1 cause_accept := '80'O; /* Normal accept cause */
1821 const OCT1 cause_new_pdp_type := '81'O; /* Cause: New PDP type due to network preference */
1822 const OCT1 cause_unknown_pdp := 'DC'O; /* Cause: Unknown PDP address or PDP type */
1823 var CreatePDPContextResponse cpr;
1824
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001825 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001826 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001827 cpr := f_pdp_ctx_act(ctx46, (cause_unknown_pdp, cause_new_pdp_type));
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001828
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001829 if (cpr.cause.causevalue == cause_new_pdp_type) {
1830 /* 3GPP TS 23.060 sec 9.2.1: "If the MS requests PDP type IPv4v6,
1831 * but the operator preferences dictate the use of a single IP
1832 * version only, the PDP type shall be changed to a single address
1833 * PDP type (IPv4 or IPv6) and a reason cause shall be returned to
1834 * the MS indicating that only the assigned PDP type is allowed. In
1835 * this case, the MS shall not request another PDP context for the
1836 * other PDP type during the existence of the PDP context." */
1837 f_pdp_ctx_del(ctx46, '1'B);
1838 } else {
1839 /* 3GPP TS 23.060 sec 9.2.1 NOTE 5: If the MS requests PDP type
1840 * IPv4v6, and the PDP context is rejected due to "unknown PDP
1841 * type", the MS can attempt to establish dual-stack connectivity
1842 * by performing two PDP context request procedures to activate an
1843 * IPv4 PDP context and an IPv6 PDP context, both to the same APN. A
1844 * typical MS first attempts v4v6, and if rejected, then tries v4
1845 * and v6 separetly */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001846 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001847 f_pdp_ctx_act(ctx4, cause_accept); /* Normal accept cause */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001848
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001849 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001850 f_pdp_ctx_act(ctx6, cause_unknown_pdp); /* Cause: Unknown PDP address or PDP type */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001851
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001852 f_pdp_ctx_del(ctx4, '1'B);
1853 }
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001854 f_shutdown_helper();
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001855 }
1856
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001857 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
1858 testcase TC_pdp_act2_recovery() runs on GT_CT {
1859 var Gtp1cUnitdata ud;
1860 var default d;
1861 var boolean ctxA_deleted := false;
1862 var boolean ctxB_created := false;
1863
1864 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001865 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1866 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001867 f_pdp_ctx_act(ctxA);
1868
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06001869 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001870
1871 log("sending 2nd CreatePDP (recovery increased)");
1872 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
1873 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
1874 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
1875 T_default.start;
1876 d := activate(pingpong());
1877 alt {
1878 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
1879 f_handle_create_req(ctxB, ud);
1880 if (not ctxB_created) {
1881 ctxB_created := true;
1882 setverdict(pass);
1883 } else {
1884 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
1885 }
1886
1887 if (not ctxA_deleted) {
1888 repeat;
1889 }
1890 }
1891 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
1892 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
1893 setverdict(pass);
1894 } else {
1895 setverdict(fail);
1896 }
1897
1898 if (not ctxA_deleted) {
1899 ctxA_deleted := true;
1900 setverdict(pass);
1901 } else {
1902 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
1903 }
1904
1905 if (not ctxB_created) {
1906 repeat;
1907 }
1908 }
1909 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
1910 setverdict(fail, "GGSN dropping still valid pdp ctx");
1911 }
1912 }
1913 deactivate(d);
1914 T_default.stop;
1915
1916 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001917 f_shutdown_helper();
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001918 }
1919
1920
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001921 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent
1922 responses (60 seconds): If same delete req is sent and duplicate is
1923 detected, saved duplicate response should be sent back. */
1924 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
1925 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001926 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001927 f_pdp_ctx_act(ctx);
1928 f_pdp_ctx_del(ctx, '1'B);
1929 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
1930 f_sleep(1.0);
1931 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
1932 duplicate. If it was not a duplicate, osmo-ggsn would answer
1933 with a failure since that PDP ctx was already deleted. */
1934 g_c_seq_nr := g_c_seq_nr - 1;
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01001935 f_pdp_ctx_del(ctx, '1'B, expect_diameter := false);
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001936
1937 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
1938 var OCT1 cause_nonexistent := 'C0'O;
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01001939 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent, expect_diameter := false);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001940 f_shutdown_helper();
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001941 }
1942
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001943 /* Activate PDP context + trigger Recovery procedure through EchoResp */
1944 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
1945 var Gtp1cUnitdata ud;
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001946 g_use_echo_intval := 5;
1947 timer T_echo;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001948 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001949 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001950 f_pdp_ctx_act(ctx);
1951
1952 /* Wait to receive echo request and send initial Restart counter */
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001953 T_echo.start(int2float(g_use_echo_intval) + 1.0);
1954 alt {
1955 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001956 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1957 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001958 }
1959 [] T_echo.timeout {
1960 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1961 "Timeout waiting for ping");
1962 }
1963 }
1964 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001965
1966 /* Wait to receive second echo request and send incremented Restart
1967 counter. This will fake a restarted SGSN, and pdp ctx allocated
1968 should be released by GGSN */
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06001969 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001970 T_echo.start(int2float(g_use_echo_intval) + 1.0);
1971 alt {
1972 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001973 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1974 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001975 }
1976 [] T_echo.timeout {
1977 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1978 "Timeout waiting for ping");
1979 }
1980 }
1981 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001982 f_pdp_ctx_exp_del_req(ctx, omit, true);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001983 f_shutdown_helper();
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001984 }
1985
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01001986 /* Test creation, user plane and deletion of big amount (1000) of concurrent PDP context */
1987 testcase TC_lots_of_concurrent_pdp_ctx() runs on GT_CT {
1988 var Gtp1cUnitdata udc;
1989 var Gtp1uUnitdata udu;
1990 const integer num_ctx := 1000;
1991 var PdpContext ctx[num_ctx];
1992 timer T_next := 0.01;
1993 var integer next_req_ctx := 0;
1994 var integer rx_resp_ctx := 0;
1995 var integer rx_pong := 0;
1996 var OCT4 dns1_addr;
1997 var OCT4 saddr;
1998 var integer teic;
1999 var integer idx;
2000
2001 f_init();
2002
2003 for (var integer i := 0; i < num_ctx; i := i + 1) {
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002004 ctx[i] := valueof(t_DefinePDP(f_rnd_imsi('26242'H), f_dec_TBCD(f_rnd_msisdn('1234'O)), c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002005 ctx[i].teic := int2oct(i+1, 4); /* +1: skip TEIC=0 */
2006 ctx[i].teid := int2oct(i+1, 4); /* +1: skip TEID=0 */
2007 ctx[i].pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2008 }
2009
2010 T_default.start(60.0);
2011
2012 T_next.start;
2013 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002014 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
2015 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002016 [] pingpong();
2017 [] T_next.timeout {
2018 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx[next_req_ctx].imsi, g_restart_ctr,
2019 ctx[next_req_ctx].teid, ctx[next_req_ctx].teic, ctx[next_req_ctx].nsapi,
2020 ctx[next_req_ctx].eua, ctx[next_req_ctx].apn, g_sgsn_ip_c, g_sgsn_ip_u,
2021 ctx[next_req_ctx].msisdn, ctx[next_req_ctx].pco_req, ctx[next_req_ctx].ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002022 ctx[next_req_ctx].uli, ctx[next_req_ctx].charging_char, ctx[next_req_ctx].imeisv,
2023 ctx[next_req_ctx].ms_tz));
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002024 next_req_ctx := next_req_ctx + 1;
2025 if (next_req_ctx < num_ctx) {
2026 T_next.start;
2027 }
2028 repeat;
2029 }
2030 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2031 teic := oct2int(udc.gtpc.teid);
2032 if (not match(teic, (1 .. num_ctx))) {
2033 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2034 "Rx Unexpected TEIC");
2035 }
2036 idx := teic - 1;
2037 f_handle_create_req(ctx[idx], udc);
2038 rx_resp_ctx := rx_resp_ctx + 1;
2039
2040 dns1_addr := f_PCO_extract_proto(ctx[idx].pco_neg, '000d'O);
2041 saddr := ctx[idx].eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2042 f_send_gtpu(ctx[idx], f_gen_icmpv4_echo(saddr, dns1_addr));
2043 repeat;
2044 }
2045 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value udu {
2046 var octetstring gpdu := udu.gtpu.gtpu_IEs.g_PDU_IEs.data;
2047 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
2048 if (ip4.header.ver != 4) {
2049 repeat;
2050 }
2051 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
2052 if (not match(icmp4, (tr_ICMPv4_ERP, tr_ICMPv4_DU))) {
2053 repeat;
2054 }
2055 rx_pong := rx_pong + 1;
2056 if (rx_pong < num_ctx) {
2057 repeat;
2058 }
2059 setverdict(pass);
2060 }
2061 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2062 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2063 }
2064
2065 /* Let's close them now: */
2066 next_req_ctx := 0;
2067 rx_resp_ctx := 0;
2068 T_next.start;
2069 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002070 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
2071 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002072 [] pingpong();
2073 [] T_next.timeout {
2074 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));
2075 next_req_ctx := next_req_ctx + 1;
2076 if (next_req_ctx < num_ctx) {
2077 T_next.start;
2078 }
2079 repeat;
2080 }
2081 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2082 teic := oct2int(udc.gtpc.teid);
2083 if (not match(teic, (1 .. num_ctx))) {
2084 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2085 "Rx Unexpected TEIC");
2086 }
2087 rx_resp_ctx := rx_resp_ctx + 1;
2088 if (rx_resp_ctx < num_ctx) {
2089 repeat;
2090 }
2091 setverdict(pass);
2092 }
2093 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2094 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2095 }
2096 T_next.stop;
2097
2098 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002099 f_shutdown_helper();
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002100 }
2101
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002102 /* Test callocation of PDP contexts until reaching addr pool exhaustion */
2103 type record of OCT4 TEIClist;
2104 testcase TC_addr_pool_exhaustion() runs on GT_CT {
2105 var Gtp1cUnitdata udc;
2106 var Gtp1uUnitdata udu;
2107 var PdpContext ctx;
2108 timer T_next := 0.005;
2109 var integer next_req_ctx := 0;
2110 var integer rx_resp_ctx := 0;
2111 var integer num_ctx;
2112 var boolean cont_req := true;
2113 var CreatePDPContextResponse cpr;
2114 var TEIClist teic_list := {};
2115 var integer teic;
2116
2117 f_init();
2118
2119 T_default.start(120.0);
2120
2121 T_next.start;
2122 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002123 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
2124 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002125 [] pingpong();
2126 [] T_next.timeout {
2127 if (cont_req) {
2128 if (next_req_ctx - rx_resp_ctx < 100) { /* if we have too many in progress, wait a bit to continue */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002129 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), f_dec_TBCD(f_rnd_msisdn('1234'O)), c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002130 ctx.nsapi := '0001'B;
2131 ctx.teic := int2oct(next_req_ctx+1, 4); /* +1: skip TEIC=0 */
2132 ctx.teid := int2oct(next_req_ctx+1, 4); /* +1: skip TEID=0 */
2133 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx.imsi, g_restart_ctr,
2134 ctx.teid, ctx.teic, ctx.nsapi,
2135 ctx.eua, ctx.apn, g_sgsn_ip_c, g_sgsn_ip_u,
2136 ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002137 ctx.uli, ctx.charging_char, ctx.imeisv,
2138 ctx.ms_tz));
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002139 next_req_ctx := next_req_ctx + 1;
2140 }
2141 T_next.start;
2142 }
2143 repeat;
2144 }
2145 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2146 cpr := udc.gtpc.gtpc_pdu.createPDPContextResponse;
2147
2148 if (cpr.cause.causevalue == '80'O) {
2149 teic_list := teic_list & {cpr.teidControlPlane.teidControlPlane};
2150 } else {
2151 if (cont_req == true) {
2152 num_ctx := rx_resp_ctx;
2153 log("Successfully created ", num_ctx, " PDP contexts before exhausting the pool");
2154 setverdict(pass);
2155 }
2156 cont_req := false;
2157 }
2158 rx_resp_ctx := rx_resp_ctx + 1;
2159 if (not cont_req and next_req_ctx == rx_resp_ctx) {
2160 break;
2161 } else {
2162 repeat;
2163 }
2164 }
2165 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2166 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2167 }
2168
2169 /* Let's close them now: */
2170 next_req_ctx := 0;
2171 rx_resp_ctx := 0;
2172 T_next.start;
2173 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002174 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrolcb1e8272022-04-20 14:43:43 +02002175 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002176 [] pingpong();
2177 [] T_next.timeout {
2178 f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, teic_list[next_req_ctx], '0001'B, '1'B));
2179 next_req_ctx := next_req_ctx + 1;
2180 if (next_req_ctx < num_ctx) {
2181 T_next.start;
2182 }
2183 repeat;
2184 }
2185 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2186 teic := oct2int(udc.gtpc.teid);
2187 if (not match(teic, (1 .. num_ctx))) {
2188 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2189 "Rx Unexpected TEIC");
2190 }
2191 rx_resp_ctx := rx_resp_ctx + 1;
2192 if (rx_resp_ctx < num_ctx) {
2193 repeat;
2194 }
2195 setverdict(pass);
2196 }
2197 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2198 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2199 }
2200 T_next.stop;
2201
2202 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002203 f_shutdown_helper();
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002204 }
2205
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002206 /* Test charging over Gy interface. */
2207 testcase TC_gy_charging_cc_time() runs on GT_CT {
2208 var default d;
2209
2210 g_gy_validity_time := 3; /* Grant access for 3 seconds, needs to be re-validated afterwards */
2211 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002212 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002213 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2214 f_pdp_ctx_act(ctx);
2215
2216 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2217
2218 /* Send some UL traffic: */
2219 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2220 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2221 f_wait_icmp4_echo_reply(ctx);
2222
2223 T_default.start(10.0);
2224 d := activate(pingpong());
2225
2226 g_gy_validity_time := 2;
2227 /* First update reports octests/pkt on both UL/DL (see icmp ping-pong above) */
2228 as_DIA_Gy_CCR(UPDATE_REQUEST);
2229
2230 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
2231 as_DIA_Gy_CCR(UPDATE_REQUEST);
2232
2233 /* Third update: make sure report contains again octets/pkts for both UL/DL: */
2234 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2235 f_wait_icmp4_echo_reply(ctx);
2236 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2237 f_wait_icmp4_echo_reply(ctx);
2238 as_DIA_Gy_CCR(UPDATE_REQUEST);
2239
2240 /* Let the CCA reach the GGSN */
2241 f_sleep(0.5);
2242 deactivate(d);
2243 T_default.stop;
2244
2245 /* Send some data and validate it is reported in the TERMINATION_REQUEST
2246 * (triggered by PFCP Session Deletion Response): */
2247 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2248 f_wait_icmp4_echo_reply(ctx);
2249
2250 f_pdp_ctx_del(ctx, '1'B);
2251
2252
2253 f_shutdown_helper();
2254 }
2255
Harald Welte94ade362017-08-04 00:36:55 +02002256 control {
Harald Welteed7a1772017-08-09 20:26:20 +02002257 execute(TC_pdp4_act_deact());
2258 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02002259 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02002260 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002261 execute(TC_pdp4_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002262 execute(TC_pdp4_act_deact_gtpu_access_wrong_saddr());
2263 execute(TC_pdp4_act_deact_gtpu_access_ipv6_apn4());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02002264 execute(TC_pdp4_clients_interact_with_txseq());
2265 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02002266 execute(TC_pdp4_act_deact_with_single_dns());
2267 execute(TC_pdp4_act_deact_with_separate_dns());
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01002268 execute(TC_pdp4_act_update_teic());
2269 execute(TC_pdp4_act_update_teid());
Harald Welteed7a1772017-08-09 20:26:20 +02002270
2271 execute(TC_pdp6_act_deact());
2272 execute(TC_pdp6_act_deact_pcodns());
2273 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002274 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002275 execute(TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr());
2276 execute(TC_pdp6_act_deact_gtpu_access_wrong_global_saddr());
2277 execute(TC_pdp6_act_deact_gtpu_access_ipv4_apn6());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01002278 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02002279
Oliver Smithee6a0882019-03-08 11:05:46 +01002280 execute(TC_pdp46_act_deact());
2281 execute(TC_pdp46_act_deact_ipcp());
2282 execute(TC_pdp46_act_deact_icmp6());
2283 execute(TC_pdp46_act_deact_pcodns4());
2284 execute(TC_pdp46_act_deact_pcodns6());
2285 execute(TC_pdp46_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002286 execute(TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4());
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01002287 execute(TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002288 execute(TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6());
Oliver Smithee6a0882019-03-08 11:05:46 +01002289 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002290 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01002291
Harald Weltedca80052017-08-13 20:01:38 +02002292 execute(TC_echo_req_resp());
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01002293 execute(TC_echo_req_resp_gtpu());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002294 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002295 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002296
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01002297 execute(TC_pdp_act_restart_ctr_echo());
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002298
2299 execute(TC_lots_of_concurrent_pdp_ctx());
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002300 /* Keep at the end, crashes older osmo-ggsn versions (OS#5469): */
2301 execute(TC_addr_pool_exhaustion());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002302
2303 /* open5gs specific tests: */
2304 if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
2305 execute(TC_gy_charging_cc_time());
2306 }
Harald Welte94ade362017-08-04 00:36:55 +02002307 }
Harald Welte379d45a2017-08-03 09:55:15 +02002308}