blob: c1ef7fbb40acd314b46f3cdcfaf7f5df33f3387d [file] [log] [blame]
Harald Welte379d45a2017-08-03 09:55:15 +02001module GGSN_Tests {
2
Harald Welte34b5a952019-05-27 11:54:11 +02003/* GGSN test suite in TTCN-3
4 * (C) 2017-2019 Harald Welte <laforge@gnumonks.org>
5 * (C) 2018-2019 sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
14
Harald Welte94ade362017-08-04 00:36:55 +020015 import from General_Types all;
Harald Welte811651e2017-08-05 15:25:06 +020016 import from Osmocom_Types all;
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +010017 import from Misc_Helpers all;
Harald Welte94ade362017-08-04 00:36:55 +020018 import from IPL4asp_PortType all;
19 import from IPL4asp_Types all;
20 import from GTP_CodecPort all;
21 import from GTP_CodecPort_CtrlFunct all;
Harald Weltec69cf4e2018-02-17 20:57:02 +010022 import from GTP_Templates all;
Harald Welte94ade362017-08-04 00:36:55 +020023 import from GTPC_Types all;
24 import from GTPU_Types all;
Harald Welte71a36022017-12-04 18:55:58 +010025 import from IPCP_Types all;
Harald Weltef8298542019-04-10 10:15:28 +020026 import from PAP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020027 import from IP_Types all;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +010028 import from ICMP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020029 import from ICMPv6_Types all;
Harald Welteddeecbb2017-08-18 22:53:30 +020030 import from Native_Functions all;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +020031 import from Osmocom_VTY_Functions all;
32 import from TELNETasp_PortType all;
Harald Welte94ade362017-08-04 00:36:55 +020033
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010034 import from DIAMETER_Types all;
35 import from DIAMETER_Templates all;
36 import from DIAMETER_Emulation all;
37
Harald Welte94ade362017-08-04 00:36:55 +020038 const integer GTP0_PORT := 3386;
39 const integer GTP1C_PORT := 2123;
40 const integer GTP1U_PORT := 2152;
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010041 const integer PCRF_PORT := 3868;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +010042 const integer OCS_PORT := 3869;
Harald Welteddeecbb2017-08-18 22:53:30 +020043
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010044 type enumerated GGSN_Impl {
45 GGSN_IMPL_OSMOCOM,
46 GGSN_IMPL_OPEN5GS
47 };
48
Harald Welteddeecbb2017-08-18 22:53:30 +020049 modulepar {
Stefan Sperlingcb782b92018-04-03 16:03:15 +020050 /* Default IP addresses. May be overridden by GGSN_Tests configuration files. */
51
52 /* The SGSN simulated by TTCN3 will bind to these addresses for GTP control and GTP user planes. */
Harald Welteddeecbb2017-08-18 22:53:30 +020053 charstring m_bind_ip_gtpc := "127.23.42.1";
54 charstring m_bind_ip_gtpu := "127.23.42.1";
55
Stefan Sperlingcb782b92018-04-03 16:03:15 +020056 /* Addresses the GGSN which is being tested is listening on for SGSN connections. */
Harald Welteddeecbb2017-08-18 22:53:30 +020057 charstring m_ggsn_ip_gtpc := "127.0.0.6";
58 charstring m_ggsn_ip_gtpu := "127.0.0.6";
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010059
Stefan Sperlingcb782b92018-04-03 16:03:15 +020060 /*
61 * Our tests expect to see these DNS servers in 'Create PDP context responses' sent by the GGSN.
62 * These addresses must therefore match 'ip[v6] dns' options configured in osmo-ggsn.conf.
63 *
64 * These addresses are not expected to serve actual DNS requests. However, tests may expect to be
65 * able to ping these addresses (currently, IPv4 addresses must respond with an ICMP 'echo reply',
66 * and IPv6 addresses may respond with either ICMPv6 'echo reply' or 'destination unreachable').
67 */
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010068 charstring m_ggsn_ip4_dns1 := "192.168.100.1"
69 charstring m_ggsn_ip4_dns2 := "8.8.8.8"
Pau Espin Pedrol363ba482018-01-29 18:42:00 +010070 charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888"
71 charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844"
Stefan Sperlingcb782b92018-04-03 16:03:15 +020072
73 /*
74 * Additional address ranges are defined in osmo-ggsn.conf from which addresses are assigned
75 * to MS "behind" the simulated SGSN. These addresses appear on tun devices used by osmo-ggsn.
76 * The tests expect to be able to send ping packets between any two simulated MS within the same
77 * address range. This requires IP forwarding to be enabled on the corresponding tun interfaces.
78 */
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010079
80 GGSN_Impl m_ggsn_impl := GGSN_IMPL_OSMOCOM;
Harald Welteddeecbb2017-08-18 22:53:30 +020081 }
Harald Welte94ade362017-08-04 00:36:55 +020082
Harald Welte811651e2017-08-05 15:25:06 +020083 type set PdpContext {
84 hexstring imsi,
85 octetstring msisdn optional,
86 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020087 ProtConfigOptions pco_req optional,
88 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020089 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020090 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020091 BIT4 nsapi,
92 /* TEI (Data) local side */
93 OCT4 teid,
94 /* TEI (Control) local side */
95 OCT4 teic,
96 /* TEI (Data) remote side */
97 OCT4 teid_remote,
98 /* TEI (Control) remote side */
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +010099 OCT4 teic_remote,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100100 OCT1 ratType optional,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200101 UserLocationInformation uli optional,
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200102 OCT2 charging_char optional,
103 OCT8 imeisv optional
Harald Welte811651e2017-08-05 15:25:06 +0200104 }
105
Harald Welte94ade362017-08-04 00:36:55 +0200106 type component GT_CT {
107 port GTPC_PT GTPC;
108 port GTPU_PT GTPU;
109
Harald Welte0be142b2017-08-13 13:28:10 +0200110 var boolean g_initialized := false;
111
Harald Welte94ade362017-08-04 00:36:55 +0200112 var OCT1 g_restart_ctr := '01'O;
113 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200114 var OCT4 g_sgsn_ip_c;
115 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +0200116 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200117 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
118 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200119 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200120
121 /* next to-be-sent GTP-C sequence number */
122 var uint16_t g_c_seq_nr;
123 /* next to-be-sent GTP-U sequence number */
124 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200125
126 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200127 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100128 var integer g_use_echo_intval := 0; /* 0 = disabled */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100129
130 /* emulated PCRF, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100131 var DIAMETER_Emulation_CT vc_Gx;
132 port DIAMETER_PT Gx_UNIT;
133 port DIAMETEREM_PROC_PT Gx_PROC;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100134 var DIAMETER_Emulation_CT vc_Gy;
135 port DIAMETER_PT Gy_UNIT;
136 port DIAMETEREM_PROC_PT Gy_PROC;
137 var integer g_gy_validity_time := 0; /* In seconds. 0 => disabled, !0 => grant over CC-Time period */
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200138 }
139
140 private function f_init_vty() runs on GT_CT {
141 map(self:GGSNVTY, system:GGSNVTY);
142 f_vty_set_prompts(GGSNVTY);
143 f_vty_transceive(GGSNVTY, "enable");
144 }
145
146 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
147 f_vty_enter_config(GGSNVTY);
148 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200149
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200150 f_vty_transceive(GGSNVTY, "apn internet");
151 if (enable) {
152 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
153 } else {
154 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
155 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200156 f_vty_transceive(GGSNVTY, "exit");
157
158 f_vty_transceive(GGSNVTY, "apn inet6");
159 if (enable) {
160 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
161 } else {
162 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
163 }
164 f_vty_transceive(GGSNVTY, "exit");
165
166 f_vty_transceive(GGSNVTY, "apn inet46");
167 if (enable) {
168 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
169 } else {
170 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
171 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200172 f_vty_transceive(GGSNVTY, "end");
173 }
174
175 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
176 if (expect_gptu_txseq) {
177 if (gtpu.s_bit != '1'B) {
178 log("GTPU sequence number expected but not present")
179 return false;
180 }
181 } else {
182 if (gtpu.s_bit != '0'B) {
183 log("GTPU sequence number not expected but present")
184 return false;
185 }
186 }
187 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200188 }
189
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100190 private function f_vty_enable_echo_interval(integer intval_sec) runs on GT_CT {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200191 f_vty_enter_config(GGSNVTY);
192 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100193 if (intval_sec > 0) {
194 f_vty_transceive(GGSNVTY, "echo-interval " & int2str(intval_sec));
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200195 } else {
196 f_vty_transceive(GGSNVTY, "no echo-interval");
197 }
198 f_vty_transceive(GGSNVTY, "end");
199 }
200
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100201 private function DiameterForwardUnitdataCallback(PDU_DIAMETER msg)
202 runs on DIAMETER_Emulation_CT return template PDU_DIAMETER {
203 DIAMETER_UNIT.send(msg);
204 return omit;
205 }
206
207 private function f_init_diameter(charstring id) runs on GT_CT {
208 var DIAMETEROps ops := {
209 create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback),
210 unitdata_cb := refers(DiameterForwardUnitdataCallback),
211 raw := true /* handler mode (single component for all IMSI)) */
212 };
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100213 var DIAMETER_conn_parameters pars;
214
215 /* Gx setup: */
216 pars := {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100217 remote_ip := m_ggsn_ip_gtpc,
218 remote_sctp_port := -1,
219 local_ip := m_bind_ip_gtpc,
220 local_sctp_port := PCRF_PORT,
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100221 origin_host := "pcrf.localdomain",
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100222 origin_realm := "localdomain",
Pau Espin Pedrol33b47492022-03-08 17:43:01 +0100223 auth_app_id := omit,
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100224 vendor_app_id := c_DIAMETER_3GPP_Gx_AID
225 };
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100226 vc_Gx := DIAMETER_Emulation_CT.create(id);
227 map(vc_Gx:DIAMETER, system:DIAMETER_CODEC_PT);
228 connect(vc_Gx:DIAMETER_UNIT, self:Gx_UNIT);
229 connect(vc_Gx:DIAMETER_PROC, self:Gx_PROC);
230 vc_Gx.start(DIAMETER_Emulation.main(ops, pars, id));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100231
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100232 /* Gy setup: */
233 pars := {
234 remote_ip := m_ggsn_ip_gtpc,
235 remote_sctp_port := -1,
236 local_ip := m_bind_ip_gtpc,
237 local_sctp_port := OCS_PORT,
238 origin_host := "ocs.localdomain",
239 origin_realm := "localdomain",
240 auth_app_id := c_DIAMETER_CREDIT_CONTROL_AID,
241 vendor_app_id := omit
242 };
243 vc_Gy := DIAMETER_Emulation_CT.create(id);
244 map(vc_Gy:DIAMETER, system:DIAMETER_CODEC_PT);
245 connect(vc_Gy:DIAMETER_UNIT, self:Gy_UNIT);
246 connect(vc_Gy:DIAMETER_PROC, self:Gy_PROC);
247 vc_Gy.start(DIAMETER_Emulation.main(ops, pars, id));
248
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100249 f_diameter_wait_capability(Gx_UNIT);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100250 f_diameter_wait_capability(Gy_UNIT);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100251 /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdong ping-pongs):
252 * RFC6733 sec 5.1
253 * RFC3539 sec 3.4.1 [5]
254 * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49
255 */
256 f_sleep(1.0);
257 }
258
Harald Welte94ade362017-08-04 00:36:55 +0200259 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200260 if (g_initialized == true) {
261 return;
262 }
263 g_initialized := true;
264
Harald Welteddeecbb2017-08-18 22:53:30 +0200265 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
266 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
267
Harald Welte94ade362017-08-04 00:36:55 +0200268 var Result res;
269 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +0200270 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200271 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200272 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200273
274 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +0200275 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200276 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200277
278 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200279 g_c_seq_nr := f_rnd_int(65535);
280 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200281
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100282 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
283 f_init_vty();
284 f_vty_set_gpdu_txseq(use_gtpu_txseq);
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100285 f_vty_enable_echo_interval(g_use_echo_intval);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100286 } else if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
287 f_init_diameter(testcasename());
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100288 }
Harald Welte94ade362017-08-04 00:36:55 +0200289 }
290
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100291 function f_shutdown_helper() runs on GT_CT {
292 /* Sleep N3_REQUESTS * T3_REQUEST seconds, nowadays 5*3=15s.
293 * This ensures all retransmit queues are cleared before jumping
294 * into next tests, hence avoding situation where a test resuses
295 * a seqnum still in the GGSN's resp queue (dup req detector).
296 * See OS#5485 avout decreasing time. We could also add a new
297 * VTY command that calls gtp_clear_queues() */
298 f_sleep(15.0);
299 setverdict(pass);
300 }
301
Harald Welte94ade362017-08-04 00:36:55 +0200302 /* Altstep implementing responses to any incoming echo requests */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100303 private altstep pingpong() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200304 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200305 var Gtp1uUnitdata udu;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100306 [g_use_echo_intval > 0] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200307 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200308 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200309 repeat;
310 };
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100311 [g_use_echo_intval == 0] GTPC.receive(tr_GTPC_PING(?)) {
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100312 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
313 "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200314 };
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100315 [] T_default.timeout {
316 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
317 "pinpong T_default timeout");
318 };
Harald Welte94ade362017-08-04 00:36:55 +0200319 }
320
Harald Welte811651e2017-08-05 15:25:06 +0200321 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200322 const octetstring c_ApnInternet := '08696E7465726E6574'O;
323 const octetstring c_ApnInet6 := '05696E657436'O;
324 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200325
Harald Welte811651e2017-08-05 15:25:06 +0200326 /* return random NSAPI */
327 function f_rnd_nsapi() return BIT4 {
328 return int2bit(f_rnd_int(16), 4);
329 }
330
331 /* return random TEI[DC] */
332 function f_rnd_tei() return OCT4 {
333 return int2oct(f_rnd_int(4294967296), 4);
334 }
335
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200336 /* return random IMEI(SV) */
337 function f_rnd_imeisv() return OCT8 {
338 return hex2oct(f_rnd_hexstring(16, 10));
339 }
340
Harald Welte811651e2017-08-05 15:25:06 +0200341 /* define an (internal) representation of a PDP context */
342 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100343 EndUserAddress eua, OCT1 ratType := '02'O /* GERAN */) := {
Harald Welte811651e2017-08-05 15:25:06 +0200344 imsi := imsi,
345 msisdn := msisdn,
346 nsapi := f_rnd_nsapi(),
347 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200348 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200349 eua := eua,
350 teid := f_rnd_tei(),
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100351 teic := f_rnd_tei(),
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100352 ratType := ratType,
353 uli := {
354 type_gtpc := '98'O,
355 lengthf := 0 /* filled in by encoder */,
356 geographicLocationType := '00'O /* CGI */,
357 geographicLocation := {
358 geographicLocationCGI := ts_GeographicLocationCGI('262'H, '42F'H, '0001'O, '0002'O)
359 }
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200360 },
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200361 charging_char := '0000'O,
362 imeisv := f_rnd_imeisv()
Harald Welte811651e2017-08-05 15:25:06 +0200363 }
364
365 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200366 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200367 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200368 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200369 }
370
371 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200372 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200373 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200374 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
375 g_d_seq_nr := g_d_seq_nr + 1;
376 } else {
377 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
378 }
Harald Welte811651e2017-08-05 15:25:06 +0200379 }
380
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100381 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 +0200382 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100383
384 if (not match(cpr.cause.causevalue, exp_cause)) {
385 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
386 "CreatePDPContextResp: cause expectancies didn't match");
387 }
388
389 if (cpr.cause.causevalue == '80'O) { /* Accepted */
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200390 /* Check if EUA type corresponds to requested type */
391 if (match(ctx.eua, t_EuaIPv4(?)) and
392 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100393 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
394 "EUAv4 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200395 }
396 if (match(ctx.eua, t_EuaIPv6(?)) and
397 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
399 "EUAv6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200400 }
401 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
402 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100403 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
404 "EUAv4v6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200405 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100406 } else if (cpr.cause.causevalue == '81'O) { /* Cause: New PDP type due to network preference */
407 /* ETSI TS 129 060 7.3.2 Create PDP Context Response. OS#5449 */
408 /* This should only happen if EUA requested type is v4v6: */
409 if (not ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
411 "Cause not expected when requesting a non v4v6 EUA");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200412 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100413 if (not match(cpr.endUserAddress, (tr_EuaIPv4(?), tr_EuaIPv6(?)))) {
414 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
415 "Cause not expected when requesting+receiving EUAv4v6");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200416 }
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200417 } else {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100418 if (ispresent(cpr.endUserAddress)) {
419 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
420 "EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
421 }
422 setverdict(pass);
423 return;
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200424 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100425
426 /* Check if PCO response corresponds to request */
427 if (ispresent(ctx.pco_req)) {
428 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
429 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
430 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
431 "IPv4 DNS Container requested, but missing");
432 }
433 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
434 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
435 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
436 "IPv6 DNS Container requested, but missing");
437 }
438 }
439 ctx.teid_remote := cpr.teidDataI.teidDataI;
440 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
441 ctx.eua := cpr.endUserAddress;
442 ctx.pco_neg := cpr.protConfigOptions;
443 setverdict(pass);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200444 }
445
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100446 function f_handle_update_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
447 var UpdatePDPContextResponseGGSN upr := ud.gtpc.gtpc_pdu.updatePDPContextResponse.updatePDPContextResponseGGSN;
448 if (exp_cause == '80'O and exp_cause == upr.cause.causevalue) {
449 ctx.teid_remote := upr.teidDataI.teidDataI;
450 ctx.teic_remote := upr.teidControlPlane.teidControlPlane;
451 if (ispresent(upr.protConfigOptions)) {
452 ctx.pco_neg := upr.protConfigOptions;
453 }
454 setverdict(pass);
455 } else if (exp_cause != '80'O and exp_cause == upr.cause.causevalue) {
456 setverdict(pass);
457 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100458 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
459 "UpdatePDPContextResp: cause expectancies didn't match");
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100460 }
461 }
462
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100463 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 +0100464 var PDU_DIAMETER rx_dia;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100465 [] Gx_UNIT.receive(tr_DIA_Gx_CCR(req_type := req_type)) -> value rx_dia {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100466 var template (omit) AVP avp;
467 var octetstring sess_id;
468 var AVP_Unsigned32 req_num;
469
470 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
471 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
472
473 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
474 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
475
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100476 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 +0100477 req_type, req_num));
478 }
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100479 [] Gx_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100480 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
481 log2str("Received unexpected DIAMETER ", rx_dia));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100482 }
483 }
484
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100485 private altstep as_DIA_Gy_CCR(DCC_NONE_CC_Request_Type req_type) runs on GT_CT {
486 var PDU_DIAMETER rx_dia;
487 [] Gy_UNIT.receive(tr_DIA_Gy_CCR(req_type := req_type)) -> value rx_dia {
488 var template (value) PDU_DIAMETER tx_dia;
489 var template (omit) AVP avp;
490 var octetstring sess_id;
491 var AVP_Unsigned32 req_num;
492
493 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
494 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
495
496 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
497 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
498 if (g_gy_validity_time > 0) {
499 tx_dia := ts_DIA_Gy_CCA_ValidityTime(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id,
500 req_type, req_num, g_gy_validity_time);
501 } else {
502 tx_dia := ts_DIA_Gy_CCA(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id,
503 req_type, req_num);
504 }
505 Gy_UNIT.send(tx_dia);
506 }
507 [] Gy_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
508 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
509 log2str("Received unexpected DIAMETER Gy", rx_dia));
510 }
511 }
512
Harald Welte811651e2017-08-05 15:25:06 +0200513 /* send a PDP context activation */
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100514 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 +0200515 var Gtp1cUnitdata ud;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100516 var CreatePDPContextResponse cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200517 var default d;
518
519 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200520 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 +0200521 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200522 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200523 ctx.uli, ctx.charging_char, ctx.imeisv));
Harald Welte94ade362017-08-04 00:36:55 +0200524 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200525 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100526 if (Gx_PROC.checkstate("Connected")) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100527 as_DIA_Gx_CCR(INITIAL_REQUEST);
528 }
529 if (Gy_PROC.checkstate("Connected")) {
530 as_DIA_Gy_CCR(INITIAL_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100531 }
Harald Welte94ade362017-08-04 00:36:55 +0200532 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200533 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200534 f_handle_create_req(ctx, ud, exp_cause);
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100535 cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Harald Welte94ade362017-08-04 00:36:55 +0200536 }
537 }
538 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200539 T_default.stop;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100540 return cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200541 }
542
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200543 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
544 var Gtp1cUnitdata ud;
545 var default d;
546
547 T_default.start;
548 d := activate(pingpong());
549 alt {
550 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
551 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
552 setverdict(pass);
553 } else if (not istemplatekind(expect_cause, "omit") and
554 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
555 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
556 setverdict(pass);
557 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100558 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
559 "DeletePDPContextReq: cause expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200560 }
561
562 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
563 setverdict(pass);
564 } else {
565 setverdict(fail);
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100566 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
567 "DeletePDPContextReq: tearDownIndicator expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200568 }
569 }
570 }
571 deactivate(d);
572 T_default.stop;
573 }
574
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +0100575 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 +0200576 var Gtp1cUnitdata ud;
577 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200578 var OCT4 expect_teid;
579
580 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
581 message with cause value "Non existent" shall be zero. */
582 if (expect_causevalue == 'C0'O) {
583 expect_teid := '00000000'O;
584 } else {
585 expect_teid := ctx.teic;
586 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200587
Harald Welte41575e92017-08-13 13:49:57 +0200588 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 +0200589 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200590 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100591 if (Gx_PROC.checkstate("Connected") and expect_diameter) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100592 as_DIA_Gx_CCR(TERMINATION_REQUEST);
593 }
594 if (Gy_PROC.checkstate("Connected") and expect_diameter) {
595 as_DIA_Gy_CCR(TERMINATION_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100596 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200597 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200598 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
599 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200600 setverdict(pass);
601 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100602 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
603 "DeletePDPContextResp: cause expectancies didn't match");
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200604 }
605 }
606 }
607 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200608 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200609 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100610
611 /* send a Update PdP Context Request, expect Response */
612 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 {
613 var Gtp1cUnitdata ud;
614 var default d;
615
616 if (not istemplatekind(new_teid, "omit")) {
617 ctx.teid := valueof(new_teid);
618 }
619 if (not istemplatekind(new_teic, "omit")) {
620 ctx.teic := valueof(new_teic);
621 }
622
623 log("sending UpdatePDP");
624 f_send_gtpc(ts_GTPC_UpdatePDP(g_peer_c, ctx.teic_remote, g_c_seq_nr, ctx.imsi, g_restart_ctr,
625 ctx.teid, ctx.teic, ctx.nsapi, g_sgsn_ip_c, g_sgsn_ip_u,
626 ctx.pco_req, ctx.ratType, ctx.uli));
627 T_default.start;
628 d := activate(pingpong());
629 alt {
630 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, updatePDPContextResponse, ctx.teic)) -> value ud {
631 f_handle_update_req(ctx, ud, exp_cause);
632 }
633 }
634 deactivate(d);
635 T_default.stop;
636 }
637
Harald Welte811651e2017-08-05 15:25:06 +0200638 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
639 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
640 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
641 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200642
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200643 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100644 template PDU_ICMP ts_ICMPv4_ERQ := {
645 echo := {
646 type_field := 8,
647 code := 0,
648 checksum := '0000'O,
649 identifier := '0345'O,
650 sequence_number := '0001'O,
651 data := ''O
652 }
653 }
654
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200655 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100656 template PDU_ICMP tr_ICMPv4_ERQ := {
657 echo := {
658 type_field := 8,
659 code := 0,
660 checksum := ?,
661 identifier := ?,
662 sequence_number := ?,
663 data := ?
664 }
665 }
666
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200667 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100668 template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
669 echo_reply := {
670 type_field := 0,
671 code := 0,
672 checksum := ?,
673 identifier := ?,
674 sequence_number := ?,
675 data := data
676 }
677 }
678
679 /* template for receiving/matching an ICMPv6 Destination Unreachable */
680 template PDU_ICMP tr_ICMPv4_DU := {
681 destination_unreachable := {
682 type_field := 1,
683 code := ?,
684 checksum := ?,
685 unused := ?,
686 original_ip_msg := ?
687 }
688 }
689
690 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
691 template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
692 header := {
693 ver := 4,
694 hlen := 5,
695 tos := 0,
696 tlen := tlen,
697 id := 35902,
698 res := '0'B,
699 dfrag := '1'B,
700 mfrag := '0'B,
701 foffset := 0,
702 ttl := 64,
703 proto := proto,
704 cksum := 0,
705 srcaddr := srcaddr,
706 dstaddr := dstaddr
707 },
708 ext_headers := omit,
709 payload := payload
710 }
711
Harald Welte231b9412017-08-09 17:16:31 +0200712 /* template to generate a 'Prefix Information' ICMPv6 option */
713 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
714 prefixInformation := {
715 typeField := 3,
716 lengthIndicator := 8,
717 prefixLength := prefix_len,
718 reserved1 := '000000'B,
719 a_Bit := '0'B,
720 l_Bit := '0'B,
721 validLifetime := oct2int('FFFFFFFF'O),
722 preferredLifetime := oct2int('FFFFFFFF'O),
723 reserved2 := '00000000'O,
724 prefix := prefix
725 }
726 }
727
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200728 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100729 template PDU_ICMPv6 ts_ICMPv6_ERQ := {
730 echoRequest := {
731 typeField := 128,
732 code := 0,
733 checksum := '0000'O,
734 identifier := 0,
735 sequenceNr := 0,
736 data := ''O
737 }
738 }
739
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200740 /* template for sending an ICMPv6 router solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200741 template PDU_ICMPv6 ts_ICMPv6_RS := {
742 routerSolicitation := {
743 typeField := 133,
744 code := 0,
745 checksum := '0000'O,
746 reserved := '00000000'O,
747 /* TODO: do we need 'Source link-layer address' ? */
748 options := omit
749 }
750 }
751
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200752 /* template for sending an ICMPv6 router advertisement */
Harald Welte231b9412017-08-09 17:16:31 +0200753 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
754 routerAdvertisement := {
755 typeField := 134,
756 code := 0,
757 checksum := '0000'O,
758 curHopLimit := ?,
759 reserved := '000000'B,
760 o_Bit := '0'B,
761 m_Bit := '0'B,
762 routerLifetime := oct2int('FFFF'O),
763 reachableTime := oct2int('FFFFFFFF'O),
764 retransTimer := oct2int('FFFFFFFF'O),
765 options := {
766 ts_ICMP6_OptPrefix(prefix, prefix_len)
767 }
768 }
769 }
770
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200771 /* template for sending an ICMPv6 neighbor solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200772 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
773 neighborSolicitation := {
774 typeField := 135,
775 code := 0,
776 checksum := '0000'O,
777 reserved := '00000000'O,
778 targetAddress := target_addr,
779 /* TODO: do we need 'Source link-layer address' ? */
780 options := omit
781 }
782 }
783
784 /* derive ICMPv6 link-local address from lower 64bit of link_id */
785 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
786 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
787 prefixInformation := {
788 typeField := 3,
789 lengthIndicator := 4,
790 prefixLength := prefix_len,
791 reserved1 := ?,
792 a_Bit := ?,
793 l_Bit := ?,
794 validLifetime := ?,
795 preferredLifetime := ?,
796 reserved2 := ?,
797 prefix := prefix
798 }
799 }
800
801 /* template for receiving/matching an ICMPv6 router advertisement */
802 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
803 routerAdvertisement := {
804 typeField := 134,
805 code := 0,
806 checksum := ?,
807 curHopLimit := ?,
808 reserved := ?,
809 o_Bit := '0'B,
810 m_Bit := '0'B,
811 routerLifetime := ?,
812 reachableTime := ?,
813 retransTimer := ?,
814 options := {
815 tr_ICMP6_OptPrefix(prefix, prefix_len)
816 }
817 }
818 }
819
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100820 /* template for receiving/matching an ICMPv6 Destination Unreachable */
821 template PDU_ICMPv6 tr_ICMPv6_DU := {
822 destinationUnreachable := {
823 typeField := 1,
824 code := ?,
825 checksum := ?,
826 unused := ?,
827 originalIpMsg := ?
828 }
829 }
830
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200831 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100832 template PDU_ICMPv6 tr_ICMPv6_ERQ := {
833 echoRequest := {
834 typeField := 128,
835 code := 0,
836 checksum := ?,
837 identifier := ?,
838 sequenceNr := ?,
839 data := ?
840 }
841 }
842
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100843 /* template for receiving/matching an ICMPv6 echo reply */
844 template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
845 echoReply := {
846 typeField := 129,
847 code := 0,
848 checksum := ?,
849 identifier := ?,
850 sequenceNr := ?,
851 data := data
852 }
853 }
854
Harald Welte231b9412017-08-09 17:16:31 +0200855 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
856 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
857 header := {
858 ver := 6,
859 trclass := 0,
860 flabel := 0,
861 plen := 0,
862 nexthead := nexthead,
863 hlim := hlim,
864 srcaddr := srcaddr,
865 dstaddr := dstaddr
866 },
867 ext_headers := omit,
868 payload := payload
869 }
870
871 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
872 return 'FE80000000000000'O & substr(link_id, 8, 8);
873 }
874
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100875 function f_ipv6_global(in OCT16 link_id) return OCT16 {
876 return substr(link_id, 0, 8) & '1234123412341234'O;
877 }
878
879 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
880 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
881 var integer i;
882 var octetstring res := substr(addr, 0, prefix);
883 for (i := prefix; i < lengthof(addr); i := i + 1) {
884 var octetstring a := addr[i] xor4b '11'O;
885 res := res & a;
886 }
887 return res;
888 }
889
Harald Welte231b9412017-08-09 17:16:31 +0200890 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
891 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
892 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
893 }
894
895 /* generate and encode ICMPv6 router solicitation */
896 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
897 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
898 var OCT16 saddr := f_ipv6_link_local(link_id);
899
900 var octetstring tmp;
901 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
902 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
903
904 return f_IPv6_enc(ip6);
905 }
906
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100907 /* Get link-id from PDP Context EUA */
908 function f_ctx_get_ipv6_interface_id(in PdpContext ctx) return OCT16 {
909 var OCT16 interface_id;
910 if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
911 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
912 } else if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv6)) {
913 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
914 } else {
915 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected request to submit icmpv6 rs in IPv4 PDP context");
916 }
917 return interface_id;
918 }
919
Harald Welte231b9412017-08-09 17:16:31 +0200920 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
921 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100922 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200923 return f_gen_icmpv6_router_solicitation(interface_id);
924 }
925
926 /* generate and encode ICMPv6 neighbor solicitation */
927 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
928 var octetstring tmp;
929 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
930 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
931 return f_IPv6_enc(ip6);
932 }
933
934 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
935 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100936 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200937 var OCT16 link_local := f_ipv6_link_local(interface_id);
938 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
939
940 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
941 }
942
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100943 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
944 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring {
945 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ));
946 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
947 var octetstring data := f_IPv4_enc(ip4);
948 var OCT2 cksum := f_IPv4_checksum(data);
949 data[10] := cksum[0];
950 data[11] := cksum[1];
951 return data;
952 }
953
954 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
955 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
956 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
957 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
958 var octetstring data := f_IPv6_enc(ip6);
959 return data;
960 }
961
962 /* Wait for ICMPv4 from GTP */
963 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +0200964 var Gtp1uUnitdata ud;
965 T_default.start;
966 alt {
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100967 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ctx.teid)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200968 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200969 setverdict(fail);
970 stop;
971 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100972 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
973 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
974 if (ip4.header.ver != 4) {
975 repeat;
976 }
977 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
978 if (not match(icmp4, expected)) {
979 repeat;
980 }
981 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100982 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
983 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
984 "Received wrong local TEID");
985 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100986 [] GTPU.receive { setverdict(fail); }
987 [] T_default.timeout { setverdict(fail); }
988 }
989 T_default.stop;
990 }
991
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100992 /* Wait for ICMPv4 echo request from GTP */
993 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
994 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
995 }
996
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100997 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
998 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
999 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
1000 }
1001
1002 /* Wait for ICMPv6 from GTP */
1003 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
1004 var Gtp1uUnitdata ud;
1005 T_default.start;
1006 alt {
Harald Welte231b9412017-08-09 17:16:31 +02001007 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +02001008 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001009 setverdict(fail);
1010 stop;
1011 }
Harald Welte231b9412017-08-09 17:16:31 +02001012 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1013 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001014 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +02001015 repeat;
1016 }
1017 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001018 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +02001019 repeat;
1020 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001021 /* We are waiting for RA, update ctx */
1022 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
1023 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
1024 log("RA with /64 prefix ", ctx.ip6_prefix);
1025 }
Harald Welte231b9412017-08-09 17:16:31 +02001026 }
1027 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
1028 [] GTPU.receive { setverdict(fail); }
1029 [] T_default.timeout { setverdict(fail); }
1030 }
1031 T_default.stop;
1032 }
1033
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001034 /* wait for GGSN to send us an ICMPv6 router advertisement */
1035 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
1036 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
1037 }
1038
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001039 /* Wait for ICMPv6 echo request from GTP */
1040 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
1041 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
1042 }
1043
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001044 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
1045 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
1046 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
1047 }
1048
Oliver Smithee6a0882019-03-08 11:05:46 +01001049 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
1050 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
1051 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1052 return f_gen_icmpv6_router_solicitation(interface_id);
1053 }
1054
1055 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
1056 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
1057 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1058 var OCT16 link_local := f_ipv6_link_local(interface_id);
1059 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
1060
1061 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
1062 }
1063
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001064 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
1065 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
1066 T_default.start;
1067 alt {
1068 [] GTPU.receive { setverdict(fail); }
1069 [] T_default.timeout { }
1070 }
1071 T_default.stop;
1072 }
1073
Harald Welte79737b42019-04-10 10:39:30 +02001074 /* list of protocols where we don't accept duplicates */
1075 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
1076 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
1077 var integer i;
1078 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
1079 if (id == protocol_ids_nodupes[i]) {
1080 return false;
1081 }
1082 }
1083 return true;
1084 }
1085
1086 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
1087 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
1088 var OCT2List protocol_ids := {};
1089 var integer i, j;
1090 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
1091 var OCT2 id := pco.protocols[i].protocolID;
1092 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
1093 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
1094 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
1095 }
1096 }
1097 protocol_ids := protocol_ids & { id };
1098 }
1099 }
1100
Harald Welte0ef285b2017-08-13 20:06:01 +02001101 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +02001102 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +02001103 f_init();
Harald Welte231b9412017-08-09 17:16:31 +02001104
Harald Welteed097432017-08-13 13:28:49 +02001105 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welte811651e2017-08-05 15:25:06 +02001106 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +02001107 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001108 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001109 }
1110
Harald Welte0ef285b2017-08-13 20:06:01 +02001111 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001112 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
1113 f_init();
1114
Harald Welteed097432017-08-13 13:28:49 +02001115 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001116 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1117 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001118
Harald Welte79737b42019-04-10 10:39:30 +02001119 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001120 /* verify PCO contains both primary and secondary DNS */
1121 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1122 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1123 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1124 }
1125
1126 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1127 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1128 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1129 }
1130
Harald Welteed7a1772017-08-09 20:26:20 +02001131 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001132 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001133 }
1134
Harald Welte0ef285b2017-08-13 20:06:01 +02001135 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +02001136 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
1137 f_init();
1138
Harald Welteed097432017-08-13 13:28:49 +02001139 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001140 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1141 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001142
Harald Welte79737b42019-04-10 10:39:30 +02001143 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +02001144 //f_send_gtpu(ctx, c_router_solicit);
1145 //f_send_gtpu(ctx, c_neigh_solicit);
1146
1147 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1148 f_wait_rtr_adv(ctx);
1149 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1150
Harald Welte811651e2017-08-05 15:25:06 +02001151 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001152 f_shutdown_helper();
Harald Welte94ade362017-08-04 00:36:55 +02001153 }
1154
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001155 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
1156 Test we can send ICMPv6 ping over GTPU to DNS server. */
1157 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
1158 f_init();
1159 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1160 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1161 f_pdp_ctx_act(ctx);
1162
1163 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1164 f_wait_rtr_adv(ctx);
1165 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1166
1167 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1168
1169 /* Check if we can use valid link-local src addr. */
1170 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1171 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
Pau Espin Pedrolb63d85f2022-02-07 16:11:47 +01001172 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
1173 f_wait_icmp6_echo_reply(ctx);
1174 } else {
1175 f_wait_gtpu_fail(ctx);
1176 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001177
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001178 /* Check if we can use valid global src addr, should work */
1179 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1180 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
1181 f_wait_icmp6_echo_reply(ctx);
1182
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001183 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001184 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001185 }
1186
1187 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1188 testcase TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr() runs on GT_CT {
1189 f_init();
1190 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1191 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1192 f_pdp_ctx_act(ctx);
1193
1194 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1195 f_wait_rtr_adv(ctx);
1196 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1197
1198 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1199 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1200 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1201 f_wait_gtpu_fail(ctx);
1202
1203 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001204 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001205 }
1206
1207 /* Assert that packets with wrong global src addr are dropped by GGSN */
1208 testcase TC_pdp6_act_deact_gtpu_access_wrong_global_saddr() runs on GT_CT {
1209 f_init();
1210 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1211 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1212 f_pdp_ctx_act(ctx);
1213
1214 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1215 f_wait_rtr_adv(ctx);
1216 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1217
1218 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1219 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001220 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1221 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
1222 f_wait_gtpu_fail(ctx);
1223
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001224 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001225 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001226 }
1227
1228 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped */
1229 testcase TC_pdp6_act_deact_gtpu_access_ipv4_apn6() runs on GT_CT {
1230 f_init();
1231 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1232 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1233 f_pdp_ctx_act(ctx);
1234
1235 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1236 f_wait_rtr_adv(ctx);
1237 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1238
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001239 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
1240 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
1241 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
1242 f_wait_gtpu_fail(ctx);
1243
1244 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001245 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001246 }
1247
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001248 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1249 testcase TC_pdp6_clients_interact() runs on GT_CT {
1250 f_init();
1251 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1252 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1253 f_pdp_ctx_act(ctxA);
1254 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
1255 f_wait_rtr_adv(ctxA);
1256 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
1257
1258 f_pdp_ctx_act(ctxB);
1259 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
1260 f_wait_rtr_adv(ctxB);
1261 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
1262
1263 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1264 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1265 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1266 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1267
1268 /* Validate if clients can interact using ll addr. */
1269 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1270 f_wait_gtpu_fail(ctxB);
1271
1272 /* Validate if clients can interact using global addr. */
1273 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1274 f_wait_gtpu_fail(ctxB);
1275
1276 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001277 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001278 f_shutdown_helper();
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001279 }
1280
Harald Welte0ef285b2017-08-13 20:06:01 +02001281 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +02001282 testcase TC_pdp4_act_deact() runs on GT_CT {
1283 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001284 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001285 f_pdp_ctx_act(ctx);
1286 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001287 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001288 }
1289
Harald Welte0ef285b2017-08-13 20:06:01 +02001290 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +02001291 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
1292 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001293 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1294 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +02001295 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001296 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +02001297 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001298 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +01001299 /* verify IPCP is at all contained */
1300 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1301 setverdict(fail, "IPCP not found in PCO");
1302 }
1303 /* verify IPCP contains both primary and secondary DNS */
1304 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001305 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1306 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1307 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1308 } else {
1309 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1310 }
Harald Welte71a36022017-12-04 18:55:58 +01001311 }
Harald Welteed7a1772017-08-09 20:26:20 +02001312 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001313 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001314 }
1315
Harald Weltef8298542019-04-10 10:15:28 +02001316 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
1317 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
1318 f_init();
1319 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1320 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1321 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1322 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1323 f_pdp_ctx_act(ctx);
1324 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1325 /* verify IPCP is at all contained */
1326 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1327 setverdict(fail, "IPCP not found in PCO");
1328 }
1329 /* verify IPCP contains both primary and secondary DNS */
1330 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1331 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1332 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1333 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1334 } else {
1335 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1336 }
1337 }
1338 /* verify that PAP is contained */
1339 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1340 setverdict(fail, "PAP not found in PCO");
1341 }
1342 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1343 if (not match(pap, tr_PAP_AuthAck)) {
1344 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1345 }
1346 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001347 f_shutdown_helper();
Harald Weltef8298542019-04-10 10:15:28 +02001348 }
1349
Harald Welte0ef285b2017-08-13 20:06:01 +02001350 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001351 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1352 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001353 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001354 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001355 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001356
Harald Welte79737b42019-04-10 10:39:30 +02001357 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001358 /* verify PCO contains both primary and secondary DNS */
1359 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1360 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1361 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1362 }
1363
1364 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1365 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1366 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1367 }
1368
Harald Welteed7a1772017-08-09 20:26:20 +02001369 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001370 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001371 }
1372
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001373 /* Test PDP context activation for dynamic IPv4 EUA.
1374 Test we can send ICMPv6 ping over GTPU to DNS server. */
1375 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1376 f_init();
1377 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1378 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1379 f_pdp_ctx_act(ctx);
1380
Harald Welte79737b42019-04-10 10:39:30 +02001381 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001382 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1383
1384 /* Check if we can use valid global src addr, should work */
1385 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1386 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1387 f_wait_icmp4_echo_reply(ctx);
1388
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001389 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001390 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001391 }
1392
1393 /* Assert that packets with wrong global src addr are dropped by GGSN */
1394 testcase TC_pdp4_act_deact_gtpu_access_wrong_saddr() runs on GT_CT {
1395 f_init();
1396 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1397 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1398 f_pdp_ctx_act(ctx);
1399
1400 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1401 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1402 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001403 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1404 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1405 f_wait_gtpu_fail(ctx);
1406
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001407 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001408 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001409 }
1410
1411 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1412 testcase TC_pdp4_act_deact_gtpu_access_ipv6_apn4() runs on GT_CT {
1413 f_init();
1414 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1415 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1416 f_pdp_ctx_act(ctx);
1417
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001418 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1419 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1420 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1421 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001422
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001423 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001424 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001425 }
1426
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001427 /* Helper function for tests below. */
1428 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001429 f_init();
1430 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1431 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1432 f_pdp_ctx_act(ctxA);
1433 f_pdp_ctx_act(ctxB);
1434 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1435 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1436 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1437 f_wait_icmp4_echo_request(ctxB);
1438
1439 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001440 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001441 }
1442
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001443 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1444 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001445 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001446 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001447 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001448 }
1449
1450 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1451 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001452 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001453 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001454 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001455 }
1456
Harald Weltedca80052017-08-13 20:01:38 +02001457 testcase TC_echo_req_resp() runs on GT_CT {
1458 f_init();
1459 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1460 T_default.start;
1461 alt {
1462 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1463 [] GTPC.receive { repeat; };
1464 [] T_default.timeout { setverdict(fail); }
1465 }
1466 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001467 f_shutdown_helper();
Harald Weltedca80052017-08-13 20:01:38 +02001468 }
1469
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001470 testcase TC_echo_req_resp_gtpu() runs on GT_CT {
1471 f_init();
1472 GTPU.send(ts_GTPU_PING(g_peer_u, g_d_seq_nr));
1473 T_default.start;
1474 alt {
1475 [] GTPU.receive(tr_GTPU_PONG(g_peer_u)) { setverdict(pass); };
1476 [] GTPU.receive { repeat; };
1477 [] T_default.timeout { setverdict(fail); }
1478 }
1479 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001480 f_shutdown_helper();
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001481 }
1482
Philipp Maier33e52612018-05-30 17:22:02 +02001483 /* Test if the parser can cope with PCO that only contain either a
1484 * single primary DNS or a secondary DNS. */
1485 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1486
1487 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1488 * the test is executed.
1489 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1490
1491 f_init();
1492 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1493 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1494 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1495 var octetstring pco_neg_dns;
1496 var octetstring pco_neg_dns_expected;
1497
1498 /* PCO with primary DNS only */
1499 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1500 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001501 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001502 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1503 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1504 /* Note: The prepended hex bytes encode the following information:
1505 * 0x02 = Configuration ACK
1506 * 0x00 = Identifier
1507 * 0x000a = Length
1508 * 0x81 = Type (Primary DNS Server Address)
1509 * 0x06 = Length
1510 * (4 byte IP-Address appended) */
1511 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1512 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1513 }
1514 f_pdp_ctx_del(ctx, '1'B);
1515
1516 /* PCO with secondary DNS only */
Harald Welte7ef6d102021-04-01 21:24:35 +02001517 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001518 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1519 f_pdp_ctx_act(ctx);
1520 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1521 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1522 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1523 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1524 }
1525 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001526 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001527 }
1528
1529 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1530 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1531 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1532 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1533
1534 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1535 * the test is executed.
1536 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1537
1538 f_init();
1539 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1540 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1541 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1542 var octetstring pco_neg_dns;
1543 var octetstring pco_neg_dns_expected;
1544
1545 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1546 f_pdp_ctx_act(ctx);
1547
1548 /* Check if primary DNS is contained */
1549 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1550 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1551 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1552 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1553 }
Philipp Maier33e52612018-05-30 17:22:02 +02001554
1555 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001556 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1557 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001558 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1559 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1560 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1561 }
1562 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001563 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001564 }
1565
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001566 /* Validate that SUT updates remote TEIC when requested through UpdatePDPContextRequest */
1567 testcase TC_pdp4_act_update_teic() runs on GT_CT {
1568 f_init();
1569 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1570 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1571 f_pdp_ctx_act(ctx);
1572
1573 /* UpdatePDPContestRequest changing the local TEIC */
1574 var OCT4 new_teic := ctx.teic;
1575 new_teic[3] := new_teic[3] xor4b '11'O;
1576 f_pdp_ctx_update(ctx, new_teic := new_teic);
1577
1578 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001579 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001580 }
1581
1582 /* Validate that SUT updates remote TEID when requested through UpdatePDPContextRequest */
1583 testcase TC_pdp4_act_update_teid() runs on GT_CT {
1584 f_init();
1585 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1586 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1587 f_pdp_ctx_act(ctx);
1588
1589 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1590 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1591 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1592
1593 /* Data is sent (back) to the local TEID established during CreatePDPContext */
1594 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1595 f_wait_icmp4_echo_reply(ctx);
1596
1597 /* UpdatePDPContestRequest changing the local TEID */
1598 var OCT4 new_teid := ctx.teid;
1599 new_teid[3] := new_teid[3] xor4b '11'O;
1600 f_pdp_ctx_update(ctx, new_teid := new_teid);
1601
1602 /* Check if we can send data after updating the PDP context. Answer should be sent to the new TEID */
1603 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1604 f_wait_icmp4_echo_reply(ctx);
1605
1606 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001607 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001608 }
1609
Oliver Smithee6a0882019-03-08 11:05:46 +01001610 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1611 testcase TC_pdp46_act_deact() runs on GT_CT {
1612 f_init();
1613 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1614 f_pdp_ctx_act(ctx);
1615 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001616 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001617 }
1618
1619 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1620 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1621 f_init();
1622 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1623 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1624 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1625 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1626 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001627 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001628 /* verify IPCP is at all contained */
1629 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1630 setverdict(fail, "IPCP not found in PCO");
1631 }
Harald Welte79737b42019-04-10 10:39:30 +02001632 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001633 /* verify IPCP contains both primary and secondary IPv4 DNS */
1634 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1635 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1636 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1637 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1638 } else {
1639 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1640 }
1641 }
1642 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001643 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001644 }
1645
1646 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1647 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1648 f_init();
1649 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1650 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1651 f_pdp_ctx_act(ctx);
1652
1653 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1654 f_wait_rtr_adv(ctx);
1655 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1656
1657 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001658 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001659 }
1660
1661 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1662 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1663 f_init();
1664
1665 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1666 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1667 f_pdp_ctx_act(ctx);
1668
Harald Welte79737b42019-04-10 10:39:30 +02001669 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001670 /* verify PCO contains both primary and secondary IPv4 DNS */
1671 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1672 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1673 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1674 }
1675
1676 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1677 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1678 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1679 }
1680
1681 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001682 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001683 }
1684
1685 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1686 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1687 f_init();
1688
1689 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1690 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1691 f_pdp_ctx_act(ctx);
1692
Harald Welte79737b42019-04-10 10:39:30 +02001693 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001694 /* verify PCO contains both primary and secondary IPv6 DNS */
1695 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1696 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1697 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1698 }
1699
1700 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1701 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1702 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1703 }
1704
1705 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001706 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001707 }
1708
1709 /* Test PDP context activation for dynamic IPv4v6 EUA.
1710 Test we can send ICMPv6 ping over GTPU to DNS server. */
1711 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1712 f_init();
1713 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1714 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1715 f_pdp_ctx_act(ctx);
1716
1717 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1718
1719 /* Check if we can use valid global src addr, should work */
1720 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1721 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1722 f_wait_icmp4_echo_reply(ctx);
1723
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001724 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001725 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001726 }
1727
1728 /* Assert that packets with wrong ipv4 src addr are dropped by GGSN on APN IPv4v6 */
1729 testcase TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4() runs on GT_CT {
1730 f_init();
1731 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1732 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1733 f_pdp_ctx_act(ctx);
1734
1735 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1736 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
Oliver Smithee6a0882019-03-08 11:05:46 +01001737 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1738 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1739 f_wait_gtpu_fail(ctx);
1740
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001741 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001742 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001743 }
1744
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001745 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1746 testcase TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6() runs on GT_CT {
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001747 f_init();
1748 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1749 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1750 f_pdp_ctx_act(ctx);
1751
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001752 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1753 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1754 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1755 f_wait_gtpu_fail(ctx);
1756
1757 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001758 f_shutdown_helper();
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001759 }
1760
1761 /* Assert that packets with wrong ipv6 global src addr are dropped by GGSN on APN IPv4v6 */
1762 testcase TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6() runs on GT_CT {
1763 f_init();
1764 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1765 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1766 f_pdp_ctx_act(ctx);
1767
1768 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1769 f_wait_rtr_adv(ctx);
1770 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1771
1772 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1773 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1774 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1775 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
Oliver Smithee6a0882019-03-08 11:05:46 +01001776 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001777
Oliver Smithee6a0882019-03-08 11:05:46 +01001778 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001779 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001780 }
1781
1782 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1783 testcase TC_pdp46_clients_interact() runs on GT_CT {
1784 f_init();
1785 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1786 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1787 f_pdp_ctx_act(ctxA);
1788 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1789 f_wait_rtr_adv(ctxA);
1790 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1791
1792 f_pdp_ctx_act(ctxB);
1793 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1794 f_wait_rtr_adv(ctxB);
1795 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1796
1797 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1798 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1799 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1800 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1801
1802 /* Validate if clients can interact using ll addr. */
1803 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1804 f_wait_gtpu_fail(ctxB);
1805
1806 /* Validate if clients can interact using global addr. */
1807 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1808 f_wait_gtpu_fail(ctxB);
1809
1810 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001811 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001812 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001813 }
1814
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001815 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
1816 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001817 const OCT1 cause_accept := '80'O; /* Normal accept cause */
1818 const OCT1 cause_new_pdp_type := '81'O; /* Cause: New PDP type due to network preference */
1819 const OCT1 cause_unknown_pdp := 'DC'O; /* Cause: Unknown PDP address or PDP type */
1820 var CreatePDPContextResponse cpr;
1821
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001822 f_init();
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001823 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001824 cpr := f_pdp_ctx_act(ctx46, (cause_unknown_pdp, cause_new_pdp_type));
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001825
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001826 if (cpr.cause.causevalue == cause_new_pdp_type) {
1827 /* 3GPP TS 23.060 sec 9.2.1: "If the MS requests PDP type IPv4v6,
1828 * but the operator preferences dictate the use of a single IP
1829 * version only, the PDP type shall be changed to a single address
1830 * PDP type (IPv4 or IPv6) and a reason cause shall be returned to
1831 * the MS indicating that only the assigned PDP type is allowed. In
1832 * this case, the MS shall not request another PDP context for the
1833 * other PDP type during the existence of the PDP context." */
1834 f_pdp_ctx_del(ctx46, '1'B);
1835 } else {
1836 /* 3GPP TS 23.060 sec 9.2.1 NOTE 5: If the MS requests PDP type
1837 * IPv4v6, and the PDP context is rejected due to "unknown PDP
1838 * type", the MS can attempt to establish dual-stack connectivity
1839 * by performing two PDP context request procedures to activate an
1840 * IPv4 PDP context and an IPv6 PDP context, both to the same APN. A
1841 * typical MS first attempts v4v6, and if rejected, then tries v4
1842 * and v6 separetly */
1843 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1844 f_pdp_ctx_act(ctx4, cause_accept); /* Normal accept cause */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001845
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001846 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv6Dyn)));
1847 f_pdp_ctx_act(ctx6, cause_unknown_pdp); /* Cause: Unknown PDP address or PDP type */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001848
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001849 f_pdp_ctx_del(ctx4, '1'B);
1850 }
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001851 f_shutdown_helper();
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001852 }
1853
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001854 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
1855 testcase TC_pdp_act2_recovery() runs on GT_CT {
1856 var Gtp1cUnitdata ud;
1857 var default d;
1858 var boolean ctxA_deleted := false;
1859 var boolean ctxB_created := false;
1860
1861 f_init();
1862 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1863 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1864 f_pdp_ctx_act(ctxA);
1865
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06001866 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001867
1868 log("sending 2nd CreatePDP (recovery increased)");
1869 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
1870 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
1871 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
1872 T_default.start;
1873 d := activate(pingpong());
1874 alt {
1875 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
1876 f_handle_create_req(ctxB, ud);
1877 if (not ctxB_created) {
1878 ctxB_created := true;
1879 setverdict(pass);
1880 } else {
1881 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
1882 }
1883
1884 if (not ctxA_deleted) {
1885 repeat;
1886 }
1887 }
1888 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
1889 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
1890 setverdict(pass);
1891 } else {
1892 setverdict(fail);
1893 }
1894
1895 if (not ctxA_deleted) {
1896 ctxA_deleted := true;
1897 setverdict(pass);
1898 } else {
1899 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
1900 }
1901
1902 if (not ctxB_created) {
1903 repeat;
1904 }
1905 }
1906 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
1907 setverdict(fail, "GGSN dropping still valid pdp ctx");
1908 }
1909 }
1910 deactivate(d);
1911 T_default.stop;
1912
1913 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001914 f_shutdown_helper();
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001915 }
1916
1917
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001918 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent
1919 responses (60 seconds): If same delete req is sent and duplicate is
1920 detected, saved duplicate response should be sent back. */
1921 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
1922 f_init();
1923 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1924 f_pdp_ctx_act(ctx);
1925 f_pdp_ctx_del(ctx, '1'B);
1926 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
1927 f_sleep(1.0);
1928 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
1929 duplicate. If it was not a duplicate, osmo-ggsn would answer
1930 with a failure since that PDP ctx was already deleted. */
1931 g_c_seq_nr := g_c_seq_nr - 1;
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01001932 f_pdp_ctx_del(ctx, '1'B, expect_diameter := false);
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001933
1934 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
1935 var OCT1 cause_nonexistent := 'C0'O;
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01001936 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent, expect_diameter := false);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001937 f_shutdown_helper();
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001938 }
1939
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001940 /* Activate PDP context + trigger Recovery procedure through EchoResp */
1941 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
1942 var Gtp1cUnitdata ud;
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001943 g_use_echo_intval := 5;
1944 timer T_echo;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001945 f_init();
1946 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1947 f_pdp_ctx_act(ctx);
1948
1949 /* Wait to receive echo request and send initial Restart counter */
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001950 T_echo.start(int2float(g_use_echo_intval) + 1.0);
1951 alt {
1952 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001953 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1954 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001955 }
1956 [] T_echo.timeout {
1957 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1958 "Timeout waiting for ping");
1959 }
1960 }
1961 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001962
1963 /* Wait to receive second echo request and send incremented Restart
1964 counter. This will fake a restarted SGSN, and pdp ctx allocated
1965 should be released by GGSN */
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06001966 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001967 T_echo.start(int2float(g_use_echo_intval) + 1.0);
1968 alt {
1969 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001970 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1971 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001972 }
1973 [] T_echo.timeout {
1974 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1975 "Timeout waiting for ping");
1976 }
1977 }
1978 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001979 f_pdp_ctx_exp_del_req(ctx, omit, true);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001980 f_shutdown_helper();
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001981 }
1982
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01001983 /* Test creation, user plane and deletion of big amount (1000) of concurrent PDP context */
1984 testcase TC_lots_of_concurrent_pdp_ctx() runs on GT_CT {
1985 var Gtp1cUnitdata udc;
1986 var Gtp1uUnitdata udu;
1987 const integer num_ctx := 1000;
1988 var PdpContext ctx[num_ctx];
1989 timer T_next := 0.01;
1990 var integer next_req_ctx := 0;
1991 var integer rx_resp_ctx := 0;
1992 var integer rx_pong := 0;
1993 var OCT4 dns1_addr;
1994 var OCT4 saddr;
1995 var integer teic;
1996 var integer idx;
1997
1998 f_init();
1999
2000 for (var integer i := 0; i < num_ctx; i := i + 1) {
2001 ctx[i] := valueof(t_DefinePDP(f_rnd_imsi('26242'H), f_rnd_msisdn('1234'O), c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2002 ctx[i].teic := int2oct(i+1, 4); /* +1: skip TEIC=0 */
2003 ctx[i].teid := int2oct(i+1, 4); /* +1: skip TEID=0 */
2004 ctx[i].pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2005 }
2006
2007 T_default.start(60.0);
2008
2009 T_next.start;
2010 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002011 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
2012 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002013 [] pingpong();
2014 [] T_next.timeout {
2015 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx[next_req_ctx].imsi, g_restart_ctr,
2016 ctx[next_req_ctx].teid, ctx[next_req_ctx].teic, ctx[next_req_ctx].nsapi,
2017 ctx[next_req_ctx].eua, ctx[next_req_ctx].apn, g_sgsn_ip_c, g_sgsn_ip_u,
2018 ctx[next_req_ctx].msisdn, ctx[next_req_ctx].pco_req, ctx[next_req_ctx].ratType,
Pau Espin Pedrol38968e92022-05-13 16:17:48 +02002019 ctx[next_req_ctx].uli, ctx[next_req_ctx].charging_char, ctx[next_req_ctx].imeisv));
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002020 next_req_ctx := next_req_ctx + 1;
2021 if (next_req_ctx < num_ctx) {
2022 T_next.start;
2023 }
2024 repeat;
2025 }
2026 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2027 teic := oct2int(udc.gtpc.teid);
2028 if (not match(teic, (1 .. num_ctx))) {
2029 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2030 "Rx Unexpected TEIC");
2031 }
2032 idx := teic - 1;
2033 f_handle_create_req(ctx[idx], udc);
2034 rx_resp_ctx := rx_resp_ctx + 1;
2035
2036 dns1_addr := f_PCO_extract_proto(ctx[idx].pco_neg, '000d'O);
2037 saddr := ctx[idx].eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2038 f_send_gtpu(ctx[idx], f_gen_icmpv4_echo(saddr, dns1_addr));
2039 repeat;
2040 }
2041 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value udu {
2042 var octetstring gpdu := udu.gtpu.gtpu_IEs.g_PDU_IEs.data;
2043 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
2044 if (ip4.header.ver != 4) {
2045 repeat;
2046 }
2047 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
2048 if (not match(icmp4, (tr_ICMPv4_ERP, tr_ICMPv4_DU))) {
2049 repeat;
2050 }
2051 rx_pong := rx_pong + 1;
2052 if (rx_pong < num_ctx) {
2053 repeat;
2054 }
2055 setverdict(pass);
2056 }
2057 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2058 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2059 }
2060
2061 /* Let's close them now: */
2062 next_req_ctx := 0;
2063 rx_resp_ctx := 0;
2064 T_next.start;
2065 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002066 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
2067 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002068 [] pingpong();
2069 [] T_next.timeout {
2070 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));
2071 next_req_ctx := next_req_ctx + 1;
2072 if (next_req_ctx < num_ctx) {
2073 T_next.start;
2074 }
2075 repeat;
2076 }
2077 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2078 teic := oct2int(udc.gtpc.teid);
2079 if (not match(teic, (1 .. num_ctx))) {
2080 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2081 "Rx Unexpected TEIC");
2082 }
2083 rx_resp_ctx := rx_resp_ctx + 1;
2084 if (rx_resp_ctx < num_ctx) {
2085 repeat;
2086 }
2087 setverdict(pass);
2088 }
2089 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2090 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2091 }
2092 T_next.stop;
2093
2094 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002095 f_shutdown_helper();
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002096 }
2097
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002098 /* Test callocation of PDP contexts until reaching addr pool exhaustion */
2099 type record of OCT4 TEIClist;
2100 testcase TC_addr_pool_exhaustion() runs on GT_CT {
2101 var Gtp1cUnitdata udc;
2102 var Gtp1uUnitdata udu;
2103 var PdpContext ctx;
2104 timer T_next := 0.005;
2105 var integer next_req_ctx := 0;
2106 var integer rx_resp_ctx := 0;
2107 var integer num_ctx;
2108 var boolean cont_req := true;
2109 var CreatePDPContextResponse cpr;
2110 var TEIClist teic_list := {};
2111 var integer teic;
2112
2113 f_init();
2114
2115 T_default.start(120.0);
2116
2117 T_next.start;
2118 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002119 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
2120 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002121 [] pingpong();
2122 [] T_next.timeout {
2123 if (cont_req) {
2124 if (next_req_ctx - rx_resp_ctx < 100) { /* if we have too many in progress, wait a bit to continue */
2125 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), f_rnd_msisdn('1234'O), c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2126 ctx.nsapi := '0001'B;
2127 ctx.teic := int2oct(next_req_ctx+1, 4); /* +1: skip TEIC=0 */
2128 ctx.teid := int2oct(next_req_ctx+1, 4); /* +1: skip TEID=0 */
2129 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx.imsi, g_restart_ctr,
2130 ctx.teid, ctx.teic, ctx.nsapi,
2131 ctx.eua, ctx.apn, g_sgsn_ip_c, g_sgsn_ip_u,
2132 ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol38968e92022-05-13 16:17:48 +02002133 ctx.uli, ctx.charging_char, ctx.imeisv));
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002134 next_req_ctx := next_req_ctx + 1;
2135 }
2136 T_next.start;
2137 }
2138 repeat;
2139 }
2140 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2141 cpr := udc.gtpc.gtpc_pdu.createPDPContextResponse;
2142
2143 if (cpr.cause.causevalue == '80'O) {
2144 teic_list := teic_list & {cpr.teidControlPlane.teidControlPlane};
2145 } else {
2146 if (cont_req == true) {
2147 num_ctx := rx_resp_ctx;
2148 log("Successfully created ", num_ctx, " PDP contexts before exhausting the pool");
2149 setverdict(pass);
2150 }
2151 cont_req := false;
2152 }
2153 rx_resp_ctx := rx_resp_ctx + 1;
2154 if (not cont_req and next_req_ctx == rx_resp_ctx) {
2155 break;
2156 } else {
2157 repeat;
2158 }
2159 }
2160 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2161 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2162 }
2163
2164 /* Let's close them now: */
2165 next_req_ctx := 0;
2166 rx_resp_ctx := 0;
2167 T_next.start;
2168 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002169 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrolcb1e8272022-04-20 14:43:43 +02002170 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002171 [] pingpong();
2172 [] T_next.timeout {
2173 f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, teic_list[next_req_ctx], '0001'B, '1'B));
2174 next_req_ctx := next_req_ctx + 1;
2175 if (next_req_ctx < num_ctx) {
2176 T_next.start;
2177 }
2178 repeat;
2179 }
2180 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2181 teic := oct2int(udc.gtpc.teid);
2182 if (not match(teic, (1 .. num_ctx))) {
2183 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2184 "Rx Unexpected TEIC");
2185 }
2186 rx_resp_ctx := rx_resp_ctx + 1;
2187 if (rx_resp_ctx < num_ctx) {
2188 repeat;
2189 }
2190 setverdict(pass);
2191 }
2192 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2193 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2194 }
2195 T_next.stop;
2196
2197 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002198 f_shutdown_helper();
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002199 }
2200
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002201 /* Test charging over Gy interface. */
2202 testcase TC_gy_charging_cc_time() runs on GT_CT {
2203 var default d;
2204
2205 g_gy_validity_time := 3; /* Grant access for 3 seconds, needs to be re-validated afterwards */
2206 f_init();
Pau Espin Pedrol2fe88952022-05-03 14:56:15 +02002207 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234567890'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002208 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2209 f_pdp_ctx_act(ctx);
2210
2211 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2212
2213 /* Send some UL traffic: */
2214 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2215 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2216 f_wait_icmp4_echo_reply(ctx);
2217
2218 T_default.start(10.0);
2219 d := activate(pingpong());
2220
2221 g_gy_validity_time := 2;
2222 /* First update reports octests/pkt on both UL/DL (see icmp ping-pong above) */
2223 as_DIA_Gy_CCR(UPDATE_REQUEST);
2224
2225 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
2226 as_DIA_Gy_CCR(UPDATE_REQUEST);
2227
2228 /* Third update: make sure report contains again octets/pkts for both UL/DL: */
2229 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2230 f_wait_icmp4_echo_reply(ctx);
2231 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2232 f_wait_icmp4_echo_reply(ctx);
2233 as_DIA_Gy_CCR(UPDATE_REQUEST);
2234
2235 /* Let the CCA reach the GGSN */
2236 f_sleep(0.5);
2237 deactivate(d);
2238 T_default.stop;
2239
2240 /* Send some data and validate it is reported in the TERMINATION_REQUEST
2241 * (triggered by PFCP Session Deletion Response): */
2242 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2243 f_wait_icmp4_echo_reply(ctx);
2244
2245 f_pdp_ctx_del(ctx, '1'B);
2246
2247
2248 f_shutdown_helper();
2249 }
2250
Harald Welte94ade362017-08-04 00:36:55 +02002251 control {
Harald Welteed7a1772017-08-09 20:26:20 +02002252 execute(TC_pdp4_act_deact());
2253 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02002254 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02002255 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002256 execute(TC_pdp4_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002257 execute(TC_pdp4_act_deact_gtpu_access_wrong_saddr());
2258 execute(TC_pdp4_act_deact_gtpu_access_ipv6_apn4());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02002259 execute(TC_pdp4_clients_interact_with_txseq());
2260 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02002261 execute(TC_pdp4_act_deact_with_single_dns());
2262 execute(TC_pdp4_act_deact_with_separate_dns());
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01002263 execute(TC_pdp4_act_update_teic());
2264 execute(TC_pdp4_act_update_teid());
Harald Welteed7a1772017-08-09 20:26:20 +02002265
2266 execute(TC_pdp6_act_deact());
2267 execute(TC_pdp6_act_deact_pcodns());
2268 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002269 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002270 execute(TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr());
2271 execute(TC_pdp6_act_deact_gtpu_access_wrong_global_saddr());
2272 execute(TC_pdp6_act_deact_gtpu_access_ipv4_apn6());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01002273 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02002274
Oliver Smithee6a0882019-03-08 11:05:46 +01002275 execute(TC_pdp46_act_deact());
2276 execute(TC_pdp46_act_deact_ipcp());
2277 execute(TC_pdp46_act_deact_icmp6());
2278 execute(TC_pdp46_act_deact_pcodns4());
2279 execute(TC_pdp46_act_deact_pcodns6());
2280 execute(TC_pdp46_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002281 execute(TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4());
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01002282 execute(TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002283 execute(TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6());
Oliver Smithee6a0882019-03-08 11:05:46 +01002284 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002285 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01002286
Harald Weltedca80052017-08-13 20:01:38 +02002287 execute(TC_echo_req_resp());
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01002288 execute(TC_echo_req_resp_gtpu());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002289 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002290 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002291
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01002292 execute(TC_pdp_act_restart_ctr_echo());
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002293
2294 execute(TC_lots_of_concurrent_pdp_ctx());
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002295 /* Keep at the end, crashes older osmo-ggsn versions (OS#5469): */
2296 execute(TC_addr_pool_exhaustion());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002297
2298 /* open5gs specific tests: */
2299 if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
2300 execute(TC_gy_charging_cc_time());
2301 }
Harald Welte94ade362017-08-04 00:36:55 +02002302 }
Harald Welte379d45a2017-08-03 09:55:15 +02002303}