blob: 435f71deffc5e377b70ef08646d20f4744fd7d2b [file] [log] [blame]
Harald Welte379d45a2017-08-03 09:55:15 +02001module GGSN_Tests {
2
Harald Welte34b5a952019-05-27 11:54:11 +02003/* GGSN test suite in TTCN-3
4 * (C) 2017-2019 Harald Welte <laforge@gnumonks.org>
5 * (C) 2018-2019 sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
Pau Espin Pedrold25095f2022-05-18 16:29:05 +020014 import from TCCEncoding_Functions all;
Harald Welte34b5a952019-05-27 11:54:11 +020015
Harald Welte94ade362017-08-04 00:36:55 +020016 import from General_Types all;
Harald Welte811651e2017-08-05 15:25:06 +020017 import from Osmocom_Types all;
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +010018 import from Misc_Helpers all;
Harald Welte94ade362017-08-04 00:36:55 +020019 import from IPL4asp_PortType all;
20 import from IPL4asp_Types all;
21 import from GTP_CodecPort all;
22 import from GTP_CodecPort_CtrlFunct all;
Harald Weltec69cf4e2018-02-17 20:57:02 +010023 import from GTP_Templates all;
Harald Welte94ade362017-08-04 00:36:55 +020024 import from GTPC_Types all;
25 import from GTPU_Types all;
Harald Welte71a36022017-12-04 18:55:58 +010026 import from IPCP_Types all;
Harald Weltef8298542019-04-10 10:15:28 +020027 import from PAP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020028 import from IP_Types all;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +010029 import from ICMP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020030 import from ICMPv6_Types all;
Harald Welteddeecbb2017-08-18 22:53:30 +020031 import from Native_Functions all;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +020032 import from Osmocom_VTY_Functions all;
33 import from TELNETasp_PortType all;
Harald Welte94ade362017-08-04 00:36:55 +020034
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010035 import from DIAMETER_Types all;
36 import from DIAMETER_Templates all;
37 import from DIAMETER_Emulation all;
38
Harald Welte94ade362017-08-04 00:36:55 +020039 const integer GTP0_PORT := 3386;
40 const integer GTP1C_PORT := 2123;
41 const integer GTP1U_PORT := 2152;
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010042 const integer PCRF_PORT := 3868;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +010043 const integer OCS_PORT := 3869;
Harald Welteddeecbb2017-08-18 22:53:30 +020044
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010045 type enumerated GGSN_Impl {
46 GGSN_IMPL_OSMOCOM,
47 GGSN_IMPL_OPEN5GS
48 };
49
Harald Welteddeecbb2017-08-18 22:53:30 +020050 modulepar {
Stefan Sperlingcb782b92018-04-03 16:03:15 +020051 /* Default IP addresses. May be overridden by GGSN_Tests configuration files. */
52
53 /* The SGSN simulated by TTCN3 will bind to these addresses for GTP control and GTP user planes. */
Harald Welteddeecbb2017-08-18 22:53:30 +020054 charstring m_bind_ip_gtpc := "127.23.42.1";
55 charstring m_bind_ip_gtpu := "127.23.42.1";
56
Stefan Sperlingcb782b92018-04-03 16:03:15 +020057 /* Addresses the GGSN which is being tested is listening on for SGSN connections. */
Harald Welteddeecbb2017-08-18 22:53:30 +020058 charstring m_ggsn_ip_gtpc := "127.0.0.6";
59 charstring m_ggsn_ip_gtpu := "127.0.0.6";
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010060
Stefan Sperlingcb782b92018-04-03 16:03:15 +020061 /*
62 * Our tests expect to see these DNS servers in 'Create PDP context responses' sent by the GGSN.
63 * These addresses must therefore match 'ip[v6] dns' options configured in osmo-ggsn.conf.
64 *
65 * These addresses are not expected to serve actual DNS requests. However, tests may expect to be
66 * able to ping these addresses (currently, IPv4 addresses must respond with an ICMP 'echo reply',
67 * and IPv6 addresses may respond with either ICMPv6 'echo reply' or 'destination unreachable').
68 */
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010069 charstring m_ggsn_ip4_dns1 := "192.168.100.1"
70 charstring m_ggsn_ip4_dns2 := "8.8.8.8"
Pau Espin Pedrol363ba482018-01-29 18:42:00 +010071 charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888"
72 charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844"
Stefan Sperlingcb782b92018-04-03 16:03:15 +020073
74 /*
75 * Additional address ranges are defined in osmo-ggsn.conf from which addresses are assigned
76 * to MS "behind" the simulated SGSN. These addresses appear on tun devices used by osmo-ggsn.
77 * The tests expect to be able to send ping packets between any two simulated MS within the same
78 * address range. This requires IP forwarding to be enabled on the corresponding tun interfaces.
79 */
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +010080 integer mp_t3_response := 5; /* local T3-RESPONSE timeout, seconds */
81 integer mp_n3_requests := 3; /* local N3-REQUESTS counter */
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010082
83 GGSN_Impl m_ggsn_impl := GGSN_IMPL_OSMOCOM;
Harald Welteddeecbb2017-08-18 22:53:30 +020084 }
Harald Welte94ade362017-08-04 00:36:55 +020085
Harald Welte811651e2017-08-05 15:25:06 +020086 type set PdpContext {
87 hexstring imsi,
88 octetstring msisdn optional,
89 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020090 ProtConfigOptions pco_req optional,
91 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020092 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020093 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020094 BIT4 nsapi,
95 /* TEI (Data) local side */
96 OCT4 teid,
97 /* TEI (Control) local side */
98 OCT4 teic,
99 /* TEI (Data) remote side */
100 OCT4 teid_remote,
101 /* TEI (Control) remote side */
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100102 OCT4 teic_remote,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100103 OCT1 ratType optional,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200104 UserLocationInformation uli optional,
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200105 OCT2 charging_char optional,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200106 OCT8 imeisv optional,
107 MS_TimeZone ms_tz optional
Harald Welte811651e2017-08-05 15:25:06 +0200108 }
109
Harald Welte94ade362017-08-04 00:36:55 +0200110 type component GT_CT {
111 port GTPC_PT GTPC;
112 port GTPU_PT GTPU;
113
Harald Welte0be142b2017-08-13 13:28:10 +0200114 var boolean g_initialized := false;
115
Harald Welte94ade362017-08-04 00:36:55 +0200116 var OCT1 g_restart_ctr := '01'O;
117 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200118 var OCT4 g_sgsn_ip_c;
119 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +0200120 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200121 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
122 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200123 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200124
125 /* next to-be-sent GTP-C sequence number */
126 var uint16_t g_c_seq_nr;
127 /* next to-be-sent GTP-U sequence number */
128 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200129
130 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200131 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100132 var integer g_use_echo_intval := 0; /* 0 = disabled */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100133
Pau Espin Pedrol733369a2022-05-20 18:39:55 +0200134 /* Emulated PCRF, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200135 var DIAMETER_conn_parameters g_gx_pars;
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100136 var DIAMETER_Emulation_CT vc_Gx;
137 port DIAMETER_PT Gx_UNIT;
138 port DIAMETEREM_PROC_PT Gx_PROC;
Pau Espin Pedrol733369a2022-05-20 18:39:55 +0200139
140 /* Emulated OCS, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200141 var DIAMETER_conn_parameters g_gy_pars;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100142 var DIAMETER_Emulation_CT vc_Gy;
143 port DIAMETER_PT Gy_UNIT;
144 port DIAMETEREM_PROC_PT Gy_PROC;
145 var integer g_gy_validity_time := 0; /* In seconds. 0 => disabled, !0 => grant over CC-Time period */
Pau Espin Pedrol52562c92022-05-23 15:45:46 +0200146 var integer g_gy_volume_threshold := 0; /* In octets. 0 => disabled, !0 => request IUT to revalidate after N octets */
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200147 var PDU_DIAMETER g_rx_gy; /* Store last received Gy message */
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200148 }
149
150 private function f_init_vty() runs on GT_CT {
151 map(self:GGSNVTY, system:GGSNVTY);
152 f_vty_set_prompts(GGSNVTY);
153 f_vty_transceive(GGSNVTY, "enable");
154 }
155
156 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
157 f_vty_enter_config(GGSNVTY);
158 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200159
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200160 f_vty_transceive(GGSNVTY, "apn internet");
161 if (enable) {
162 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
163 } else {
164 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
165 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200166 f_vty_transceive(GGSNVTY, "exit");
167
168 f_vty_transceive(GGSNVTY, "apn inet6");
169 if (enable) {
170 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
171 } else {
172 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
173 }
174 f_vty_transceive(GGSNVTY, "exit");
175
176 f_vty_transceive(GGSNVTY, "apn inet46");
177 if (enable) {
178 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
179 } else {
180 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
181 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200182 f_vty_transceive(GGSNVTY, "end");
183 }
184
185 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
186 if (expect_gptu_txseq) {
187 if (gtpu.s_bit != '1'B) {
188 log("GTPU sequence number expected but not present")
189 return false;
190 }
191 } else {
192 if (gtpu.s_bit != '0'B) {
193 log("GTPU sequence number not expected but present")
194 return false;
195 }
196 }
197 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200198 }
199
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100200 private function f_vty_enable_echo_interval(integer intval_sec) runs on GT_CT {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200201 f_vty_enter_config(GGSNVTY);
202 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100203 if (intval_sec > 0) {
204 f_vty_transceive(GGSNVTY, "echo-interval " & int2str(intval_sec));
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200205 } else {
206 f_vty_transceive(GGSNVTY, "no echo-interval");
207 }
208 f_vty_transceive(GGSNVTY, "end");
209 }
210
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100211 private function DiameterForwardUnitdataCallback(PDU_DIAMETER msg)
212 runs on DIAMETER_Emulation_CT return template PDU_DIAMETER {
213 DIAMETER_UNIT.send(msg);
214 return omit;
215 }
216
217 private function f_init_diameter(charstring id) runs on GT_CT {
218 var DIAMETEROps ops := {
219 create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback),
220 unitdata_cb := refers(DiameterForwardUnitdataCallback),
221 raw := true /* handler mode (single component for all IMSI)) */
222 };
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100223
224 /* Gx setup: */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200225 g_gx_pars := {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100226 remote_ip := m_ggsn_ip_gtpc,
227 remote_sctp_port := -1,
228 local_ip := m_bind_ip_gtpc,
229 local_sctp_port := PCRF_PORT,
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100230 origin_host := "pcrf.localdomain",
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100231 origin_realm := "localdomain",
Pau Espin Pedrol33b47492022-03-08 17:43:01 +0100232 auth_app_id := omit,
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100233 vendor_app_id := c_DIAMETER_3GPP_Gx_AID
234 };
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100235 vc_Gx := DIAMETER_Emulation_CT.create(id);
236 map(vc_Gx:DIAMETER, system:DIAMETER_CODEC_PT);
237 connect(vc_Gx:DIAMETER_UNIT, self:Gx_UNIT);
238 connect(vc_Gx:DIAMETER_PROC, self:Gx_PROC);
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200239 vc_Gx.start(DIAMETER_Emulation.main(ops, g_gx_pars, id));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100240
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100241 /* Gy setup: */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200242 g_gy_pars := {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100243 remote_ip := m_ggsn_ip_gtpc,
244 remote_sctp_port := -1,
245 local_ip := m_bind_ip_gtpc,
246 local_sctp_port := OCS_PORT,
247 origin_host := "ocs.localdomain",
248 origin_realm := "localdomain",
249 auth_app_id := c_DIAMETER_CREDIT_CONTROL_AID,
250 vendor_app_id := omit
251 };
252 vc_Gy := DIAMETER_Emulation_CT.create(id);
253 map(vc_Gy:DIAMETER, system:DIAMETER_CODEC_PT);
254 connect(vc_Gy:DIAMETER_UNIT, self:Gy_UNIT);
255 connect(vc_Gy:DIAMETER_PROC, self:Gy_PROC);
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200256 vc_Gy.start(DIAMETER_Emulation.main(ops, g_gy_pars, id));
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100257
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100258 f_diameter_wait_capability(Gx_UNIT);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100259 f_diameter_wait_capability(Gy_UNIT);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100260 /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdong ping-pongs):
261 * RFC6733 sec 5.1
262 * RFC3539 sec 3.4.1 [5]
263 * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49
264 */
265 f_sleep(1.0);
266 }
267
Harald Welte94ade362017-08-04 00:36:55 +0200268 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200269 if (g_initialized == true) {
270 return;
271 }
272 g_initialized := true;
273
Harald Welteddeecbb2017-08-18 22:53:30 +0200274 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
275 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
276
Harald Welte94ade362017-08-04 00:36:55 +0200277 var Result res;
278 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +0200279 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200280 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200281 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200282
283 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +0200284 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200285 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200286
287 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200288 g_c_seq_nr := f_rnd_int(65535);
289 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200290
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100291 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
292 f_init_vty();
293 f_vty_set_gpdu_txseq(use_gtpu_txseq);
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100294 f_vty_enable_echo_interval(g_use_echo_intval);
Oliver Smith95722c62023-10-20 13:59:10 +0200295 /* Emit a marker to appear in the SUT's own logging output */
296 f_logp(GGSNVTY, testcasename() & "() start");
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100297 } else if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
298 f_init_diameter(testcasename());
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100299 }
Harald Welte94ade362017-08-04 00:36:55 +0200300 }
301
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100302 function f_shutdown_helper() runs on GT_CT {
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +0100303 /* Sleep (T3-RESPONSE * N3-REQUESTS) seconds.
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100304 * This ensures all retransmit queues are cleared before jumping
305 * into next tests, hence avoding situation where a test resuses
306 * a seqnum still in the GGSN's resp queue (dup req detector).
307 * See OS#5485 avout decreasing time. We could also add a new
308 * VTY command that calls gtp_clear_queues() */
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +0100309 f_sleep(int2float(mp_t3_response * mp_n3_requests));
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100310 setverdict(pass);
311 }
312
Harald Welte94ade362017-08-04 00:36:55 +0200313 /* Altstep implementing responses to any incoming echo requests */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100314 private altstep pingpong() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200315 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200316 var Gtp1uUnitdata udu;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100317 [g_use_echo_intval > 0] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200318 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200319 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200320 repeat;
321 };
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100322 [g_use_echo_intval == 0] GTPC.receive(tr_GTPC_PING(?)) {
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100323 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
324 "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200325 };
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100326 [] T_default.timeout {
327 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
328 "pinpong T_default timeout");
329 };
Harald Welte94ade362017-08-04 00:36:55 +0200330 }
331
Harald Welte811651e2017-08-05 15:25:06 +0200332 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200333 const octetstring c_ApnInternet := '08696E7465726E6574'O;
334 const octetstring c_ApnInet6 := '05696E657436'O;
335 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200336
Harald Welte811651e2017-08-05 15:25:06 +0200337 /* return random NSAPI */
338 function f_rnd_nsapi() return BIT4 {
339 return int2bit(f_rnd_int(16), 4);
340 }
341
342 /* return random TEI[DC] */
343 function f_rnd_tei() return OCT4 {
344 return int2oct(f_rnd_int(4294967296), 4);
345 }
346
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200347 /* return random IMEI(SV) */
348 function f_rnd_imeisv() return OCT8 {
349 return hex2oct(f_rnd_hexstring(16, 10));
350 }
351
Harald Welte811651e2017-08-05 15:25:06 +0200352 /* define an (internal) representation of a PDP context */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +0200353 template PdpContext t_DefinePDP(hexstring imsi, charstring msisdn, octetstring apn,
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100354 EndUserAddress eua, OCT1 ratType := '02'O /* GERAN */) := {
Harald Welte811651e2017-08-05 15:25:06 +0200355 imsi := imsi,
Pau Espin Pedrold25095f2022-05-18 16:29:05 +0200356 msisdn := '11'O & f_enc_TBCD(msisdn), /* encoded as TS 29.060 7.7.33, TS 29.002 */
Harald Welte811651e2017-08-05 15:25:06 +0200357 nsapi := f_rnd_nsapi(),
358 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200359 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200360 eua := eua,
361 teid := f_rnd_tei(),
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100362 teic := f_rnd_tei(),
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100363 ratType := ratType,
364 uli := {
365 type_gtpc := '98'O,
366 lengthf := 0 /* filled in by encoder */,
367 geographicLocationType := '00'O /* CGI */,
368 geographicLocation := {
369 geographicLocationCGI := ts_GeographicLocationCGI('262'H, '42F'H, '0001'O, '0002'O)
370 }
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200371 },
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200372 charging_char := '0000'O,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200373 imeisv := f_rnd_imeisv(),
374 ms_tz := f_ts_MS_TimeZone('03'O, '01'B)
Harald Welte811651e2017-08-05 15:25:06 +0200375 }
376
377 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200378 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200379 GTPC.send(data);
Pau Espin Pedrol82a7f702022-05-19 17:41:29 +0200380 g_c_seq_nr := (g_c_seq_nr + 1) mod 65536;
Harald Welte811651e2017-08-05 15:25:06 +0200381 }
382
383 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200384 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200385 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200386 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
Pau Espin Pedrol82a7f702022-05-19 17:41:29 +0200387 g_d_seq_nr := (g_d_seq_nr + 1) mod 65536;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200388 } else {
389 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
390 }
Harald Welte811651e2017-08-05 15:25:06 +0200391 }
392
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100393 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 +0200394 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100395
396 if (not match(cpr.cause.causevalue, exp_cause)) {
397 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
398 "CreatePDPContextResp: cause expectancies didn't match");
399 }
400
401 if (cpr.cause.causevalue == '80'O) { /* Accepted */
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200402 /* Check if EUA type corresponds to requested type */
403 if (match(ctx.eua, t_EuaIPv4(?)) and
404 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
406 "EUAv4 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200407 }
408 if (match(ctx.eua, t_EuaIPv6(?)) and
409 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
411 "EUAv6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200412 }
413 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
414 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100415 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
416 "EUAv4v6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200417 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100418 } else if (cpr.cause.causevalue == '81'O) { /* Cause: New PDP type due to network preference */
419 /* ETSI TS 129 060 7.3.2 Create PDP Context Response. OS#5449 */
420 /* This should only happen if EUA requested type is v4v6: */
421 if (not ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
422 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
423 "Cause not expected when requesting a non v4v6 EUA");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200424 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100425 if (not match(cpr.endUserAddress, (tr_EuaIPv4(?), tr_EuaIPv6(?)))) {
426 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
427 "Cause not expected when requesting+receiving EUAv4v6");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200428 }
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200429 } else {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100430 if (ispresent(cpr.endUserAddress)) {
431 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
432 "EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
433 }
434 setverdict(pass);
435 return;
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200436 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100437
438 /* Check if PCO response corresponds to request */
439 if (ispresent(ctx.pco_req)) {
440 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
441 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
442 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
443 "IPv4 DNS Container requested, but missing");
444 }
445 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
446 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
447 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
448 "IPv6 DNS Container requested, but missing");
449 }
450 }
451 ctx.teid_remote := cpr.teidDataI.teidDataI;
452 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
453 ctx.eua := cpr.endUserAddress;
454 ctx.pco_neg := cpr.protConfigOptions;
455 setverdict(pass);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200456 }
457
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100458 function f_handle_update_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
459 var UpdatePDPContextResponseGGSN upr := ud.gtpc.gtpc_pdu.updatePDPContextResponse.updatePDPContextResponseGGSN;
460 if (exp_cause == '80'O and exp_cause == upr.cause.causevalue) {
461 ctx.teid_remote := upr.teidDataI.teidDataI;
462 ctx.teic_remote := upr.teidControlPlane.teidControlPlane;
463 if (ispresent(upr.protConfigOptions)) {
464 ctx.pco_neg := upr.protConfigOptions;
465 }
466 setverdict(pass);
467 } else if (exp_cause != '80'O and exp_cause == upr.cause.causevalue) {
468 setverdict(pass);
469 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100470 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
471 "UpdatePDPContextResp: cause expectancies didn't match");
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100472 }
473 }
474
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100475 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 +0100476 var PDU_DIAMETER rx_dia;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100477 [] Gx_UNIT.receive(tr_DIA_Gx_CCR(req_type := req_type)) -> value rx_dia {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100478 var template (omit) AVP avp;
479 var octetstring sess_id;
480 var AVP_Unsigned32 req_num;
481
482 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
483 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
484
485 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
486 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
487
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100488 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 +0100489 req_type, req_num));
490 }
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100491 [] Gx_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100492 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
493 log2str("Received unexpected DIAMETER ", rx_dia));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100494 }
495 }
496
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200497 private function f_tr_DIA_Gy_CCR(template (omit) PdpContext ctx, DCC_NONE_CC_Request_Type req_type)
498 runs on GT_CT return template (present) PDU_DIAMETER
499 {
500 var template (present) PDU_DIAMETER tpl;
501 var charstring smf_origin_host := "smf.localdomain";
502 var template (present) octetstring imsi := ?;
503 var template (present) octetstring msisdn := ?;
504 var template (present) octetstring imeisv := ?;
505 var template (present) octetstring rat_type := ?;
506 var template (present) OCT4 charging_char := ?;
507 var template (present) OCT1 nsapi := ?;
508 if (not istemplatekind(ctx, "omit")) {
509 var PdpContext ctx_val := valueof(ctx);
510 imsi := char2oct(f_dec_TBCD(imsi_hex2oct(ctx_val.imsi)));
511 msisdn := char2oct(f_dec_TBCD(substr(ctx_val.msisdn, 1, lengthof(ctx_val.msisdn) -1)));
512 imeisv := char2oct(f_dec_TBCD(ctx_val.imeisv));
513 rat_type := ctx_val.ratType;
514 charging_char := char2oct(oct2str(ctx_val.charging_char));
515 nsapi := char2oct(hex2str(bit2hex(ctx_val.nsapi)));
516 }
517 select (req_type) {
518 case (INITIAL_REQUEST) {
519 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
520 avps := superset(
521 tr_AVP_SessionId,
522 tr_AVP_OriginHost(smf_origin_host),
523 tr_AVP_OriginRealm(g_gy_pars.origin_realm),
524 tr_AVP_DestinationRealm(g_gy_pars.origin_realm),
525 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
526 tr_AVP_ServiceContextId,
527 tr_AVP_CcReqType(req_type),
528 tr_AVP_CcReqNum(?),
529 tr_AVP_EventTimestamp(?),
530 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
531 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
532 tr_AVP_RequestedAction(DIRECT_DEBITING),
533 tr_AVP_3GPP_AoCRequestType,
534 tr_AVP_MultipleServicesIndicator,
535 tr_AVP_Multiple_Services_Credit_Control(content := superset(
536 tr_AVP_Requested_Service_Unit,
Pau Espin Pedrol6477d732022-06-03 12:04:40 +0200537 tr_AVP_PCC_3GPP_QoS_Information,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200538 tr_AVP_GI_3GPP_RatType(rat_type)
539 )),
540 tr_AVP_3GPP_ServiceInformation(content := superset(
541 tr_AVP_3GPP_PSInformation(content := superset(
542 tr_AVP_3GPP_ChargingId,
543 tr_AVP_3GPP_PDPType((IPv4,IPv6,IPv4v6)),
544 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
545 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_bind_ip_gtpc))),
546 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_ggsn_ip_gtpc))),
547 tr_AVP_3GPP_CalledStationId,
548 tr_AVP_3GPP_SelectionMode,
549 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
550 tr_AVP_3GPP_SGSNMCCMNC,
551 tr_AVP_3GPP_NSAPI(nsapi),
552 tr_AVP_3GPP_MS_TimeZone,
553 tr_AVP_3GPP_ULI,
554 tr_AVP_UserEquipmentInfo({
555 tr_AVP_UserEquipmentInfoType(IMEISV),
556 tr_AVP_UserEquipmentInfoValue(imeisv)
557 })
558 ))
559 ))
560 ));
561 }
562 case (UPDATE_REQUEST) {
563 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
564 avps := superset(
565 tr_AVP_SessionId,
566 tr_AVP_OriginHost(smf_origin_host),
567 tr_AVP_OriginRealm(g_gy_pars.origin_realm),
568 tr_AVP_DestinationRealm(g_gy_pars.origin_realm),
569 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
570 tr_AVP_ServiceContextId,
571 tr_AVP_CcReqType(req_type),
572 tr_AVP_CcReqNum(?),
573 tr_AVP_DestinationHost(?),
574 tr_AVP_EventTimestamp(?),
575 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
576 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
577 tr_AVP_RequestedAction(DIRECT_DEBITING),
578 tr_AVP_3GPP_AoCRequestType,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200579 tr_AVP_Multiple_Services_Credit_Control(content := superset(
580 tr_AVP_Requested_Service_Unit,
581 tr_AVP_Used_Service_Unit,
Pau Espin Pedrolcba0f6d2022-05-24 13:49:46 +0200582 /* tr_AVP_3GPP_Reporting_Reason, can be sometimes inside UsedServiceUnit */
Pau Espin Pedrol6477d732022-06-03 12:04:40 +0200583 tr_AVP_PCC_3GPP_QoS_Information,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200584 tr_AVP_GI_3GPP_RatType(rat_type)
585 )),
586 tr_AVP_3GPP_ServiceInformation(content := superset(
587 tr_AVP_3GPP_PSInformation(content := superset(
588 tr_AVP_3GPP_ChargingId,
589 /* tr_AVP_3GPP_PDPType, Only in INIT */
590 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
591 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_bind_ip_gtpc))),
592 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_ggsn_ip_gtpc))),
593 tr_AVP_3GPP_CalledStationId,
594 tr_AVP_3GPP_SelectionMode,
595 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
596 tr_AVP_3GPP_SGSNMCCMNC,
597 tr_AVP_3GPP_NSAPI(nsapi),
598 tr_AVP_3GPP_MS_TimeZone,
599 tr_AVP_3GPP_ULI,
600 tr_AVP_UserEquipmentInfo({
601 tr_AVP_UserEquipmentInfoType(IMEISV),
602 tr_AVP_UserEquipmentInfoValue(imeisv)
603 })
604 ))
605 ))
606 ));
607 }
608 case (TERMINATION_REQUEST) {
609 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
610 avps := superset(
611 tr_AVP_SessionId,
612 tr_AVP_OriginHost(smf_origin_host),
613 tr_AVP_OriginRealm(g_gy_pars.origin_realm),
614 tr_AVP_DestinationRealm(g_gy_pars.origin_realm),
615 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
616 tr_AVP_ServiceContextId,
617 tr_AVP_CcReqType(req_type),
618 tr_AVP_CcReqNum(?),
619 tr_AVP_DestinationHost(?),
620 tr_AVP_EventTimestamp(?),
621 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
622 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
623 tr_AVP_TerminationCause(?),
624 tr_AVP_RequestedAction(DIRECT_DEBITING),
625 tr_AVP_3GPP_AoCRequestType,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200626 tr_AVP_Multiple_Services_Credit_Control(content := superset(
627 /* tr_AVP_Requested_Service_Unit, Only in INIT and UPDATE */
628 tr_AVP_Used_Service_Unit,
Pau Espin Pedrolcba0f6d2022-05-24 13:49:46 +0200629 tr_AVP_3GPP_Reporting_Reason(FINAL),
Pau Espin Pedrol6477d732022-06-03 12:04:40 +0200630 tr_AVP_PCC_3GPP_QoS_Information,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200631 tr_AVP_GI_3GPP_RatType(rat_type)
632 )),
633 tr_AVP_3GPP_ServiceInformation(content := superset(
634 tr_AVP_3GPP_PSInformation(content := superset(
635 tr_AVP_3GPP_ChargingId,
636 /* tr_AVP_3GPP_PDPType, Only in INIT */
637 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
638 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_bind_ip_gtpc))),
639 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_ggsn_ip_gtpc))),
640 tr_AVP_3GPP_CalledStationId,
641 tr_AVP_3GPP_SelectionMode,
642 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
643 tr_AVP_3GPP_SGSNMCCMNC,
644 tr_AVP_3GPP_NSAPI(nsapi),
645 tr_AVP_3GPP_MS_TimeZone,
646 tr_AVP_3GPP_ULI,
647 tr_AVP_UserEquipmentInfo({
648 tr_AVP_UserEquipmentInfoType(IMEISV),
649 tr_AVP_UserEquipmentInfoValue(imeisv)
650 })
651 ))
652 ))
653 ));
654 }
655 }
656 return tpl;
657 }
658
659 private altstep as_DIA_Gy_CCR(template (omit) PdpContext ctx, DCC_NONE_CC_Request_Type req_type) runs on GT_CT {
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200660 [] Gy_UNIT.receive(f_tr_DIA_Gy_CCR(ctx, req_type := req_type)) -> value g_rx_gy {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100661 var template (value) PDU_DIAMETER tx_dia;
662 var template (omit) AVP avp;
663 var octetstring sess_id;
664 var AVP_Unsigned32 req_num;
665
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200666 avp := f_DIAMETER_get_avp(g_rx_gy, c_AVP_Code_BASE_NONE_Session_Id);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100667 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
668
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200669 avp := f_DIAMETER_get_avp(g_rx_gy, c_AVP_Code_DCC_NONE_CC_Request_Number);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100670 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
671 if (g_gy_validity_time > 0) {
Pau Espin Pedrol52562c92022-05-23 15:45:46 +0200672 if (g_gy_volume_threshold > 0) {
673 tx_dia := ts_DIA_Gy_CCA_ValidityTimeVolumeThreshold(g_rx_gy.hop_by_hop_id, g_rx_gy.end_to_end_id, sess_id,
674 req_type, req_num, g_gy_validity_time, g_gy_volume_threshold);
675 } else {
676 tx_dia := ts_DIA_Gy_CCA_ValidityTime(g_rx_gy.hop_by_hop_id, g_rx_gy.end_to_end_id, sess_id,
677 req_type, req_num, g_gy_validity_time);
678 }
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100679 } else {
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200680 tx_dia := ts_DIA_Gy_CCA(g_rx_gy.hop_by_hop_id, g_rx_gy.end_to_end_id, sess_id,
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100681 req_type, req_num);
682 }
683 Gy_UNIT.send(tx_dia);
684 }
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200685 [] Gy_UNIT.receive(PDU_DIAMETER:?) -> value g_rx_gy {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100686 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200687 log2str("Received unexpected DIAMETER Gy", g_rx_gy));
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100688 }
689 }
690
Harald Welte811651e2017-08-05 15:25:06 +0200691 /* send a PDP context activation */
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100692 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 +0200693 var Gtp1cUnitdata ud;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100694 var CreatePDPContextResponse cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200695 var default d;
696
697 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200698 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 +0200699 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200700 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200701 ctx.uli, ctx.charging_char, ctx.imeisv, ctx.ms_tz));
Harald Welte94ade362017-08-04 00:36:55 +0200702 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200703 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100704 if (Gx_PROC.checkstate("Connected")) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100705 as_DIA_Gx_CCR(INITIAL_REQUEST);
706 }
707 if (Gy_PROC.checkstate("Connected")) {
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200708 as_DIA_Gy_CCR(ctx, INITIAL_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100709 }
Harald Welte94ade362017-08-04 00:36:55 +0200710 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200711 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200712 f_handle_create_req(ctx, ud, exp_cause);
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100713 cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Harald Welte94ade362017-08-04 00:36:55 +0200714 }
715 }
716 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200717 T_default.stop;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100718 return cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200719 }
720
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200721 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
722 var Gtp1cUnitdata ud;
723 var default d;
724
725 T_default.start;
726 d := activate(pingpong());
727 alt {
728 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
729 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
730 setverdict(pass);
731 } else if (not istemplatekind(expect_cause, "omit") and
732 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
733 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
734 setverdict(pass);
735 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100736 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
737 "DeletePDPContextReq: cause expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200738 }
739
740 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
741 setverdict(pass);
742 } else {
743 setverdict(fail);
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100744 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
745 "DeletePDPContextReq: tearDownIndicator expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200746 }
747 }
748 }
749 deactivate(d);
750 T_default.stop;
751 }
752
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +0100753 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 +0200754 var Gtp1cUnitdata ud;
755 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200756 var OCT4 expect_teid;
757
758 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
759 message with cause value "Non existent" shall be zero. */
760 if (expect_causevalue == 'C0'O) {
761 expect_teid := '00000000'O;
762 } else {
763 expect_teid := ctx.teic;
764 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200765
Harald Welte41575e92017-08-13 13:49:57 +0200766 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 +0200767 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200768 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100769 if (Gx_PROC.checkstate("Connected") and expect_diameter) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100770 as_DIA_Gx_CCR(TERMINATION_REQUEST);
771 }
772 if (Gy_PROC.checkstate("Connected") and expect_diameter) {
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200773 as_DIA_Gy_CCR(ctx, TERMINATION_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100774 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200775 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200776 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
777 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200778 setverdict(pass);
779 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100780 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
781 "DeletePDPContextResp: cause expectancies didn't match");
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200782 }
783 }
784 }
785 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200786 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200787 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100788
789 /* send a Update PdP Context Request, expect Response */
790 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 {
791 var Gtp1cUnitdata ud;
792 var default d;
793
794 if (not istemplatekind(new_teid, "omit")) {
795 ctx.teid := valueof(new_teid);
796 }
797 if (not istemplatekind(new_teic, "omit")) {
798 ctx.teic := valueof(new_teic);
799 }
800
801 log("sending UpdatePDP");
802 f_send_gtpc(ts_GTPC_UpdatePDP(g_peer_c, ctx.teic_remote, g_c_seq_nr, ctx.imsi, g_restart_ctr,
803 ctx.teid, ctx.teic, ctx.nsapi, g_sgsn_ip_c, g_sgsn_ip_u,
804 ctx.pco_req, ctx.ratType, ctx.uli));
805 T_default.start;
806 d := activate(pingpong());
807 alt {
808 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, updatePDPContextResponse, ctx.teic)) -> value ud {
809 f_handle_update_req(ctx, ud, exp_cause);
810 }
811 }
812 deactivate(d);
813 T_default.stop;
814 }
815
Harald Welte811651e2017-08-05 15:25:06 +0200816 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
817 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
818 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
819 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200820
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200821 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100822 template (value) PDU_ICMP ts_ICMPv4_ERQ(octetstring data := ''O) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100823 echo := {
824 type_field := 8,
825 code := 0,
826 checksum := '0000'O,
827 identifier := '0345'O,
828 sequence_number := '0001'O,
Pau Espin Pedrol52562c92022-05-23 15:45:46 +0200829 data := data
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100830 }
831 }
832
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200833 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100834 template (present) PDU_ICMP tr_ICMPv4_ERQ := {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100835 echo := {
836 type_field := 8,
837 code := 0,
838 checksum := ?,
839 identifier := ?,
840 sequence_number := ?,
841 data := ?
842 }
843 }
844
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200845 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100846 template (present) PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100847 echo_reply := {
848 type_field := 0,
849 code := 0,
850 checksum := ?,
851 identifier := ?,
852 sequence_number := ?,
853 data := data
854 }
855 }
856
857 /* template for receiving/matching an ICMPv6 Destination Unreachable */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100858 template (present) PDU_ICMP tr_ICMPv4_DU := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100859 destination_unreachable := {
860 type_field := 1,
861 code := ?,
862 checksum := ?,
863 unused := ?,
864 original_ip_msg := ?
865 }
866 }
867
868 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100869 template (value) IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100870 header := {
871 ver := 4,
872 hlen := 5,
873 tos := 0,
874 tlen := tlen,
875 id := 35902,
876 res := '0'B,
877 dfrag := '1'B,
878 mfrag := '0'B,
879 foffset := 0,
880 ttl := 64,
881 proto := proto,
882 cksum := 0,
883 srcaddr := srcaddr,
884 dstaddr := dstaddr
885 },
886 ext_headers := omit,
887 payload := payload
888 }
889
Harald Welte231b9412017-08-09 17:16:31 +0200890 /* template to generate a 'Prefix Information' ICMPv6 option */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100891 template (value) OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200892 prefixInformation := {
893 typeField := 3,
894 lengthIndicator := 8,
895 prefixLength := prefix_len,
896 reserved1 := '000000'B,
897 a_Bit := '0'B,
898 l_Bit := '0'B,
899 validLifetime := oct2int('FFFFFFFF'O),
900 preferredLifetime := oct2int('FFFFFFFF'O),
901 reserved2 := '00000000'O,
902 prefix := prefix
903 }
904 }
905
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200906 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100907 template (value) PDU_ICMPv6 ts_ICMPv6_ERQ := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100908 echoRequest := {
909 typeField := 128,
910 code := 0,
911 checksum := '0000'O,
912 identifier := 0,
913 sequenceNr := 0,
914 data := ''O
915 }
916 }
917
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200918 /* template for sending an ICMPv6 router solicitation */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100919 template (value) PDU_ICMPv6 ts_ICMPv6_RS := {
Harald Welte231b9412017-08-09 17:16:31 +0200920 routerSolicitation := {
921 typeField := 133,
922 code := 0,
923 checksum := '0000'O,
924 reserved := '00000000'O,
925 /* TODO: do we need 'Source link-layer address' ? */
926 options := omit
927 }
928 }
929
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200930 /* template for sending an ICMPv6 router advertisement */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100931 template (value) PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200932 routerAdvertisement := {
933 typeField := 134,
934 code := 0,
935 checksum := '0000'O,
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100936 curHopLimit := 0,
Harald Welte231b9412017-08-09 17:16:31 +0200937 reserved := '000000'B,
938 o_Bit := '0'B,
939 m_Bit := '0'B,
940 routerLifetime := oct2int('FFFF'O),
941 reachableTime := oct2int('FFFFFFFF'O),
942 retransTimer := oct2int('FFFFFFFF'O),
943 options := {
944 ts_ICMP6_OptPrefix(prefix, prefix_len)
945 }
946 }
947 }
948
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200949 /* template for sending an ICMPv6 neighbor solicitation */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100950 template (value) PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
Harald Welte231b9412017-08-09 17:16:31 +0200951 neighborSolicitation := {
952 typeField := 135,
953 code := 0,
954 checksum := '0000'O,
955 reserved := '00000000'O,
956 targetAddress := target_addr,
957 /* TODO: do we need 'Source link-layer address' ? */
958 options := omit
959 }
960 }
961
962 /* derive ICMPv6 link-local address from lower 64bit of link_id */
963 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100964 template (present) OptionField tr_ICMP6_OptPrefix(template (present) OCT16 prefix, template (present) INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200965 prefixInformation := {
966 typeField := 3,
967 lengthIndicator := 4,
968 prefixLength := prefix_len,
969 reserved1 := ?,
970 a_Bit := ?,
971 l_Bit := ?,
972 validLifetime := ?,
973 preferredLifetime := ?,
974 reserved2 := ?,
975 prefix := prefix
976 }
977 }
978
Pau Espin Pedrolae04c792023-12-05 14:51:42 +0100979 /* template for receiving/matching an ICMPv6 'MTU' option, rfc4861 4.6.4 */
980 template (present) OptionField tr_ICMP6_OptMTU(template (present) integer mtu := ?) := {
981 mTU := {
982 typeField := 5,
983 lengthIndicator := 1,
984 reserved := ?,
985 mTU_Value := mtu
986 }
987 }
988
Harald Welte231b9412017-08-09 17:16:31 +0200989 /* template for receiving/matching an ICMPv6 router advertisement */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100990 template (present) PDU_ICMPv6 tr_ICMPv6_RA(template (present) OCT16 prefix, template (present) INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200991 routerAdvertisement := {
992 typeField := 134,
993 code := 0,
994 checksum := ?,
995 curHopLimit := ?,
996 reserved := ?,
997 o_Bit := '0'B,
998 m_Bit := '0'B,
999 routerLifetime := ?,
1000 reachableTime := ?,
1001 retransTimer := ?,
Pau Espin Pedrolae04c792023-12-05 14:51:42 +01001002 options := ({ tr_ICMP6_OptPrefix(prefix, prefix_len) },
1003 { tr_ICMP6_OptPrefix(prefix, prefix_len), tr_ICMP6_OptMTU }
1004 )
Harald Welte231b9412017-08-09 17:16:31 +02001005 }
1006 }
1007
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001008 /* template for receiving/matching an ICMPv6 Destination Unreachable */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001009 template (present) PDU_ICMPv6 tr_ICMPv6_DU := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001010 destinationUnreachable := {
1011 typeField := 1,
1012 code := ?,
1013 checksum := ?,
1014 unused := ?,
1015 originalIpMsg := ?
1016 }
1017 }
1018
Stefan Sperling6cd217e2018-03-30 15:17:34 +02001019 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001020 template (present) PDU_ICMPv6 tr_ICMPv6_ERQ := {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001021 echoRequest := {
1022 typeField := 128,
1023 code := 0,
1024 checksum := ?,
1025 identifier := ?,
1026 sequenceNr := ?,
1027 data := ?
1028 }
1029 }
1030
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001031 /* template for receiving/matching an ICMPv6 echo reply */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001032 template (present) PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001033 echoReply := {
1034 typeField := 129,
1035 code := 0,
1036 checksum := ?,
1037 identifier := ?,
1038 sequenceNr := ?,
1039 data := data
1040 }
1041 }
1042
Harald Welte231b9412017-08-09 17:16:31 +02001043 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001044 template (value) IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
Harald Welte231b9412017-08-09 17:16:31 +02001045 header := {
1046 ver := 6,
1047 trclass := 0,
1048 flabel := 0,
1049 plen := 0,
1050 nexthead := nexthead,
1051 hlim := hlim,
1052 srcaddr := srcaddr,
1053 dstaddr := dstaddr
1054 },
1055 ext_headers := omit,
1056 payload := payload
1057 }
1058
1059 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
1060 return 'FE80000000000000'O & substr(link_id, 8, 8);
1061 }
1062
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001063 function f_ipv6_global(in OCT16 link_id) return OCT16 {
1064 return substr(link_id, 0, 8) & '1234123412341234'O;
1065 }
1066
1067 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
1068 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
1069 var integer i;
1070 var octetstring res := substr(addr, 0, prefix);
1071 for (i := prefix; i < lengthof(addr); i := i + 1) {
1072 var octetstring a := addr[i] xor4b '11'O;
1073 res := res & a;
1074 }
1075 return res;
1076 }
1077
Harald Welte231b9412017-08-09 17:16:31 +02001078 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
1079 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
1080 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
1081 }
1082
1083 /* generate and encode ICMPv6 router solicitation */
1084 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
1085 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
1086 var OCT16 saddr := f_ipv6_link_local(link_id);
1087
1088 var octetstring tmp;
1089 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
1090 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
1091
1092 return f_IPv6_enc(ip6);
1093 }
1094
Pau Espin Pedrol57604212022-02-14 16:54:18 +01001095 /* Get link-id from PDP Context EUA */
1096 function f_ctx_get_ipv6_interface_id(in PdpContext ctx) return OCT16 {
1097 var OCT16 interface_id;
1098 if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
1099 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1100 } else if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv6)) {
1101 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
1102 } else {
1103 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected request to submit icmpv6 rs in IPv4 PDP context");
1104 }
1105 return interface_id;
1106 }
1107
Harald Welte231b9412017-08-09 17:16:31 +02001108 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
1109 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +01001110 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001111 return f_gen_icmpv6_router_solicitation(interface_id);
1112 }
1113
1114 /* generate and encode ICMPv6 neighbor solicitation */
1115 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
1116 var octetstring tmp;
1117 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
1118 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
1119 return f_IPv6_enc(ip6);
1120 }
1121
1122 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
1123 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +01001124 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001125 var OCT16 link_local := f_ipv6_link_local(interface_id);
1126 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
1127
1128 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
1129 }
1130
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001131 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02001132 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr, octetstring pl := ''O) return octetstring {
1133 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ(pl)));
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001134 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
1135 var octetstring data := f_IPv4_enc(ip4);
1136 var OCT2 cksum := f_IPv4_checksum(data);
1137 data[10] := cksum[0];
1138 data[11] := cksum[1];
1139 return data;
1140 }
1141
1142 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
1143 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
1144 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
1145 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
1146 var octetstring data := f_IPv6_enc(ip6);
1147 return data;
1148 }
1149
1150 /* Wait for ICMPv4 from GTP */
1151 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +02001152 var Gtp1uUnitdata ud;
1153 T_default.start;
1154 alt {
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001155 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ctx.teid)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +02001156 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001157 setverdict(fail);
1158 stop;
1159 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001160 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1161 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
1162 if (ip4.header.ver != 4) {
1163 repeat;
1164 }
1165 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
1166 if (not match(icmp4, expected)) {
1167 repeat;
1168 }
1169 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001170 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
1171 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1172 "Received wrong local TEID");
1173 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001174 [] GTPU.receive { setverdict(fail); }
1175 [] T_default.timeout { setverdict(fail); }
1176 }
1177 T_default.stop;
1178 }
1179
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001180 /* Wait for ICMPv4 echo request from GTP */
1181 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
1182 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
1183 }
1184
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001185 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
1186 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
1187 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
1188 }
1189
1190 /* Wait for ICMPv6 from GTP */
1191 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
1192 var Gtp1uUnitdata ud;
1193 T_default.start;
1194 alt {
Harald Welte231b9412017-08-09 17:16:31 +02001195 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +02001196 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Pau Espin Pedrol9c1c2ae2023-12-05 14:24:49 +01001197 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1198 log2str("Received GTPU with wrong txseq while waiting for ICMPv6: ", expected));
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001199 }
Harald Welte231b9412017-08-09 17:16:31 +02001200 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1201 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001202 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +02001203 repeat;
1204 }
1205 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001206 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +02001207 repeat;
1208 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001209 /* We are waiting for RA, update ctx */
1210 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
1211 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
1212 log("RA with /64 prefix ", ctx.ip6_prefix);
1213 }
Harald Welte231b9412017-08-09 17:16:31 +02001214 }
1215 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
Pau Espin Pedrol9c1c2ae2023-12-05 14:24:49 +01001216 [] GTPU.receive {
1217 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1218 log2str("Received unexpected GTPU while waiting for ICMPv6: ", expected));
1219 }
1220 [] T_default.timeout {
1221 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1222 log2str("Timeout waiting for ICMPv6: ", expected));
1223 }
Harald Welte231b9412017-08-09 17:16:31 +02001224 }
1225 T_default.stop;
1226 }
1227
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001228 /* wait for GGSN to send us an ICMPv6 router advertisement */
1229 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
1230 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
1231 }
1232
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001233 /* Wait for ICMPv6 echo request from GTP */
1234 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
1235 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
1236 }
1237
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001238 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
1239 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
1240 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
1241 }
1242
Oliver Smithee6a0882019-03-08 11:05:46 +01001243 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
1244 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
1245 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1246 return f_gen_icmpv6_router_solicitation(interface_id);
1247 }
1248
1249 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
1250 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
1251 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1252 var OCT16 link_local := f_ipv6_link_local(interface_id);
1253 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
1254
1255 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
1256 }
1257
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001258 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
1259 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
1260 T_default.start;
1261 alt {
1262 [] GTPU.receive { setverdict(fail); }
1263 [] T_default.timeout { }
1264 }
1265 T_default.stop;
1266 }
1267
Harald Welte79737b42019-04-10 10:39:30 +02001268 /* list of protocols where we don't accept duplicates */
1269 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
1270 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
1271 var integer i;
1272 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
1273 if (id == protocol_ids_nodupes[i]) {
1274 return false;
1275 }
1276 }
1277 return true;
1278 }
1279
1280 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
1281 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
1282 var OCT2List protocol_ids := {};
1283 var integer i, j;
1284 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
1285 var OCT2 id := pco.protocols[i].protocolID;
1286 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
1287 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
1288 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
1289 }
1290 }
1291 protocol_ids := protocol_ids & { id };
1292 }
1293 }
1294
Harald Welte0ef285b2017-08-13 20:06:01 +02001295 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +02001296 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +02001297 f_init();
Harald Welte231b9412017-08-09 17:16:31 +02001298
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001299 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welte811651e2017-08-05 15:25:06 +02001300 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +02001301 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001302 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001303 }
1304
Harald Welte0ef285b2017-08-13 20:06:01 +02001305 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001306 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
1307 f_init();
1308
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001309 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001310 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1311 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001312
Harald Welte79737b42019-04-10 10:39:30 +02001313 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001314 /* verify PCO contains both primary and secondary DNS */
1315 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1316 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1317 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1318 }
1319
1320 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1321 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1322 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1323 }
1324
Harald Welteed7a1772017-08-09 20:26:20 +02001325 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001326 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001327 }
1328
Harald Welte0ef285b2017-08-13 20:06:01 +02001329 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +02001330 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
1331 f_init();
1332
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001333 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001334 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1335 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001336
Harald Welte79737b42019-04-10 10:39:30 +02001337 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +02001338 //f_send_gtpu(ctx, c_router_solicit);
1339 //f_send_gtpu(ctx, c_neigh_solicit);
1340
1341 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1342 f_wait_rtr_adv(ctx);
1343 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1344
Harald Welte811651e2017-08-05 15:25:06 +02001345 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001346 f_shutdown_helper();
Harald Welte94ade362017-08-04 00:36:55 +02001347 }
1348
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001349 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
1350 Test we can send ICMPv6 ping over GTPU to DNS server. */
1351 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
1352 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001353 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001354 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1355 f_pdp_ctx_act(ctx);
1356
1357 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1358 f_wait_rtr_adv(ctx);
1359 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1360
1361 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1362
1363 /* Check if we can use valid link-local src addr. */
1364 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1365 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
Pau Espin Pedrolb63d85f2022-02-07 16:11:47 +01001366 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
1367 f_wait_icmp6_echo_reply(ctx);
1368 } else {
1369 f_wait_gtpu_fail(ctx);
1370 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001371
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001372 /* Check if we can use valid global src addr, should work */
1373 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1374 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
1375 f_wait_icmp6_echo_reply(ctx);
1376
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001377 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001378 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001379 }
1380
1381 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1382 testcase TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr() runs on GT_CT {
1383 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001384 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001385 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1386 f_pdp_ctx_act(ctx);
1387
1388 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1389 f_wait_rtr_adv(ctx);
1390 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1391
1392 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1393 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1394 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1395 f_wait_gtpu_fail(ctx);
1396
1397 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001398 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001399 }
1400
1401 /* Assert that packets with wrong global src addr are dropped by GGSN */
1402 testcase TC_pdp6_act_deact_gtpu_access_wrong_global_saddr() runs on GT_CT {
1403 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001404 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001405 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1406 f_pdp_ctx_act(ctx);
1407
1408 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1409 f_wait_rtr_adv(ctx);
1410 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1411
1412 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1413 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001414 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1415 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
1416 f_wait_gtpu_fail(ctx);
1417
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001418 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001419 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001420 }
1421
1422 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped */
1423 testcase TC_pdp6_act_deact_gtpu_access_ipv4_apn6() runs on GT_CT {
1424 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001425 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001426 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1427 f_pdp_ctx_act(ctx);
1428
1429 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1430 f_wait_rtr_adv(ctx);
1431 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1432
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001433 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
1434 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
1435 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
1436 f_wait_gtpu_fail(ctx);
1437
1438 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001439 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001440 }
1441
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001442 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1443 testcase TC_pdp6_clients_interact() runs on GT_CT {
1444 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001445 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1446 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001447 f_pdp_ctx_act(ctxA);
1448 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
1449 f_wait_rtr_adv(ctxA);
1450 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
1451
1452 f_pdp_ctx_act(ctxB);
1453 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
1454 f_wait_rtr_adv(ctxB);
1455 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
1456
1457 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1458 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1459 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1460 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1461
1462 /* Validate if clients can interact using ll addr. */
1463 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1464 f_wait_gtpu_fail(ctxB);
1465
1466 /* Validate if clients can interact using global addr. */
1467 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1468 f_wait_gtpu_fail(ctxB);
1469
1470 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001471 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001472 f_shutdown_helper();
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001473 }
1474
Harald Welte0ef285b2017-08-13 20:06:01 +02001475 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +02001476 testcase TC_pdp4_act_deact() runs on GT_CT {
1477 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001478 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001479 f_pdp_ctx_act(ctx);
1480 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001481 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001482 }
1483
Harald Welte0ef285b2017-08-13 20:06:01 +02001484 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +02001485 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
1486 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001487 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1488 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001489 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001490 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +02001491 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001492 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +01001493 /* verify IPCP is at all contained */
1494 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1495 setverdict(fail, "IPCP not found in PCO");
1496 }
1497 /* verify IPCP contains both primary and secondary DNS */
1498 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001499 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1500 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1501 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1502 } else {
1503 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1504 }
Harald Welte71a36022017-12-04 18:55:58 +01001505 }
Harald Welteed7a1772017-08-09 20:26:20 +02001506 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001507 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001508 }
1509
Harald Weltef8298542019-04-10 10:15:28 +02001510 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
1511 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
1512 f_init();
1513 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1514 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001515 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltef8298542019-04-10 10:15:28 +02001516 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1517 f_pdp_ctx_act(ctx);
1518 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1519 /* verify IPCP is at all contained */
1520 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1521 setverdict(fail, "IPCP not found in PCO");
1522 }
1523 /* verify IPCP contains both primary and secondary DNS */
1524 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1525 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1526 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1527 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1528 } else {
1529 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1530 }
1531 }
1532 /* verify that PAP is contained */
1533 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1534 setverdict(fail, "PAP not found in PCO");
1535 }
1536 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1537 if (not match(pap, tr_PAP_AuthAck)) {
1538 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1539 }
1540 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001541 f_shutdown_helper();
Harald Weltef8298542019-04-10 10:15:28 +02001542 }
1543
Harald Welte0ef285b2017-08-13 20:06:01 +02001544 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001545 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1546 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001547 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001548 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001549 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001550
Harald Welte79737b42019-04-10 10:39:30 +02001551 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001552 /* verify PCO contains both primary and secondary DNS */
1553 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1554 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1555 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1556 }
1557
1558 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1559 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1560 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1561 }
1562
Harald Welteed7a1772017-08-09 20:26:20 +02001563 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001564 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001565 }
1566
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001567 /* Test PDP context activation for dynamic IPv4 EUA.
1568 Test we can send ICMPv6 ping over GTPU to DNS server. */
1569 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1570 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001571 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001572 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1573 f_pdp_ctx_act(ctx);
1574
Harald Welte79737b42019-04-10 10:39:30 +02001575 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001576 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1577
1578 /* Check if we can use valid global src addr, should work */
1579 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1580 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1581 f_wait_icmp4_echo_reply(ctx);
1582
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001583 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001584 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001585 }
1586
1587 /* Assert that packets with wrong global src addr are dropped by GGSN */
1588 testcase TC_pdp4_act_deact_gtpu_access_wrong_saddr() runs on GT_CT {
1589 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001590 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001591 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1592 f_pdp_ctx_act(ctx);
1593
1594 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1595 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1596 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001597 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1598 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1599 f_wait_gtpu_fail(ctx);
1600
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001601 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001602 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001603 }
1604
1605 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1606 testcase TC_pdp4_act_deact_gtpu_access_ipv6_apn4() runs on GT_CT {
1607 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001608 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001609 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1610 f_pdp_ctx_act(ctx);
1611
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001612 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1613 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1614 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1615 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001616
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001617 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001618 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001619 }
1620
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001621 /* Helper function for tests below. */
1622 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001623 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001624 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1625 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001626 f_pdp_ctx_act(ctxA);
1627 f_pdp_ctx_act(ctxB);
1628 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1629 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1630 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1631 f_wait_icmp4_echo_request(ctxB);
1632
1633 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001634 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001635 }
1636
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001637 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1638 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001639 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001640 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001641 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001642 }
1643
1644 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1645 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001646 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001647 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001648 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001649 }
1650
Harald Weltedca80052017-08-13 20:01:38 +02001651 testcase TC_echo_req_resp() runs on GT_CT {
1652 f_init();
1653 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1654 T_default.start;
1655 alt {
1656 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1657 [] GTPC.receive { repeat; };
1658 [] T_default.timeout { setverdict(fail); }
1659 }
1660 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001661 f_shutdown_helper();
Harald Weltedca80052017-08-13 20:01:38 +02001662 }
1663
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001664 testcase TC_echo_req_resp_gtpu() runs on GT_CT {
1665 f_init();
1666 GTPU.send(ts_GTPU_PING(g_peer_u, g_d_seq_nr));
1667 T_default.start;
1668 alt {
1669 [] GTPU.receive(tr_GTPU_PONG(g_peer_u)) { setverdict(pass); };
1670 [] GTPU.receive { repeat; };
1671 [] T_default.timeout { setverdict(fail); }
1672 }
1673 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001674 f_shutdown_helper();
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001675 }
1676
Philipp Maier33e52612018-05-30 17:22:02 +02001677 /* Test if the parser can cope with PCO that only contain either a
1678 * single primary DNS or a secondary DNS. */
1679 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1680
1681 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1682 * the test is executed.
1683 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1684
1685 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001686 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001687 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1688 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1689 var octetstring pco_neg_dns;
1690 var octetstring pco_neg_dns_expected;
1691
1692 /* PCO with primary DNS only */
1693 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1694 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001695 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001696 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1697 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1698 /* Note: The prepended hex bytes encode the following information:
1699 * 0x02 = Configuration ACK
1700 * 0x00 = Identifier
1701 * 0x000a = Length
1702 * 0x81 = Type (Primary DNS Server Address)
1703 * 0x06 = Length
1704 * (4 byte IP-Address appended) */
1705 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1706 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1707 }
1708 f_pdp_ctx_del(ctx, '1'B);
1709
1710 /* PCO with secondary DNS only */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001711 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001712 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1713 f_pdp_ctx_act(ctx);
1714 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1715 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1716 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1717 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1718 }
1719 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001720 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001721 }
1722
1723 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1724 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1725 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1726 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1727
1728 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1729 * the test is executed.
1730 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1731
1732 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001733 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001734 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1735 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1736 var octetstring pco_neg_dns;
1737 var octetstring pco_neg_dns_expected;
1738
1739 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1740 f_pdp_ctx_act(ctx);
1741
1742 /* Check if primary DNS is contained */
1743 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1744 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1745 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1746 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1747 }
Philipp Maier33e52612018-05-30 17:22:02 +02001748
1749 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001750 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1751 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001752 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1753 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1754 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1755 }
1756 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001757 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001758 }
1759
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001760 /* Validate that SUT updates remote TEIC when requested through UpdatePDPContextRequest */
1761 testcase TC_pdp4_act_update_teic() runs on GT_CT {
1762 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001763 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001764 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1765 f_pdp_ctx_act(ctx);
1766
1767 /* UpdatePDPContestRequest changing the local TEIC */
1768 var OCT4 new_teic := ctx.teic;
1769 new_teic[3] := new_teic[3] xor4b '11'O;
1770 f_pdp_ctx_update(ctx, new_teic := new_teic);
1771
1772 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001773 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001774 }
1775
1776 /* Validate that SUT updates remote TEID when requested through UpdatePDPContextRequest */
1777 testcase TC_pdp4_act_update_teid() runs on GT_CT {
1778 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001779 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001780 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1781 f_pdp_ctx_act(ctx);
1782
1783 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1784 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1785 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1786
1787 /* Data is sent (back) to the local TEID established during CreatePDPContext */
1788 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1789 f_wait_icmp4_echo_reply(ctx);
1790
1791 /* UpdatePDPContestRequest changing the local TEID */
1792 var OCT4 new_teid := ctx.teid;
1793 new_teid[3] := new_teid[3] xor4b '11'O;
1794 f_pdp_ctx_update(ctx, new_teid := new_teid);
1795
1796 /* Check if we can send data after updating the PDP context. Answer should be sent to the new TEID */
1797 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1798 f_wait_icmp4_echo_reply(ctx);
1799
1800 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001801 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001802 }
1803
Oliver Smithee6a0882019-03-08 11:05:46 +01001804 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1805 testcase TC_pdp46_act_deact() runs on GT_CT {
1806 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001807 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001808 f_pdp_ctx_act(ctx);
1809 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001810 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001811 }
1812
1813 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1814 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1815 f_init();
1816 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1817 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001818 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001819 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1820 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001821 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001822 /* verify IPCP is at all contained */
1823 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1824 setverdict(fail, "IPCP not found in PCO");
1825 }
Harald Welte79737b42019-04-10 10:39:30 +02001826 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001827 /* verify IPCP contains both primary and secondary IPv4 DNS */
1828 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1829 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1830 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1831 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1832 } else {
1833 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1834 }
1835 }
1836 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001837 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001838 }
1839
1840 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1841 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1842 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001843 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001844 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1845 f_pdp_ctx_act(ctx);
1846
1847 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1848 f_wait_rtr_adv(ctx);
1849 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1850
1851 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001852 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001853 }
1854
1855 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1856 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1857 f_init();
1858
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001859 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001860 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1861 f_pdp_ctx_act(ctx);
1862
Harald Welte79737b42019-04-10 10:39:30 +02001863 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001864 /* verify PCO contains both primary and secondary IPv4 DNS */
1865 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1866 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1867 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1868 }
1869
1870 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1871 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1872 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1873 }
1874
1875 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001876 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001877 }
1878
1879 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1880 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1881 f_init();
1882
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001883 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001884 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1885 f_pdp_ctx_act(ctx);
1886
Harald Welte79737b42019-04-10 10:39:30 +02001887 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001888 /* verify PCO contains both primary and secondary IPv6 DNS */
1889 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1890 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1891 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1892 }
1893
1894 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1895 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1896 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1897 }
1898
1899 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001900 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001901 }
1902
1903 /* Test PDP context activation for dynamic IPv4v6 EUA.
1904 Test we can send ICMPv6 ping over GTPU to DNS server. */
1905 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1906 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001907 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001908 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1909 f_pdp_ctx_act(ctx);
1910
1911 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1912
1913 /* Check if we can use valid global src addr, should work */
1914 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1915 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1916 f_wait_icmp4_echo_reply(ctx);
1917
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001918 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001919 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001920 }
1921
1922 /* Assert that packets with wrong ipv4 src addr are dropped by GGSN on APN IPv4v6 */
1923 testcase TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4() runs on GT_CT {
1924 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001925 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001926 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1927 f_pdp_ctx_act(ctx);
1928
1929 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1930 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
Oliver Smithee6a0882019-03-08 11:05:46 +01001931 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1932 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1933 f_wait_gtpu_fail(ctx);
1934
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001935 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001936 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001937 }
1938
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001939 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1940 testcase TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6() runs on GT_CT {
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001941 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001942 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001943 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1944 f_pdp_ctx_act(ctx);
1945
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001946 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1947 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1948 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1949 f_wait_gtpu_fail(ctx);
1950
1951 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001952 f_shutdown_helper();
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001953 }
1954
1955 /* Assert that packets with wrong ipv6 global src addr are dropped by GGSN on APN IPv4v6 */
1956 testcase TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6() runs on GT_CT {
1957 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001958 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001959 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1960 f_pdp_ctx_act(ctx);
1961
1962 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1963 f_wait_rtr_adv(ctx);
1964 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1965
1966 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1967 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1968 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1969 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
Oliver Smithee6a0882019-03-08 11:05:46 +01001970 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001971
Oliver Smithee6a0882019-03-08 11:05:46 +01001972 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001973 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001974 }
1975
1976 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1977 testcase TC_pdp46_clients_interact() runs on GT_CT {
1978 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001979 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1980 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001981 f_pdp_ctx_act(ctxA);
1982 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1983 f_wait_rtr_adv(ctxA);
1984 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1985
1986 f_pdp_ctx_act(ctxB);
1987 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1988 f_wait_rtr_adv(ctxB);
1989 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1990
1991 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1992 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1993 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1994 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1995
1996 /* Validate if clients can interact using ll addr. */
1997 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1998 f_wait_gtpu_fail(ctxB);
1999
2000 /* Validate if clients can interact using global addr. */
2001 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
2002 f_wait_gtpu_fail(ctxB);
2003
2004 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02002005 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002006 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01002007 }
2008
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002009 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
2010 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002011 const OCT1 cause_accept := '80'O; /* Normal accept cause */
2012 const OCT1 cause_new_pdp_type := '81'O; /* Cause: New PDP type due to network preference */
2013 const OCT1 cause_unknown_pdp := 'DC'O; /* Cause: Unknown PDP address or PDP type */
2014 var CreatePDPContextResponse cpr;
2015
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002016 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002017 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002018 cpr := f_pdp_ctx_act(ctx46, (cause_unknown_pdp, cause_new_pdp_type));
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002019
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002020 if (cpr.cause.causevalue == cause_new_pdp_type) {
2021 /* 3GPP TS 23.060 sec 9.2.1: "If the MS requests PDP type IPv4v6,
2022 * but the operator preferences dictate the use of a single IP
2023 * version only, the PDP type shall be changed to a single address
2024 * PDP type (IPv4 or IPv6) and a reason cause shall be returned to
2025 * the MS indicating that only the assigned PDP type is allowed. In
2026 * this case, the MS shall not request another PDP context for the
2027 * other PDP type during the existence of the PDP context." */
2028 f_pdp_ctx_del(ctx46, '1'B);
2029 } else {
2030 /* 3GPP TS 23.060 sec 9.2.1 NOTE 5: If the MS requests PDP type
2031 * IPv4v6, and the PDP context is rejected due to "unknown PDP
2032 * type", the MS can attempt to establish dual-stack connectivity
2033 * by performing two PDP context request procedures to activate an
2034 * IPv4 PDP context and an IPv6 PDP context, both to the same APN. A
2035 * typical MS first attempts v4v6, and if rejected, then tries v4
2036 * and v6 separetly */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002037 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002038 f_pdp_ctx_act(ctx4, cause_accept); /* Normal accept cause */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002039
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002040 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv6Dyn)));
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002041 f_pdp_ctx_act(ctx6, cause_unknown_pdp); /* Cause: Unknown PDP address or PDP type */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002042
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002043 f_pdp_ctx_del(ctx4, '1'B);
2044 }
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002045 f_shutdown_helper();
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002046 }
2047
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002048 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
2049 testcase TC_pdp_act2_recovery() runs on GT_CT {
2050 var Gtp1cUnitdata ud;
2051 var default d;
2052 var boolean ctxA_deleted := false;
2053 var boolean ctxB_created := false;
2054
2055 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002056 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2057 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002058 f_pdp_ctx_act(ctxA);
2059
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06002060 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002061
2062 log("sending 2nd CreatePDP (recovery increased)");
2063 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
2064 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
2065 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
2066 T_default.start;
2067 d := activate(pingpong());
2068 alt {
2069 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
2070 f_handle_create_req(ctxB, ud);
2071 if (not ctxB_created) {
2072 ctxB_created := true;
2073 setverdict(pass);
2074 } else {
2075 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
2076 }
2077
2078 if (not ctxA_deleted) {
2079 repeat;
2080 }
2081 }
2082 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
2083 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
2084 setverdict(pass);
2085 } else {
2086 setverdict(fail);
2087 }
2088
2089 if (not ctxA_deleted) {
2090 ctxA_deleted := true;
2091 setverdict(pass);
2092 } else {
2093 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
2094 }
2095
2096 if (not ctxB_created) {
2097 repeat;
2098 }
2099 }
2100 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
2101 setverdict(fail, "GGSN dropping still valid pdp ctx");
2102 }
2103 }
2104 deactivate(d);
2105 T_default.stop;
2106
2107 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002108 f_shutdown_helper();
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002109 }
2110
2111
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +01002112 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent responses (T3-RESPONSE * N3-REQUESTS):
2113 * If same delete req is sent and duplicate is detected, saved duplicate response should be sent back. */
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002114 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
2115 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002116 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002117 f_pdp_ctx_act(ctx);
2118 f_pdp_ctx_del(ctx, '1'B);
2119 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +01002120 f_sleep(int2float(mp_t3_response));
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002121 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
2122 duplicate. If it was not a duplicate, osmo-ggsn would answer
2123 with a failure since that PDP ctx was already deleted. */
Pau Espin Pedrold6b51332022-05-19 17:47:11 +02002124 if (g_c_seq_nr == 0) {
2125 g_c_seq_nr := 65535;
2126 } else {
2127 g_c_seq_nr := g_c_seq_nr - 1;
2128 }
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01002129 f_pdp_ctx_del(ctx, '1'B, expect_diameter := false);
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002130
2131 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
2132 var OCT1 cause_nonexistent := 'C0'O;
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01002133 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent, expect_diameter := false);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002134 f_shutdown_helper();
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002135 }
2136
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002137 /* Activate PDP context + trigger Recovery procedure through EchoResp */
2138 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
2139 var Gtp1cUnitdata ud;
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002140 g_use_echo_intval := 5;
2141 timer T_echo;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002142 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002143 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002144 f_pdp_ctx_act(ctx);
2145
2146 /* Wait to receive echo request and send initial Restart counter */
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002147 T_echo.start(int2float(g_use_echo_intval) + 1.0);
2148 alt {
2149 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002150 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
2151 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002152 }
2153 [] T_echo.timeout {
2154 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2155 "Timeout waiting for ping");
2156 }
2157 }
2158 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002159
2160 /* Wait to receive second echo request and send incremented Restart
2161 counter. This will fake a restarted SGSN, and pdp ctx allocated
2162 should be released by GGSN */
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06002163 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002164 T_echo.start(int2float(g_use_echo_intval) + 1.0);
2165 alt {
2166 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002167 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
2168 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002169 }
2170 [] T_echo.timeout {
2171 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2172 "Timeout waiting for ping");
2173 }
2174 }
2175 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002176 f_pdp_ctx_exp_del_req(ctx, omit, true);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002177 f_shutdown_helper();
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002178 }
2179
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002180 /* Test creation, user plane and deletion of big amount (1000) of concurrent PDP context */
2181 testcase TC_lots_of_concurrent_pdp_ctx() runs on GT_CT {
2182 var Gtp1cUnitdata udc;
2183 var Gtp1uUnitdata udu;
2184 const integer num_ctx := 1000;
2185 var PdpContext ctx[num_ctx];
2186 timer T_next := 0.01;
2187 var integer next_req_ctx := 0;
2188 var integer rx_resp_ctx := 0;
2189 var integer rx_pong := 0;
2190 var OCT4 dns1_addr;
2191 var OCT4 saddr;
2192 var integer teic;
2193 var integer idx;
2194
2195 f_init();
2196
2197 for (var integer i := 0; i < num_ctx; i := i + 1) {
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002198 ctx[i] := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234" & int2str(f_rnd_int(4294967296)), c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002199 ctx[i].teic := int2oct(i+1, 4); /* +1: skip TEIC=0 */
2200 ctx[i].teid := int2oct(i+1, 4); /* +1: skip TEID=0 */
2201 ctx[i].pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2202 }
2203
2204 T_default.start(60.0);
2205
2206 T_next.start;
2207 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002208 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002209 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, INITIAL_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002210 [] pingpong();
2211 [] T_next.timeout {
2212 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx[next_req_ctx].imsi, g_restart_ctr,
2213 ctx[next_req_ctx].teid, ctx[next_req_ctx].teic, ctx[next_req_ctx].nsapi,
2214 ctx[next_req_ctx].eua, ctx[next_req_ctx].apn, g_sgsn_ip_c, g_sgsn_ip_u,
2215 ctx[next_req_ctx].msisdn, ctx[next_req_ctx].pco_req, ctx[next_req_ctx].ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002216 ctx[next_req_ctx].uli, ctx[next_req_ctx].charging_char, ctx[next_req_ctx].imeisv,
2217 ctx[next_req_ctx].ms_tz));
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002218 next_req_ctx := next_req_ctx + 1;
2219 if (next_req_ctx < num_ctx) {
2220 T_next.start;
2221 }
2222 repeat;
2223 }
2224 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2225 teic := oct2int(udc.gtpc.teid);
2226 if (not match(teic, (1 .. num_ctx))) {
2227 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2228 "Rx Unexpected TEIC");
2229 }
2230 idx := teic - 1;
2231 f_handle_create_req(ctx[idx], udc);
2232 rx_resp_ctx := rx_resp_ctx + 1;
2233
2234 dns1_addr := f_PCO_extract_proto(ctx[idx].pco_neg, '000d'O);
2235 saddr := ctx[idx].eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2236 f_send_gtpu(ctx[idx], f_gen_icmpv4_echo(saddr, dns1_addr));
2237 repeat;
2238 }
2239 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value udu {
2240 var octetstring gpdu := udu.gtpu.gtpu_IEs.g_PDU_IEs.data;
2241 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
2242 if (ip4.header.ver != 4) {
2243 repeat;
2244 }
2245 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
2246 if (not match(icmp4, (tr_ICMPv4_ERP, tr_ICMPv4_DU))) {
2247 repeat;
2248 }
2249 rx_pong := rx_pong + 1;
2250 if (rx_pong < num_ctx) {
2251 repeat;
2252 }
2253 setverdict(pass);
2254 }
2255 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2256 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2257 }
2258
2259 /* Let's close them now: */
2260 next_req_ctx := 0;
2261 rx_resp_ctx := 0;
2262 T_next.start;
2263 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002264 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002265 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002266 [] pingpong();
2267 [] T_next.timeout {
2268 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));
2269 next_req_ctx := next_req_ctx + 1;
2270 if (next_req_ctx < num_ctx) {
2271 T_next.start;
2272 }
2273 repeat;
2274 }
2275 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2276 teic := oct2int(udc.gtpc.teid);
2277 if (not match(teic, (1 .. num_ctx))) {
2278 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2279 "Rx Unexpected TEIC");
2280 }
2281 rx_resp_ctx := rx_resp_ctx + 1;
2282 if (rx_resp_ctx < num_ctx) {
2283 repeat;
2284 }
2285 setverdict(pass);
2286 }
2287 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2288 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2289 }
2290 T_next.stop;
2291
2292 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002293 f_shutdown_helper();
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002294 }
2295
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002296 /* Test callocation of PDP contexts until reaching addr pool exhaustion */
2297 type record of OCT4 TEIClist;
2298 testcase TC_addr_pool_exhaustion() runs on GT_CT {
2299 var Gtp1cUnitdata udc;
2300 var Gtp1uUnitdata udu;
2301 var PdpContext ctx;
2302 timer T_next := 0.005;
2303 var integer next_req_ctx := 0;
2304 var integer rx_resp_ctx := 0;
2305 var integer num_ctx;
2306 var boolean cont_req := true;
2307 var CreatePDPContextResponse cpr;
2308 var TEIClist teic_list := {};
2309 var integer teic;
2310
2311 f_init();
2312
2313 T_default.start(120.0);
2314
2315 T_next.start;
2316 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002317 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002318 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, INITIAL_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002319 [] pingpong();
2320 [] T_next.timeout {
2321 if (cont_req) {
2322 if (next_req_ctx - rx_resp_ctx < 100) { /* if we have too many in progress, wait a bit to continue */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002323 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234" & int2str(f_rnd_int(4294967296)), c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002324 ctx.nsapi := '0001'B;
2325 ctx.teic := int2oct(next_req_ctx+1, 4); /* +1: skip TEIC=0 */
2326 ctx.teid := int2oct(next_req_ctx+1, 4); /* +1: skip TEID=0 */
2327 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx.imsi, g_restart_ctr,
2328 ctx.teid, ctx.teic, ctx.nsapi,
2329 ctx.eua, ctx.apn, g_sgsn_ip_c, g_sgsn_ip_u,
2330 ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002331 ctx.uli, ctx.charging_char, ctx.imeisv,
2332 ctx.ms_tz));
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002333 next_req_ctx := next_req_ctx + 1;
2334 }
2335 T_next.start;
2336 }
2337 repeat;
2338 }
2339 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2340 cpr := udc.gtpc.gtpc_pdu.createPDPContextResponse;
2341
2342 if (cpr.cause.causevalue == '80'O) {
2343 teic_list := teic_list & {cpr.teidControlPlane.teidControlPlane};
2344 } else {
2345 if (cont_req == true) {
2346 num_ctx := rx_resp_ctx;
2347 log("Successfully created ", num_ctx, " PDP contexts before exhausting the pool");
2348 setverdict(pass);
2349 }
2350 cont_req := false;
2351 }
2352 rx_resp_ctx := rx_resp_ctx + 1;
2353 if (not cont_req and next_req_ctx == rx_resp_ctx) {
2354 break;
2355 } else {
2356 repeat;
2357 }
2358 }
2359 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2360 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2361 }
2362
2363 /* Let's close them now: */
2364 next_req_ctx := 0;
2365 rx_resp_ctx := 0;
2366 T_next.start;
2367 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002368 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002369 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002370 [] pingpong();
2371 [] T_next.timeout {
2372 f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, teic_list[next_req_ctx], '0001'B, '1'B));
2373 next_req_ctx := next_req_ctx + 1;
2374 if (next_req_ctx < num_ctx) {
2375 T_next.start;
2376 }
2377 repeat;
2378 }
2379 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2380 teic := oct2int(udc.gtpc.teid);
2381 if (not match(teic, (1 .. num_ctx))) {
2382 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2383 "Rx Unexpected TEIC");
2384 }
2385 rx_resp_ctx := rx_resp_ctx + 1;
2386 if (rx_resp_ctx < num_ctx) {
2387 repeat;
2388 }
2389 setverdict(pass);
2390 }
2391 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2392 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2393 }
2394 T_next.stop;
2395
2396 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002397 f_shutdown_helper();
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002398 }
2399
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002400 /* Test charging over Gy interface. */
2401 testcase TC_gy_charging_cc_time() runs on GT_CT {
2402 var default d;
2403
2404 g_gy_validity_time := 3; /* Grant access for 3 seconds, needs to be re-validated afterwards */
2405 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002406 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002407 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2408 f_pdp_ctx_act(ctx);
2409
2410 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2411
2412 /* Send some UL traffic: */
2413 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2414 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2415 f_wait_icmp4_echo_reply(ctx);
2416
2417 T_default.start(10.0);
2418 d := activate(pingpong());
2419
2420 g_gy_validity_time := 2;
2421 /* First update reports octests/pkt on both UL/DL (see icmp ping-pong above) */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002422 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002423 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (3..4), 28, 28);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002424
2425 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002426 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002427 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (2..3), 0, 0);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002428
2429 /* Third update: make sure report contains again octets/pkts for both UL/DL: */
2430 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2431 f_wait_icmp4_echo_reply(ctx);
2432 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2433 f_wait_icmp4_echo_reply(ctx);
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002434 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002435 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (2..3), 56, 56);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002436
2437 /* Let the CCA reach the GGSN */
2438 f_sleep(0.5);
2439 deactivate(d);
2440 T_default.stop;
2441
2442 /* Send some data and validate it is reported in the TERMINATION_REQUEST
2443 * (triggered by PFCP Session Deletion Response): */
2444 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2445 f_wait_icmp4_echo_reply(ctx);
2446
2447 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002448 f_validate_gy_cc_report(g_rx_gy, FINAL, (0..2), 28, 28);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002449
2450
2451 f_shutdown_helper();
2452 }
2453
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002454 /* Test Volume-Quota-Thresold AVP triggers request before Validity-Time */
2455 testcase TC_gy_charging_volume_quota_threshold() runs on GT_CT {
2456 var default d;
2457 timer Tout;
2458 g_gy_volume_threshold := 1000; /* Will make a trigger when we send bigger payload below */
2459 g_gy_validity_time := 8; /* Grant access for 8 seconds, needs to be re-validated afterwards */
2460 f_init();
2461 var float tout_sec := int2float(g_gy_validity_time) / 2.0;
2462 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2463 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2464 f_pdp_ctx_act(ctx);
2465
2466 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2467
2468 T_default.start(40.0);
2469 d := activate(pingpong());
2470
2471 /* Send some UL traffic: */
2472 var octetstring payload := f_rnd_octstring(1200);
2473 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2474 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr, payload));
2475 f_wait_icmp4_echo_reply(ctx);
2476
2477 /* ICMP Req generates one report: */
2478 Tout.start(tout_sec);
2479 alt {
2480 [] as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
2481 [] Tout.timeout {
2482 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2483 "TImeout waiting for Gy UPDATE triggered by Volume-Quota-Threshold");
2484 }
2485 }
Pau Espin Pedrol5fa8f782022-10-03 13:57:54 +02002486 f_validate_gy_cc_report(g_rx_gy, THRESHOLD, (0..6), (1200..1400), 0);
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002487
2488 /* ICMP Resp (echo back) generates one report: */
2489 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol5fa8f782022-10-03 13:57:54 +02002490 f_validate_gy_cc_report(g_rx_gy, THRESHOLD, (0..1), 0, (1200..1400));
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002491
2492 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
2493 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
2494 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (8..9), 0, 0);
2495
2496 /* Let the CCA reach the GGSN */
2497 f_sleep(0.5);
2498 deactivate(d);
2499 T_default.stop;
2500
2501 f_pdp_ctx_del(ctx, '1'B);
2502 f_validate_gy_cc_report(g_rx_gy, FINAL, (0..2), 0, 0);
2503
2504
2505 f_shutdown_helper();
2506 }
2507
Harald Welte94ade362017-08-04 00:36:55 +02002508 control {
Harald Welteed7a1772017-08-09 20:26:20 +02002509 execute(TC_pdp4_act_deact());
2510 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02002511 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02002512 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002513 execute(TC_pdp4_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002514 execute(TC_pdp4_act_deact_gtpu_access_wrong_saddr());
2515 execute(TC_pdp4_act_deact_gtpu_access_ipv6_apn4());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02002516 execute(TC_pdp4_clients_interact_with_txseq());
2517 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02002518 execute(TC_pdp4_act_deact_with_single_dns());
2519 execute(TC_pdp4_act_deact_with_separate_dns());
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01002520 execute(TC_pdp4_act_update_teic());
2521 execute(TC_pdp4_act_update_teid());
Harald Welteed7a1772017-08-09 20:26:20 +02002522
2523 execute(TC_pdp6_act_deact());
2524 execute(TC_pdp6_act_deact_pcodns());
2525 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002526 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002527 execute(TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr());
2528 execute(TC_pdp6_act_deact_gtpu_access_wrong_global_saddr());
2529 execute(TC_pdp6_act_deact_gtpu_access_ipv4_apn6());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01002530 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02002531
Oliver Smithee6a0882019-03-08 11:05:46 +01002532 execute(TC_pdp46_act_deact());
2533 execute(TC_pdp46_act_deact_ipcp());
2534 execute(TC_pdp46_act_deact_icmp6());
2535 execute(TC_pdp46_act_deact_pcodns4());
2536 execute(TC_pdp46_act_deact_pcodns6());
2537 execute(TC_pdp46_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002538 execute(TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4());
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01002539 execute(TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002540 execute(TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6());
Oliver Smithee6a0882019-03-08 11:05:46 +01002541 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002542 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01002543
Harald Weltedca80052017-08-13 20:01:38 +02002544 execute(TC_echo_req_resp());
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01002545 execute(TC_echo_req_resp_gtpu());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002546 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002547 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002548
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01002549 execute(TC_pdp_act_restart_ctr_echo());
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002550
2551 execute(TC_lots_of_concurrent_pdp_ctx());
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002552 /* Keep at the end, crashes older osmo-ggsn versions (OS#5469): */
2553 execute(TC_addr_pool_exhaustion());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002554
2555 /* open5gs specific tests: */
2556 if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
2557 execute(TC_gy_charging_cc_time());
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002558 execute(TC_gy_charging_volume_quota_threshold());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002559 }
Harald Welte94ade362017-08-04 00:36:55 +02002560 }
Harald Welte379d45a2017-08-03 09:55:15 +02002561}