blob: a1aab9ba6388175ca79e433d29360d806435259e [file] [log] [blame]
Harald Welte379d45a2017-08-03 09:55:15 +02001module GGSN_Tests {
2
Harald Welte34b5a952019-05-27 11:54:11 +02003/* GGSN test suite in TTCN-3
4 * (C) 2017-2019 Harald Welte <laforge@gnumonks.org>
5 * (C) 2018-2019 sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
Pau Espin Pedrold25095f2022-05-18 16:29:05 +020014 import from TCCEncoding_Functions all;
Harald Welte34b5a952019-05-27 11:54:11 +020015
Harald Welte94ade362017-08-04 00:36:55 +020016 import from General_Types all;
Harald Welte811651e2017-08-05 15:25:06 +020017 import from Osmocom_Types all;
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +010018 import from Misc_Helpers all;
Harald Welte94ade362017-08-04 00:36:55 +020019 import from IPL4asp_PortType all;
20 import from IPL4asp_Types all;
21 import from GTP_CodecPort all;
22 import from GTP_CodecPort_CtrlFunct all;
Harald Weltec69cf4e2018-02-17 20:57:02 +010023 import from GTP_Templates all;
Harald Welte94ade362017-08-04 00:36:55 +020024 import from GTPC_Types all;
25 import from GTPU_Types all;
Harald Welte71a36022017-12-04 18:55:58 +010026 import from IPCP_Types all;
Harald Weltef8298542019-04-10 10:15:28 +020027 import from PAP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020028 import from IP_Types all;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +010029 import from ICMP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020030 import from ICMPv6_Types all;
Harald Welteddeecbb2017-08-18 22:53:30 +020031 import from Native_Functions all;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +020032 import from Osmocom_VTY_Functions all;
33 import from TELNETasp_PortType all;
Harald Welte94ade362017-08-04 00:36:55 +020034
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010035 import from DIAMETER_Types all;
36 import from DIAMETER_Templates all;
Pau Espin Pedrol117a94f2023-12-21 16:10:12 +010037 import from DIAMETER_ts29_272_Templates all;
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010038 import from DIAMETER_Emulation all;
39
Harald Welte94ade362017-08-04 00:36:55 +020040 const integer GTP0_PORT := 3386;
41 const integer GTP1C_PORT := 2123;
42 const integer GTP1U_PORT := 2152;
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010043 const integer PCRF_PORT := 3868;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +010044 const integer OCS_PORT := 3869;
Harald Welteddeecbb2017-08-18 22:53:30 +020045
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010046 type enumerated GGSN_Impl {
47 GGSN_IMPL_OSMOCOM,
48 GGSN_IMPL_OPEN5GS
49 };
50
Harald Welteddeecbb2017-08-18 22:53:30 +020051 modulepar {
Stefan Sperlingcb782b92018-04-03 16:03:15 +020052 /* Default IP addresses. May be overridden by GGSN_Tests configuration files. */
53
54 /* The SGSN simulated by TTCN3 will bind to these addresses for GTP control and GTP user planes. */
Harald Welteddeecbb2017-08-18 22:53:30 +020055 charstring m_bind_ip_gtpc := "127.23.42.1";
56 charstring m_bind_ip_gtpu := "127.23.42.1";
57
Stefan Sperlingcb782b92018-04-03 16:03:15 +020058 /* Addresses the GGSN which is being tested is listening on for SGSN connections. */
Harald Welteddeecbb2017-08-18 22:53:30 +020059 charstring m_ggsn_ip_gtpc := "127.0.0.6";
60 charstring m_ggsn_ip_gtpu := "127.0.0.6";
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010061
Stefan Sperlingcb782b92018-04-03 16:03:15 +020062 /*
63 * Our tests expect to see these DNS servers in 'Create PDP context responses' sent by the GGSN.
64 * These addresses must therefore match 'ip[v6] dns' options configured in osmo-ggsn.conf.
65 *
66 * These addresses are not expected to serve actual DNS requests. However, tests may expect to be
67 * able to ping these addresses (currently, IPv4 addresses must respond with an ICMP 'echo reply',
68 * and IPv6 addresses may respond with either ICMPv6 'echo reply' or 'destination unreachable').
69 */
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010070 charstring m_ggsn_ip4_dns1 := "192.168.100.1"
71 charstring m_ggsn_ip4_dns2 := "8.8.8.8"
Pau Espin Pedrol363ba482018-01-29 18:42:00 +010072 charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888"
73 charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844"
Stefan Sperlingcb782b92018-04-03 16:03:15 +020074
75 /*
76 * Additional address ranges are defined in osmo-ggsn.conf from which addresses are assigned
77 * to MS "behind" the simulated SGSN. These addresses appear on tun devices used by osmo-ggsn.
78 * The tests expect to be able to send ping packets between any two simulated MS within the same
79 * address range. This requires IP forwarding to be enabled on the corresponding tun interfaces.
80 */
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +010081 integer mp_t3_response := 5; /* local T3-RESPONSE timeout, seconds */
82 integer mp_n3_requests := 3; /* local N3-REQUESTS counter */
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010083
84 GGSN_Impl m_ggsn_impl := GGSN_IMPL_OSMOCOM;
Harald Welteddeecbb2017-08-18 22:53:30 +020085 }
Harald Welte94ade362017-08-04 00:36:55 +020086
Harald Welte811651e2017-08-05 15:25:06 +020087 type set PdpContext {
88 hexstring imsi,
89 octetstring msisdn optional,
90 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020091 ProtConfigOptions pco_req optional,
92 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020093 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020094 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020095 BIT4 nsapi,
96 /* TEI (Data) local side */
97 OCT4 teid,
98 /* TEI (Control) local side */
99 OCT4 teic,
100 /* TEI (Data) remote side */
101 OCT4 teid_remote,
102 /* TEI (Control) remote side */
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100103 OCT4 teic_remote,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100104 OCT1 ratType optional,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200105 UserLocationInformation uli optional,
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200106 OCT2 charging_char optional,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200107 OCT8 imeisv optional,
108 MS_TimeZone ms_tz optional
Harald Welte811651e2017-08-05 15:25:06 +0200109 }
110
Harald Welte94ade362017-08-04 00:36:55 +0200111 type component GT_CT {
112 port GTPC_PT GTPC;
113 port GTPU_PT GTPU;
114
Harald Welte0be142b2017-08-13 13:28:10 +0200115 var boolean g_initialized := false;
116
Harald Welte94ade362017-08-04 00:36:55 +0200117 var OCT1 g_restart_ctr := '01'O;
118 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200119 var OCT4 g_sgsn_ip_c;
120 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +0200121 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200122 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
123 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200124 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200125
126 /* next to-be-sent GTP-C sequence number */
127 var uint16_t g_c_seq_nr;
128 /* next to-be-sent GTP-U sequence number */
129 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200130
131 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200132 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100133 var integer g_use_echo_intval := 0; /* 0 = disabled */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100134
Pau Espin Pedrol733369a2022-05-20 18:39:55 +0200135 /* Emulated PCRF, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200136 var DIAMETER_conn_parameters g_gx_pars;
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100137 var DIAMETER_Emulation_CT vc_Gx;
138 port DIAMETER_PT Gx_UNIT;
139 port DIAMETEREM_PROC_PT Gx_PROC;
Pau Espin Pedrol733369a2022-05-20 18:39:55 +0200140
141 /* Emulated OCS, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200142 var DIAMETER_conn_parameters g_gy_pars;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100143 var DIAMETER_Emulation_CT vc_Gy;
144 port DIAMETER_PT Gy_UNIT;
145 port DIAMETEREM_PROC_PT Gy_PROC;
146 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 +0200147 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 +0200148 var PDU_DIAMETER g_rx_gy; /* Store last received Gy message */
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200149 }
150
151 private function f_init_vty() runs on GT_CT {
152 map(self:GGSNVTY, system:GGSNVTY);
153 f_vty_set_prompts(GGSNVTY);
154 f_vty_transceive(GGSNVTY, "enable");
155 }
156
157 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
158 f_vty_enter_config(GGSNVTY);
159 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200160
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200161 f_vty_transceive(GGSNVTY, "apn internet");
162 if (enable) {
163 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
164 } else {
165 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
166 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200167 f_vty_transceive(GGSNVTY, "exit");
168
169 f_vty_transceive(GGSNVTY, "apn inet6");
170 if (enable) {
171 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
172 } else {
173 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
174 }
175 f_vty_transceive(GGSNVTY, "exit");
176
177 f_vty_transceive(GGSNVTY, "apn inet46");
178 if (enable) {
179 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
180 } else {
181 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
182 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200183 f_vty_transceive(GGSNVTY, "end");
184 }
185
186 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
187 if (expect_gptu_txseq) {
188 if (gtpu.s_bit != '1'B) {
189 log("GTPU sequence number expected but not present")
190 return false;
191 }
192 } else {
193 if (gtpu.s_bit != '0'B) {
194 log("GTPU sequence number not expected but present")
195 return false;
196 }
197 }
198 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200199 }
200
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100201 private function f_vty_enable_echo_interval(integer intval_sec) runs on GT_CT {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200202 f_vty_enter_config(GGSNVTY);
203 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100204 if (intval_sec > 0) {
205 f_vty_transceive(GGSNVTY, "echo-interval " & int2str(intval_sec));
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200206 } else {
207 f_vty_transceive(GGSNVTY, "no echo-interval");
208 }
209 f_vty_transceive(GGSNVTY, "end");
210 }
211
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100212 private function DiameterForwardUnitdataCallback(PDU_DIAMETER msg)
213 runs on DIAMETER_Emulation_CT return template PDU_DIAMETER {
214 DIAMETER_UNIT.send(msg);
215 return omit;
216 }
217
218 private function f_init_diameter(charstring id) runs on GT_CT {
219 var DIAMETEROps ops := {
220 create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback),
221 unitdata_cb := refers(DiameterForwardUnitdataCallback),
222 raw := true /* handler mode (single component for all IMSI)) */
223 };
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100224
225 /* Gx setup: */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200226 g_gx_pars := {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100227 remote_ip := m_ggsn_ip_gtpc,
228 remote_sctp_port := -1,
229 local_ip := m_bind_ip_gtpc,
230 local_sctp_port := PCRF_PORT,
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100231 origin_host := "pcrf.localdomain",
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100232 origin_realm := "localdomain",
Pau Espin Pedrol33b47492022-03-08 17:43:01 +0100233 auth_app_id := omit,
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100234 vendor_app_id := c_DIAMETER_3GPP_Gx_AID
235 };
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100236 vc_Gx := DIAMETER_Emulation_CT.create(id);
237 map(vc_Gx:DIAMETER, system:DIAMETER_CODEC_PT);
238 connect(vc_Gx:DIAMETER_UNIT, self:Gx_UNIT);
239 connect(vc_Gx:DIAMETER_PROC, self:Gx_PROC);
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200240 vc_Gx.start(DIAMETER_Emulation.main(ops, g_gx_pars, id));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100241
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100242 /* Gy setup: */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200243 g_gy_pars := {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100244 remote_ip := m_ggsn_ip_gtpc,
245 remote_sctp_port := -1,
246 local_ip := m_bind_ip_gtpc,
247 local_sctp_port := OCS_PORT,
248 origin_host := "ocs.localdomain",
249 origin_realm := "localdomain",
250 auth_app_id := c_DIAMETER_CREDIT_CONTROL_AID,
251 vendor_app_id := omit
252 };
253 vc_Gy := DIAMETER_Emulation_CT.create(id);
254 map(vc_Gy:DIAMETER, system:DIAMETER_CODEC_PT);
255 connect(vc_Gy:DIAMETER_UNIT, self:Gy_UNIT);
256 connect(vc_Gy:DIAMETER_PROC, self:Gy_PROC);
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200257 vc_Gy.start(DIAMETER_Emulation.main(ops, g_gy_pars, id));
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100258
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100259 f_diameter_wait_capability(Gx_UNIT);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100260 f_diameter_wait_capability(Gy_UNIT);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100261 /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdong ping-pongs):
262 * RFC6733 sec 5.1
263 * RFC3539 sec 3.4.1 [5]
264 * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49
265 */
266 f_sleep(1.0);
267 }
268
Harald Welte94ade362017-08-04 00:36:55 +0200269 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200270 if (g_initialized == true) {
271 return;
272 }
273 g_initialized := true;
274
Harald Welteddeecbb2017-08-18 22:53:30 +0200275 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
276 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
277
Harald Welte94ade362017-08-04 00:36:55 +0200278 var Result res;
279 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +0200280 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200281 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200282 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200283
284 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +0200285 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200286 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200287
288 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200289 g_c_seq_nr := f_rnd_int(65535);
290 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200291
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100292 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
293 f_init_vty();
294 f_vty_set_gpdu_txseq(use_gtpu_txseq);
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100295 f_vty_enable_echo_interval(g_use_echo_intval);
Oliver Smith95722c62023-10-20 13:59:10 +0200296 /* Emit a marker to appear in the SUT's own logging output */
297 f_logp(GGSNVTY, testcasename() & "() start");
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100298 } else if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
299 f_init_diameter(testcasename());
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100300 }
Harald Welte94ade362017-08-04 00:36:55 +0200301 }
302
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100303 function f_shutdown_helper() runs on GT_CT {
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +0100304 /* Sleep (T3-RESPONSE * N3-REQUESTS) seconds.
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100305 * This ensures all retransmit queues are cleared before jumping
306 * into next tests, hence avoding situation where a test resuses
307 * a seqnum still in the GGSN's resp queue (dup req detector).
308 * See OS#5485 avout decreasing time. We could also add a new
309 * VTY command that calls gtp_clear_queues() */
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +0100310 f_sleep(int2float(mp_t3_response * mp_n3_requests));
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100311 setverdict(pass);
312 }
313
Harald Welte94ade362017-08-04 00:36:55 +0200314 /* Altstep implementing responses to any incoming echo requests */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100315 private altstep pingpong() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200316 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200317 var Gtp1uUnitdata udu;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100318 [g_use_echo_intval > 0] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200319 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200320 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200321 repeat;
322 };
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100323 [g_use_echo_intval == 0] GTPC.receive(tr_GTPC_PING(?)) {
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100324 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
325 "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200326 };
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100327 [] T_default.timeout {
328 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
329 "pinpong T_default timeout");
330 };
Harald Welte94ade362017-08-04 00:36:55 +0200331 }
332
Harald Welte811651e2017-08-05 15:25:06 +0200333 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200334 const octetstring c_ApnInternet := '08696E7465726E6574'O;
335 const octetstring c_ApnInet6 := '05696E657436'O;
336 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200337
Harald Welte811651e2017-08-05 15:25:06 +0200338 /* return random NSAPI */
339 function f_rnd_nsapi() return BIT4 {
340 return int2bit(f_rnd_int(16), 4);
341 }
342
343 /* return random TEI[DC] */
344 function f_rnd_tei() return OCT4 {
345 return int2oct(f_rnd_int(4294967296), 4);
346 }
347
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200348 /* return random IMEI(SV) */
349 function f_rnd_imeisv() return OCT8 {
350 return hex2oct(f_rnd_hexstring(16, 10));
351 }
352
Harald Welte811651e2017-08-05 15:25:06 +0200353 /* define an (internal) representation of a PDP context */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +0200354 template PdpContext t_DefinePDP(hexstring imsi, charstring msisdn, octetstring apn,
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100355 EndUserAddress eua, OCT1 ratType := '02'O /* GERAN */) := {
Harald Welte811651e2017-08-05 15:25:06 +0200356 imsi := imsi,
Pau Espin Pedrold25095f2022-05-18 16:29:05 +0200357 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 +0200358 nsapi := f_rnd_nsapi(),
359 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200360 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200361 eua := eua,
362 teid := f_rnd_tei(),
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100363 teic := f_rnd_tei(),
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100364 ratType := ratType,
365 uli := {
366 type_gtpc := '98'O,
367 lengthf := 0 /* filled in by encoder */,
368 geographicLocationType := '00'O /* CGI */,
369 geographicLocation := {
370 geographicLocationCGI := ts_GeographicLocationCGI('262'H, '42F'H, '0001'O, '0002'O)
371 }
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200372 },
Pau Espin Pedrol38968e92022-05-13 16:17:48 +0200373 charging_char := '0000'O,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200374 imeisv := f_rnd_imeisv(),
375 ms_tz := f_ts_MS_TimeZone('03'O, '01'B)
Harald Welte811651e2017-08-05 15:25:06 +0200376 }
377
378 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200379 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200380 GTPC.send(data);
Pau Espin Pedrol82a7f702022-05-19 17:41:29 +0200381 g_c_seq_nr := (g_c_seq_nr + 1) mod 65536;
Harald Welte811651e2017-08-05 15:25:06 +0200382 }
383
384 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200385 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200386 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200387 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
Pau Espin Pedrol82a7f702022-05-19 17:41:29 +0200388 g_d_seq_nr := (g_d_seq_nr + 1) mod 65536;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200389 } else {
390 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
391 }
Harald Welte811651e2017-08-05 15:25:06 +0200392 }
393
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100394 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 +0200395 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100396
397 if (not match(cpr.cause.causevalue, exp_cause)) {
398 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
399 "CreatePDPContextResp: cause expectancies didn't match");
400 }
401
402 if (cpr.cause.causevalue == '80'O) { /* Accepted */
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200403 /* Check if EUA type corresponds to requested type */
404 if (match(ctx.eua, t_EuaIPv4(?)) and
405 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100406 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
407 "EUAv4 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200408 }
409 if (match(ctx.eua, t_EuaIPv6(?)) and
410 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100411 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
412 "EUAv6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200413 }
414 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
415 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100416 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
417 "EUAv4v6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200418 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100419 } else if (cpr.cause.causevalue == '81'O) { /* Cause: New PDP type due to network preference */
420 /* ETSI TS 129 060 7.3.2 Create PDP Context Response. OS#5449 */
421 /* This should only happen if EUA requested type is v4v6: */
422 if (not ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
423 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
424 "Cause not expected when requesting a non v4v6 EUA");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200425 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100426 if (not match(cpr.endUserAddress, (tr_EuaIPv4(?), tr_EuaIPv6(?)))) {
427 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
428 "Cause not expected when requesting+receiving EUAv4v6");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200429 }
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200430 } else {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100431 if (ispresent(cpr.endUserAddress)) {
432 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
433 "EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
434 }
435 setverdict(pass);
436 return;
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200437 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100438
439 /* Check if PCO response corresponds to request */
440 if (ispresent(ctx.pco_req)) {
441 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
442 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
443 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
444 "IPv4 DNS Container requested, but missing");
445 }
446 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
447 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
448 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
449 "IPv6 DNS Container requested, but missing");
450 }
451 }
452 ctx.teid_remote := cpr.teidDataI.teidDataI;
453 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
454 ctx.eua := cpr.endUserAddress;
455 ctx.pco_neg := cpr.protConfigOptions;
456 setverdict(pass);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200457 }
458
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100459 function f_handle_update_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
460 var UpdatePDPContextResponseGGSN upr := ud.gtpc.gtpc_pdu.updatePDPContextResponse.updatePDPContextResponseGGSN;
461 if (exp_cause == '80'O and exp_cause == upr.cause.causevalue) {
462 ctx.teid_remote := upr.teidDataI.teidDataI;
463 ctx.teic_remote := upr.teidControlPlane.teidControlPlane;
464 if (ispresent(upr.protConfigOptions)) {
465 ctx.pco_neg := upr.protConfigOptions;
466 }
467 setverdict(pass);
468 } else if (exp_cause != '80'O and exp_cause == upr.cause.causevalue) {
469 setverdict(pass);
470 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
472 "UpdatePDPContextResp: cause expectancies didn't match");
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100473 }
474 }
475
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100476 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 +0100477 var PDU_DIAMETER rx_dia;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100478 [] Gx_UNIT.receive(tr_DIA_Gx_CCR(req_type := req_type)) -> value rx_dia {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100479 var template (omit) AVP avp;
480 var octetstring sess_id;
481 var AVP_Unsigned32 req_num;
482
483 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
484 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
485
486 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
487 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
488
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100489 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 +0100490 req_type, req_num));
491 }
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100492 [] Gx_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100493 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
494 log2str("Received unexpected DIAMETER ", rx_dia));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100495 }
496 }
497
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200498 private function f_tr_DIA_Gy_CCR(template (omit) PdpContext ctx, DCC_NONE_CC_Request_Type req_type)
499 runs on GT_CT return template (present) PDU_DIAMETER
500 {
501 var template (present) PDU_DIAMETER tpl;
502 var charstring smf_origin_host := "smf.localdomain";
503 var template (present) octetstring imsi := ?;
504 var template (present) octetstring msisdn := ?;
505 var template (present) octetstring imeisv := ?;
506 var template (present) octetstring rat_type := ?;
507 var template (present) OCT4 charging_char := ?;
508 var template (present) OCT1 nsapi := ?;
509 if (not istemplatekind(ctx, "omit")) {
510 var PdpContext ctx_val := valueof(ctx);
511 imsi := char2oct(f_dec_TBCD(imsi_hex2oct(ctx_val.imsi)));
512 msisdn := char2oct(f_dec_TBCD(substr(ctx_val.msisdn, 1, lengthof(ctx_val.msisdn) -1)));
513 imeisv := char2oct(f_dec_TBCD(ctx_val.imeisv));
514 rat_type := ctx_val.ratType;
515 charging_char := char2oct(oct2str(ctx_val.charging_char));
516 nsapi := char2oct(hex2str(bit2hex(ctx_val.nsapi)));
517 }
518 select (req_type) {
519 case (INITIAL_REQUEST) {
520 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
521 avps := superset(
522 tr_AVP_SessionId,
523 tr_AVP_OriginHost(smf_origin_host),
524 tr_AVP_OriginRealm(g_gy_pars.origin_realm),
525 tr_AVP_DestinationRealm(g_gy_pars.origin_realm),
526 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
527 tr_AVP_ServiceContextId,
528 tr_AVP_CcReqType(req_type),
529 tr_AVP_CcReqNum(?),
530 tr_AVP_EventTimestamp(?),
531 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
532 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
533 tr_AVP_RequestedAction(DIRECT_DEBITING),
534 tr_AVP_3GPP_AoCRequestType,
535 tr_AVP_MultipleServicesIndicator,
536 tr_AVP_Multiple_Services_Credit_Control(content := superset(
537 tr_AVP_Requested_Service_Unit,
Pau Espin Pedrol6477d732022-06-03 12:04:40 +0200538 tr_AVP_PCC_3GPP_QoS_Information,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200539 tr_AVP_GI_3GPP_RatType(rat_type)
540 )),
541 tr_AVP_3GPP_ServiceInformation(content := superset(
542 tr_AVP_3GPP_PSInformation(content := superset(
543 tr_AVP_3GPP_ChargingId,
544 tr_AVP_3GPP_PDPType((IPv4,IPv6,IPv4v6)),
545 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
546 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_bind_ip_gtpc))),
547 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_ggsn_ip_gtpc))),
548 tr_AVP_3GPP_CalledStationId,
549 tr_AVP_3GPP_SelectionMode,
550 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
551 tr_AVP_3GPP_SGSNMCCMNC,
552 tr_AVP_3GPP_NSAPI(nsapi),
553 tr_AVP_3GPP_MS_TimeZone,
554 tr_AVP_3GPP_ULI,
555 tr_AVP_UserEquipmentInfo({
556 tr_AVP_UserEquipmentInfoType(IMEISV),
557 tr_AVP_UserEquipmentInfoValue(imeisv)
558 })
559 ))
560 ))
561 ));
562 }
563 case (UPDATE_REQUEST) {
564 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
565 avps := superset(
566 tr_AVP_SessionId,
567 tr_AVP_OriginHost(smf_origin_host),
568 tr_AVP_OriginRealm(g_gy_pars.origin_realm),
569 tr_AVP_DestinationRealm(g_gy_pars.origin_realm),
570 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
571 tr_AVP_ServiceContextId,
572 tr_AVP_CcReqType(req_type),
573 tr_AVP_CcReqNum(?),
574 tr_AVP_DestinationHost(?),
575 tr_AVP_EventTimestamp(?),
576 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
577 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
578 tr_AVP_RequestedAction(DIRECT_DEBITING),
579 tr_AVP_3GPP_AoCRequestType,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200580 tr_AVP_Multiple_Services_Credit_Control(content := superset(
581 tr_AVP_Requested_Service_Unit,
582 tr_AVP_Used_Service_Unit,
Pau Espin Pedrolcba0f6d2022-05-24 13:49:46 +0200583 /* tr_AVP_3GPP_Reporting_Reason, can be sometimes inside UsedServiceUnit */
Pau Espin Pedrol6477d732022-06-03 12:04:40 +0200584 tr_AVP_PCC_3GPP_QoS_Information,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200585 tr_AVP_GI_3GPP_RatType(rat_type)
586 )),
587 tr_AVP_3GPP_ServiceInformation(content := superset(
588 tr_AVP_3GPP_PSInformation(content := superset(
589 tr_AVP_3GPP_ChargingId,
590 /* tr_AVP_3GPP_PDPType, Only in INIT */
591 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
592 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_bind_ip_gtpc))),
593 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_ggsn_ip_gtpc))),
594 tr_AVP_3GPP_CalledStationId,
595 tr_AVP_3GPP_SelectionMode,
596 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
597 tr_AVP_3GPP_SGSNMCCMNC,
598 tr_AVP_3GPP_NSAPI(nsapi),
599 tr_AVP_3GPP_MS_TimeZone,
600 tr_AVP_3GPP_ULI,
601 tr_AVP_UserEquipmentInfo({
602 tr_AVP_UserEquipmentInfoType(IMEISV),
603 tr_AVP_UserEquipmentInfoValue(imeisv)
604 })
605 ))
606 ))
607 ));
608 }
609 case (TERMINATION_REQUEST) {
610 tpl := tr_DIAMETER(flags:='11000000'B, cmd_code:=Credit_Control,
611 avps := superset(
612 tr_AVP_SessionId,
613 tr_AVP_OriginHost(smf_origin_host),
614 tr_AVP_OriginRealm(g_gy_pars.origin_realm),
615 tr_AVP_DestinationRealm(g_gy_pars.origin_realm),
616 tr_AVP_AuthAppId(int2oct(c_DIAMETER_CREDIT_CONTROL_AID, 4)),
617 tr_AVP_ServiceContextId,
618 tr_AVP_CcReqType(req_type),
619 tr_AVP_CcReqNum(?),
620 tr_AVP_DestinationHost(?),
621 tr_AVP_EventTimestamp(?),
622 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_IMSI), tr_AVP_SubcrIdData(imsi)}),
623 tr_AVP_SubcrId({tr_AVP_SubcrIdType(END_USER_E164), tr_AVP_SubcrIdData(msisdn)}),
624 tr_AVP_TerminationCause(?),
625 tr_AVP_RequestedAction(DIRECT_DEBITING),
626 tr_AVP_3GPP_AoCRequestType,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200627 tr_AVP_Multiple_Services_Credit_Control(content := superset(
628 /* tr_AVP_Requested_Service_Unit, Only in INIT and UPDATE */
629 tr_AVP_Used_Service_Unit,
Pau Espin Pedrolcba0f6d2022-05-24 13:49:46 +0200630 tr_AVP_3GPP_Reporting_Reason(FINAL),
Pau Espin Pedrol6477d732022-06-03 12:04:40 +0200631 tr_AVP_PCC_3GPP_QoS_Information,
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200632 tr_AVP_GI_3GPP_RatType(rat_type)
633 )),
634 tr_AVP_3GPP_ServiceInformation(content := superset(
635 tr_AVP_3GPP_PSInformation(content := superset(
636 tr_AVP_3GPP_ChargingId,
637 /* tr_AVP_3GPP_PDPType, Only in INIT */
638 tr_AVP_3GPP_PDPAddress(tr_AVP_Address((IP,IP6), ?)),
639 tr_AVP_3GPP_SGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_bind_ip_gtpc))),
640 tr_AVP_3GPP_GGSNAddress(tr_AVP_Address(IP, f_inet_addr(m_ggsn_ip_gtpc))),
641 tr_AVP_3GPP_CalledStationId,
642 tr_AVP_3GPP_SelectionMode,
643 tr_AVP_3GPP_ChargingCharacteristics(charging_char),
644 tr_AVP_3GPP_SGSNMCCMNC,
645 tr_AVP_3GPP_NSAPI(nsapi),
646 tr_AVP_3GPP_MS_TimeZone,
647 tr_AVP_3GPP_ULI,
648 tr_AVP_UserEquipmentInfo({
649 tr_AVP_UserEquipmentInfoType(IMEISV),
650 tr_AVP_UserEquipmentInfoValue(imeisv)
651 })
652 ))
653 ))
654 ));
655 }
656 }
657 return tpl;
658 }
659
660 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 +0200661 [] 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 +0100662 var template (value) PDU_DIAMETER tx_dia;
663 var template (omit) AVP avp;
664 var octetstring sess_id;
665 var AVP_Unsigned32 req_num;
666
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200667 avp := f_DIAMETER_get_avp(g_rx_gy, c_AVP_Code_BASE_NONE_Session_Id);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100668 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
669
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200670 avp := f_DIAMETER_get_avp(g_rx_gy, c_AVP_Code_DCC_NONE_CC_Request_Number);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100671 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
672 if (g_gy_validity_time > 0) {
Pau Espin Pedrol52562c92022-05-23 15:45:46 +0200673 if (g_gy_volume_threshold > 0) {
674 tx_dia := ts_DIA_Gy_CCA_ValidityTimeVolumeThreshold(g_rx_gy.hop_by_hop_id, g_rx_gy.end_to_end_id, sess_id,
675 req_type, req_num, g_gy_validity_time, g_gy_volume_threshold);
676 } else {
677 tx_dia := ts_DIA_Gy_CCA_ValidityTime(g_rx_gy.hop_by_hop_id, g_rx_gy.end_to_end_id, sess_id,
678 req_type, req_num, g_gy_validity_time);
679 }
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100680 } else {
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200681 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 +0100682 req_type, req_num);
683 }
684 Gy_UNIT.send(tx_dia);
685 }
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200686 [] Gy_UNIT.receive(PDU_DIAMETER:?) -> value g_rx_gy {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100687 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +0200688 log2str("Received unexpected DIAMETER Gy", g_rx_gy));
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100689 }
690 }
691
Harald Welte811651e2017-08-05 15:25:06 +0200692 /* send a PDP context activation */
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100693 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 +0200694 var Gtp1cUnitdata ud;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100695 var CreatePDPContextResponse cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200696 var default d;
697
698 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200699 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 +0200700 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Pau Espin Pedrol0e127872022-05-12 17:58:50 +0200701 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +0200702 ctx.uli, ctx.charging_char, ctx.imeisv, ctx.ms_tz));
Harald Welte94ade362017-08-04 00:36:55 +0200703 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200704 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100705 if (Gx_PROC.checkstate("Connected")) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100706 as_DIA_Gx_CCR(INITIAL_REQUEST);
707 }
708 if (Gy_PROC.checkstate("Connected")) {
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200709 as_DIA_Gy_CCR(ctx, INITIAL_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100710 }
Harald Welte94ade362017-08-04 00:36:55 +0200711 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200712 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200713 f_handle_create_req(ctx, ud, exp_cause);
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100714 cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Harald Welte94ade362017-08-04 00:36:55 +0200715 }
716 }
717 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200718 T_default.stop;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100719 return cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200720 }
721
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200722 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
723 var Gtp1cUnitdata ud;
724 var default d;
725
726 T_default.start;
727 d := activate(pingpong());
728 alt {
729 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
730 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
731 setverdict(pass);
732 } else if (not istemplatekind(expect_cause, "omit") and
733 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
734 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
735 setverdict(pass);
736 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100737 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
738 "DeletePDPContextReq: cause expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200739 }
740
741 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
742 setverdict(pass);
743 } else {
744 setverdict(fail);
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100745 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
746 "DeletePDPContextReq: tearDownIndicator expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200747 }
748 }
749 }
750 deactivate(d);
751 T_default.stop;
752 }
753
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +0100754 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 +0200755 var Gtp1cUnitdata ud;
756 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200757 var OCT4 expect_teid;
758
759 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
760 message with cause value "Non existent" shall be zero. */
761 if (expect_causevalue == 'C0'O) {
762 expect_teid := '00000000'O;
763 } else {
764 expect_teid := ctx.teic;
765 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200766
Harald Welte41575e92017-08-13 13:49:57 +0200767 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 +0200768 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200769 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100770 if (Gx_PROC.checkstate("Connected") and expect_diameter) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100771 as_DIA_Gx_CCR(TERMINATION_REQUEST);
772 }
773 if (Gy_PROC.checkstate("Connected") and expect_diameter) {
Pau Espin Pedrola2af5782022-05-18 16:34:29 +0200774 as_DIA_Gy_CCR(ctx, TERMINATION_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100775 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200776 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200777 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
778 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200779 setverdict(pass);
780 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100781 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
782 "DeletePDPContextResp: cause expectancies didn't match");
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200783 }
784 }
785 }
786 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200787 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200788 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100789
790 /* send a Update PdP Context Request, expect Response */
791 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 {
792 var Gtp1cUnitdata ud;
793 var default d;
794
795 if (not istemplatekind(new_teid, "omit")) {
796 ctx.teid := valueof(new_teid);
797 }
798 if (not istemplatekind(new_teic, "omit")) {
799 ctx.teic := valueof(new_teic);
800 }
801
802 log("sending UpdatePDP");
803 f_send_gtpc(ts_GTPC_UpdatePDP(g_peer_c, ctx.teic_remote, g_c_seq_nr, ctx.imsi, g_restart_ctr,
804 ctx.teid, ctx.teic, ctx.nsapi, g_sgsn_ip_c, g_sgsn_ip_u,
805 ctx.pco_req, ctx.ratType, ctx.uli));
806 T_default.start;
807 d := activate(pingpong());
808 alt {
809 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, updatePDPContextResponse, ctx.teic)) -> value ud {
810 f_handle_update_req(ctx, ud, exp_cause);
811 }
812 }
813 deactivate(d);
814 T_default.stop;
815 }
816
Harald Welte811651e2017-08-05 15:25:06 +0200817 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
818 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
819 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
820 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200821
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200822 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100823 template (value) PDU_ICMP ts_ICMPv4_ERQ(octetstring data := ''O) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100824 echo := {
825 type_field := 8,
826 code := 0,
827 checksum := '0000'O,
828 identifier := '0345'O,
829 sequence_number := '0001'O,
Pau Espin Pedrol52562c92022-05-23 15:45:46 +0200830 data := data
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100831 }
832 }
833
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200834 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100835 template (present) PDU_ICMP tr_ICMPv4_ERQ := {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100836 echo := {
837 type_field := 8,
838 code := 0,
839 checksum := ?,
840 identifier := ?,
841 sequence_number := ?,
842 data := ?
843 }
844 }
845
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200846 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100847 template (present) PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100848 echo_reply := {
849 type_field := 0,
850 code := 0,
851 checksum := ?,
852 identifier := ?,
853 sequence_number := ?,
854 data := data
855 }
856 }
857
858 /* template for receiving/matching an ICMPv6 Destination Unreachable */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100859 template (present) PDU_ICMP tr_ICMPv4_DU := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100860 destination_unreachable := {
861 type_field := 1,
862 code := ?,
863 checksum := ?,
864 unused := ?,
865 original_ip_msg := ?
866 }
867 }
868
869 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100870 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 +0100871 header := {
872 ver := 4,
873 hlen := 5,
874 tos := 0,
875 tlen := tlen,
876 id := 35902,
877 res := '0'B,
878 dfrag := '1'B,
879 mfrag := '0'B,
880 foffset := 0,
881 ttl := 64,
882 proto := proto,
883 cksum := 0,
884 srcaddr := srcaddr,
885 dstaddr := dstaddr
886 },
887 ext_headers := omit,
888 payload := payload
889 }
890
Harald Welte231b9412017-08-09 17:16:31 +0200891 /* template to generate a 'Prefix Information' ICMPv6 option */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100892 template (value) OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200893 prefixInformation := {
894 typeField := 3,
895 lengthIndicator := 8,
896 prefixLength := prefix_len,
897 reserved1 := '000000'B,
898 a_Bit := '0'B,
899 l_Bit := '0'B,
900 validLifetime := oct2int('FFFFFFFF'O),
901 preferredLifetime := oct2int('FFFFFFFF'O),
902 reserved2 := '00000000'O,
903 prefix := prefix
904 }
905 }
906
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200907 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100908 template (value) PDU_ICMPv6 ts_ICMPv6_ERQ := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100909 echoRequest := {
910 typeField := 128,
911 code := 0,
912 checksum := '0000'O,
913 identifier := 0,
914 sequenceNr := 0,
915 data := ''O
916 }
917 }
918
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200919 /* template for sending an ICMPv6 router solicitation */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100920 template (value) PDU_ICMPv6 ts_ICMPv6_RS := {
Harald Welte231b9412017-08-09 17:16:31 +0200921 routerSolicitation := {
922 typeField := 133,
923 code := 0,
924 checksum := '0000'O,
925 reserved := '00000000'O,
926 /* TODO: do we need 'Source link-layer address' ? */
927 options := omit
928 }
929 }
930
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200931 /* template for sending an ICMPv6 router advertisement */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100932 template (value) PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200933 routerAdvertisement := {
934 typeField := 134,
935 code := 0,
936 checksum := '0000'O,
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100937 curHopLimit := 0,
Harald Welte231b9412017-08-09 17:16:31 +0200938 reserved := '000000'B,
939 o_Bit := '0'B,
940 m_Bit := '0'B,
941 routerLifetime := oct2int('FFFF'O),
942 reachableTime := oct2int('FFFFFFFF'O),
943 retransTimer := oct2int('FFFFFFFF'O),
944 options := {
945 ts_ICMP6_OptPrefix(prefix, prefix_len)
946 }
947 }
948 }
949
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200950 /* template for sending an ICMPv6 neighbor solicitation */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100951 template (value) PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
Harald Welte231b9412017-08-09 17:16:31 +0200952 neighborSolicitation := {
953 typeField := 135,
954 code := 0,
955 checksum := '0000'O,
956 reserved := '00000000'O,
957 targetAddress := target_addr,
958 /* TODO: do we need 'Source link-layer address' ? */
959 options := omit
960 }
961 }
962
963 /* derive ICMPv6 link-local address from lower 64bit of link_id */
964 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100965 template (present) OptionField tr_ICMP6_OptPrefix(template (present) OCT16 prefix, template (present) INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200966 prefixInformation := {
967 typeField := 3,
968 lengthIndicator := 4,
969 prefixLength := prefix_len,
970 reserved1 := ?,
971 a_Bit := ?,
972 l_Bit := ?,
973 validLifetime := ?,
974 preferredLifetime := ?,
975 reserved2 := ?,
976 prefix := prefix
977 }
978 }
979
Pau Espin Pedrolae04c792023-12-05 14:51:42 +0100980 /* template for receiving/matching an ICMPv6 'MTU' option, rfc4861 4.6.4 */
981 template (present) OptionField tr_ICMP6_OptMTU(template (present) integer mtu := ?) := {
982 mTU := {
983 typeField := 5,
984 lengthIndicator := 1,
985 reserved := ?,
986 mTU_Value := mtu
987 }
988 }
989
Harald Welte231b9412017-08-09 17:16:31 +0200990 /* template for receiving/matching an ICMPv6 router advertisement */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +0100991 template (present) PDU_ICMPv6 tr_ICMPv6_RA(template (present) OCT16 prefix, template (present) INT1 prefix_len) := {
Harald Welte231b9412017-08-09 17:16:31 +0200992 routerAdvertisement := {
993 typeField := 134,
994 code := 0,
995 checksum := ?,
996 curHopLimit := ?,
997 reserved := ?,
998 o_Bit := '0'B,
999 m_Bit := '0'B,
1000 routerLifetime := ?,
1001 reachableTime := ?,
1002 retransTimer := ?,
Pau Espin Pedrolae04c792023-12-05 14:51:42 +01001003 options := ({ tr_ICMP6_OptPrefix(prefix, prefix_len) },
1004 { tr_ICMP6_OptPrefix(prefix, prefix_len), tr_ICMP6_OptMTU }
1005 )
Harald Welte231b9412017-08-09 17:16:31 +02001006 }
1007 }
1008
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001009 /* template for receiving/matching an ICMPv6 Destination Unreachable */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001010 template (present) PDU_ICMPv6 tr_ICMPv6_DU := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001011 destinationUnreachable := {
1012 typeField := 1,
1013 code := ?,
1014 checksum := ?,
1015 unused := ?,
1016 originalIpMsg := ?
1017 }
1018 }
1019
Stefan Sperling6cd217e2018-03-30 15:17:34 +02001020 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001021 template (present) PDU_ICMPv6 tr_ICMPv6_ERQ := {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001022 echoRequest := {
1023 typeField := 128,
1024 code := 0,
1025 checksum := ?,
1026 identifier := ?,
1027 sequenceNr := ?,
1028 data := ?
1029 }
1030 }
1031
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001032 /* template for receiving/matching an ICMPv6 echo reply */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001033 template (present) PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001034 echoReply := {
1035 typeField := 129,
1036 code := 0,
1037 checksum := ?,
1038 identifier := ?,
1039 sequenceNr := ?,
1040 data := data
1041 }
1042 }
1043
Harald Welte231b9412017-08-09 17:16:31 +02001044 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
Pau Espin Pedrol229ceed2023-12-05 14:50:53 +01001045 template (value) IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
Harald Welte231b9412017-08-09 17:16:31 +02001046 header := {
1047 ver := 6,
1048 trclass := 0,
1049 flabel := 0,
1050 plen := 0,
1051 nexthead := nexthead,
1052 hlim := hlim,
1053 srcaddr := srcaddr,
1054 dstaddr := dstaddr
1055 },
1056 ext_headers := omit,
1057 payload := payload
1058 }
1059
1060 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
1061 return 'FE80000000000000'O & substr(link_id, 8, 8);
1062 }
1063
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001064 function f_ipv6_global(in OCT16 link_id) return OCT16 {
1065 return substr(link_id, 0, 8) & '1234123412341234'O;
1066 }
1067
1068 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
1069 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
1070 var integer i;
1071 var octetstring res := substr(addr, 0, prefix);
1072 for (i := prefix; i < lengthof(addr); i := i + 1) {
1073 var octetstring a := addr[i] xor4b '11'O;
1074 res := res & a;
1075 }
1076 return res;
1077 }
1078
Harald Welte231b9412017-08-09 17:16:31 +02001079 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
1080 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
1081 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
1082 }
1083
1084 /* generate and encode ICMPv6 router solicitation */
1085 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
1086 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
1087 var OCT16 saddr := f_ipv6_link_local(link_id);
1088
1089 var octetstring tmp;
1090 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
1091 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
1092
1093 return f_IPv6_enc(ip6);
1094 }
1095
Pau Espin Pedrol57604212022-02-14 16:54:18 +01001096 /* Get link-id from PDP Context EUA */
1097 function f_ctx_get_ipv6_interface_id(in PdpContext ctx) return OCT16 {
1098 var OCT16 interface_id;
1099 if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
1100 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1101 } else if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv6)) {
1102 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
1103 } else {
1104 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected request to submit icmpv6 rs in IPv4 PDP context");
1105 }
1106 return interface_id;
1107 }
1108
Harald Welte231b9412017-08-09 17:16:31 +02001109 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
1110 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +01001111 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001112 return f_gen_icmpv6_router_solicitation(interface_id);
1113 }
1114
1115 /* generate and encode ICMPv6 neighbor solicitation */
1116 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
1117 var octetstring tmp;
1118 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
1119 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
1120 return f_IPv6_enc(ip6);
1121 }
1122
1123 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
1124 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +01001125 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001126 var OCT16 link_local := f_ipv6_link_local(interface_id);
1127 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
1128
1129 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
1130 }
1131
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001132 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02001133 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr, octetstring pl := ''O) return octetstring {
1134 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ(pl)));
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001135 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
1136 var octetstring data := f_IPv4_enc(ip4);
1137 var OCT2 cksum := f_IPv4_checksum(data);
1138 data[10] := cksum[0];
1139 data[11] := cksum[1];
1140 return data;
1141 }
1142
1143 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
1144 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
1145 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
1146 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
1147 var octetstring data := f_IPv6_enc(ip6);
1148 return data;
1149 }
1150
1151 /* Wait for ICMPv4 from GTP */
1152 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +02001153 var Gtp1uUnitdata ud;
1154 T_default.start;
1155 alt {
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001156 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ctx.teid)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +02001157 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001158 setverdict(fail);
1159 stop;
1160 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001161 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1162 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
1163 if (ip4.header.ver != 4) {
1164 repeat;
1165 }
1166 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
1167 if (not match(icmp4, expected)) {
1168 repeat;
1169 }
1170 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001171 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
1172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1173 "Received wrong local TEID");
1174 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001175 [] GTPU.receive { setverdict(fail); }
1176 [] T_default.timeout { setverdict(fail); }
1177 }
1178 T_default.stop;
1179 }
1180
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001181 /* Wait for ICMPv4 echo request from GTP */
1182 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
1183 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
1184 }
1185
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001186 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
1187 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
1188 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
1189 }
1190
1191 /* Wait for ICMPv6 from GTP */
1192 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
1193 var Gtp1uUnitdata ud;
1194 T_default.start;
1195 alt {
Harald Welte231b9412017-08-09 17:16:31 +02001196 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +02001197 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Pau Espin Pedrol9c1c2ae2023-12-05 14:24:49 +01001198 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1199 log2str("Received GTPU with wrong txseq while waiting for ICMPv6: ", expected));
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001200 }
Harald Welte231b9412017-08-09 17:16:31 +02001201 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1202 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001203 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +02001204 repeat;
1205 }
1206 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001207 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +02001208 repeat;
1209 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001210 /* We are waiting for RA, update ctx */
1211 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
1212 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
1213 log("RA with /64 prefix ", ctx.ip6_prefix);
1214 }
Harald Welte231b9412017-08-09 17:16:31 +02001215 }
1216 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
Pau Espin Pedrol9c1c2ae2023-12-05 14:24:49 +01001217 [] GTPU.receive {
1218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1219 log2str("Received unexpected GTPU while waiting for ICMPv6: ", expected));
1220 }
1221 [] T_default.timeout {
1222 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1223 log2str("Timeout waiting for ICMPv6: ", expected));
1224 }
Harald Welte231b9412017-08-09 17:16:31 +02001225 }
1226 T_default.stop;
1227 }
1228
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001229 /* wait for GGSN to send us an ICMPv6 router advertisement */
1230 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
1231 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
1232 }
1233
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001234 /* Wait for ICMPv6 echo request from GTP */
1235 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
1236 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
1237 }
1238
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001239 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
1240 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
1241 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
1242 }
1243
Oliver Smithee6a0882019-03-08 11:05:46 +01001244 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
1245 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
1246 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1247 return f_gen_icmpv6_router_solicitation(interface_id);
1248 }
1249
1250 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
1251 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
1252 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1253 var OCT16 link_local := f_ipv6_link_local(interface_id);
1254 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
1255
1256 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
1257 }
1258
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001259 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
1260 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
1261 T_default.start;
1262 alt {
1263 [] GTPU.receive { setverdict(fail); }
1264 [] T_default.timeout { }
1265 }
1266 T_default.stop;
1267 }
1268
Harald Welte79737b42019-04-10 10:39:30 +02001269 /* list of protocols where we don't accept duplicates */
1270 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
1271 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
1272 var integer i;
1273 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
1274 if (id == protocol_ids_nodupes[i]) {
1275 return false;
1276 }
1277 }
1278 return true;
1279 }
1280
1281 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
1282 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
1283 var OCT2List protocol_ids := {};
1284 var integer i, j;
1285 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
1286 var OCT2 id := pco.protocols[i].protocolID;
1287 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
1288 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
1289 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
1290 }
1291 }
1292 protocol_ids := protocol_ids & { id };
1293 }
1294 }
1295
Harald Welte0ef285b2017-08-13 20:06:01 +02001296 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +02001297 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +02001298 f_init();
Harald Welte231b9412017-08-09 17:16:31 +02001299
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001300 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welte811651e2017-08-05 15:25:06 +02001301 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +02001302 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001303 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001304 }
1305
Harald Welte0ef285b2017-08-13 20:06:01 +02001306 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001307 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
1308 f_init();
1309
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001310 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001311 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1312 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001313
Harald Welte79737b42019-04-10 10:39:30 +02001314 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001315 /* verify PCO contains both primary and secondary DNS */
1316 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1317 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1318 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1319 }
1320
1321 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1322 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1323 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1324 }
1325
Harald Welteed7a1772017-08-09 20:26:20 +02001326 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001327 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001328 }
1329
Harald Welte0ef285b2017-08-13 20:06:01 +02001330 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +02001331 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
1332 f_init();
1333
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001334 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001335 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1336 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001337
Harald Welte79737b42019-04-10 10:39:30 +02001338 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +02001339 //f_send_gtpu(ctx, c_router_solicit);
1340 //f_send_gtpu(ctx, c_neigh_solicit);
1341
1342 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1343 f_wait_rtr_adv(ctx);
1344 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1345
Harald Welte811651e2017-08-05 15:25:06 +02001346 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001347 f_shutdown_helper();
Harald Welte94ade362017-08-04 00:36:55 +02001348 }
1349
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001350 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
1351 Test we can send ICMPv6 ping over GTPU to DNS server. */
1352 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
1353 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001354 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 +01001355 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1356 f_pdp_ctx_act(ctx);
1357
1358 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1359 f_wait_rtr_adv(ctx);
1360 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1361
1362 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1363
1364 /* Check if we can use valid link-local src addr. */
1365 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1366 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
Pau Espin Pedrolb63d85f2022-02-07 16:11:47 +01001367 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
1368 f_wait_icmp6_echo_reply(ctx);
1369 } else {
1370 f_wait_gtpu_fail(ctx);
1371 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001372
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001373 /* Check if we can use valid global src addr, should work */
1374 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1375 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
1376 f_wait_icmp6_echo_reply(ctx);
1377
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001378 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001379 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001380 }
1381
1382 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1383 testcase TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr() runs on GT_CT {
1384 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001385 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 +01001386 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1387 f_pdp_ctx_act(ctx);
1388
1389 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1390 f_wait_rtr_adv(ctx);
1391 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1392
1393 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1394 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1395 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1396 f_wait_gtpu_fail(ctx);
1397
1398 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001399 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001400 }
1401
1402 /* Assert that packets with wrong global src addr are dropped by GGSN */
1403 testcase TC_pdp6_act_deact_gtpu_access_wrong_global_saddr() runs on GT_CT {
1404 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001405 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 +01001406 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1407 f_pdp_ctx_act(ctx);
1408
1409 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1410 f_wait_rtr_adv(ctx);
1411 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1412
1413 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1414 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001415 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1416 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
1417 f_wait_gtpu_fail(ctx);
1418
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001419 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001420 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001421 }
1422
1423 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped */
1424 testcase TC_pdp6_act_deact_gtpu_access_ipv4_apn6() runs on GT_CT {
1425 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001426 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 +01001427 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1428 f_pdp_ctx_act(ctx);
1429
1430 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1431 f_wait_rtr_adv(ctx);
1432 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1433
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001434 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
1435 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
1436 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
1437 f_wait_gtpu_fail(ctx);
1438
1439 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001440 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001441 }
1442
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001443 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1444 testcase TC_pdp6_clients_interact() runs on GT_CT {
1445 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001446 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1447 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 +01001448 f_pdp_ctx_act(ctxA);
1449 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
1450 f_wait_rtr_adv(ctxA);
1451 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
1452
1453 f_pdp_ctx_act(ctxB);
1454 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
1455 f_wait_rtr_adv(ctxB);
1456 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
1457
1458 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1459 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1460 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1461 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1462
1463 /* Validate if clients can interact using ll addr. */
1464 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1465 f_wait_gtpu_fail(ctxB);
1466
1467 /* Validate if clients can interact using global addr. */
1468 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1469 f_wait_gtpu_fail(ctxB);
1470
1471 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001472 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001473 f_shutdown_helper();
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001474 }
1475
Harald Welte0ef285b2017-08-13 20:06:01 +02001476 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +02001477 testcase TC_pdp4_act_deact() runs on GT_CT {
1478 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001479 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001480 f_pdp_ctx_act(ctx);
1481 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001482 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001483 }
1484
Harald Welte0ef285b2017-08-13 20:06:01 +02001485 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +02001486 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
1487 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001488 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1489 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001490 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001491 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +02001492 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001493 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +01001494 /* verify IPCP is at all contained */
1495 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1496 setverdict(fail, "IPCP not found in PCO");
1497 }
1498 /* verify IPCP contains both primary and secondary DNS */
1499 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001500 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1501 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1502 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1503 } else {
1504 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1505 }
Harald Welte71a36022017-12-04 18:55:58 +01001506 }
Harald Welteed7a1772017-08-09 20:26:20 +02001507 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001508 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001509 }
1510
Harald Weltef8298542019-04-10 10:15:28 +02001511 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
1512 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
1513 f_init();
1514 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1515 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001516 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltef8298542019-04-10 10:15:28 +02001517 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1518 f_pdp_ctx_act(ctx);
1519 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1520 /* verify IPCP is at all contained */
1521 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1522 setverdict(fail, "IPCP not found in PCO");
1523 }
1524 /* verify IPCP contains both primary and secondary DNS */
1525 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1526 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1527 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1528 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1529 } else {
1530 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1531 }
1532 }
1533 /* verify that PAP is contained */
1534 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1535 setverdict(fail, "PAP not found in PCO");
1536 }
1537 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1538 if (not match(pap, tr_PAP_AuthAck)) {
1539 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1540 }
1541 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001542 f_shutdown_helper();
Harald Weltef8298542019-04-10 10:15:28 +02001543 }
1544
Harald Welte0ef285b2017-08-13 20:06:01 +02001545 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001546 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1547 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001548 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001549 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001550 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001551
Harald Welte79737b42019-04-10 10:39:30 +02001552 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001553 /* verify PCO contains both primary and secondary DNS */
1554 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1555 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1556 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1557 }
1558
1559 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1560 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1561 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1562 }
1563
Harald Welteed7a1772017-08-09 20:26:20 +02001564 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001565 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001566 }
1567
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001568 /* Test PDP context activation for dynamic IPv4 EUA.
1569 Test we can send ICMPv6 ping over GTPU to DNS server. */
1570 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1571 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001572 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001573 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1574 f_pdp_ctx_act(ctx);
1575
Harald Welte79737b42019-04-10 10:39:30 +02001576 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001577 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1578
1579 /* Check if we can use valid global src addr, should work */
1580 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1581 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1582 f_wait_icmp4_echo_reply(ctx);
1583
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001584 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001585 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001586 }
1587
1588 /* Assert that packets with wrong global src addr are dropped by GGSN */
1589 testcase TC_pdp4_act_deact_gtpu_access_wrong_saddr() runs on GT_CT {
1590 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001591 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 +01001592 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1593 f_pdp_ctx_act(ctx);
1594
1595 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1596 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1597 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001598 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1599 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1600 f_wait_gtpu_fail(ctx);
1601
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001602 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001603 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001604 }
1605
1606 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1607 testcase TC_pdp4_act_deact_gtpu_access_ipv6_apn4() runs on GT_CT {
1608 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001609 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 +01001610 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1611 f_pdp_ctx_act(ctx);
1612
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001613 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1614 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1615 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1616 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001617
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001618 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001619 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001620 }
1621
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001622 /* Helper function for tests below. */
1623 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001624 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001625 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1626 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 +01001627 f_pdp_ctx_act(ctxA);
1628 f_pdp_ctx_act(ctxB);
1629 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1630 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1631 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1632 f_wait_icmp4_echo_request(ctxB);
1633
1634 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001635 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001636 }
1637
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001638 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1639 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001640 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001641 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001642 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001643 }
1644
1645 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1646 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001647 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001648 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001649 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001650 }
1651
Harald Weltedca80052017-08-13 20:01:38 +02001652 testcase TC_echo_req_resp() runs on GT_CT {
1653 f_init();
1654 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1655 T_default.start;
1656 alt {
1657 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1658 [] GTPC.receive { repeat; };
1659 [] T_default.timeout { setverdict(fail); }
1660 }
1661 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001662 f_shutdown_helper();
Harald Weltedca80052017-08-13 20:01:38 +02001663 }
1664
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001665 testcase TC_echo_req_resp_gtpu() runs on GT_CT {
1666 f_init();
1667 GTPU.send(ts_GTPU_PING(g_peer_u, g_d_seq_nr));
1668 T_default.start;
1669 alt {
1670 [] GTPU.receive(tr_GTPU_PONG(g_peer_u)) { setverdict(pass); };
1671 [] GTPU.receive { repeat; };
1672 [] T_default.timeout { setverdict(fail); }
1673 }
1674 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001675 f_shutdown_helper();
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001676 }
1677
Philipp Maier33e52612018-05-30 17:22:02 +02001678 /* Test if the parser can cope with PCO that only contain either a
1679 * single primary DNS or a secondary DNS. */
1680 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1681
1682 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1683 * the test is executed.
1684 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1685
1686 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001687 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001688 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1689 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1690 var octetstring pco_neg_dns;
1691 var octetstring pco_neg_dns_expected;
1692
1693 /* PCO with primary DNS only */
1694 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1695 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001696 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001697 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1698 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1699 /* Note: The prepended hex bytes encode the following information:
1700 * 0x02 = Configuration ACK
1701 * 0x00 = Identifier
1702 * 0x000a = Length
1703 * 0x81 = Type (Primary DNS Server Address)
1704 * 0x06 = Length
1705 * (4 byte IP-Address appended) */
1706 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1707 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1708 }
1709 f_pdp_ctx_del(ctx, '1'B);
1710
1711 /* PCO with secondary DNS only */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001712 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001713 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1714 f_pdp_ctx_act(ctx);
1715 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1716 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1717 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1718 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1719 }
1720 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001721 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001722 }
1723
1724 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1725 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1726 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1727 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1728
1729 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1730 * the test is executed.
1731 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1732
1733 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001734 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001735 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1736 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1737 var octetstring pco_neg_dns;
1738 var octetstring pco_neg_dns_expected;
1739
1740 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1741 f_pdp_ctx_act(ctx);
1742
1743 /* Check if primary DNS is contained */
1744 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1745 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1746 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1747 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1748 }
Philipp Maier33e52612018-05-30 17:22:02 +02001749
1750 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001751 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1752 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001753 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1754 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1755 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1756 }
1757 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001758 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001759 }
1760
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001761 /* Validate that SUT updates remote TEIC when requested through UpdatePDPContextRequest */
1762 testcase TC_pdp4_act_update_teic() runs on GT_CT {
1763 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001764 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 +01001765 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1766 f_pdp_ctx_act(ctx);
1767
1768 /* UpdatePDPContestRequest changing the local TEIC */
1769 var OCT4 new_teic := ctx.teic;
1770 new_teic[3] := new_teic[3] xor4b '11'O;
1771 f_pdp_ctx_update(ctx, new_teic := new_teic);
1772
1773 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001774 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001775 }
1776
1777 /* Validate that SUT updates remote TEID when requested through UpdatePDPContextRequest */
1778 testcase TC_pdp4_act_update_teid() runs on GT_CT {
1779 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001780 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 +01001781 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1782 f_pdp_ctx_act(ctx);
1783
1784 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1785 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1786 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1787
1788 /* Data is sent (back) to the local TEID established during CreatePDPContext */
1789 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1790 f_wait_icmp4_echo_reply(ctx);
1791
1792 /* UpdatePDPContestRequest changing the local TEID */
1793 var OCT4 new_teid := ctx.teid;
1794 new_teid[3] := new_teid[3] xor4b '11'O;
1795 f_pdp_ctx_update(ctx, new_teid := new_teid);
1796
1797 /* Check if we can send data after updating the PDP context. Answer should be sent to the new TEID */
1798 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1799 f_wait_icmp4_echo_reply(ctx);
1800
1801 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001802 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001803 }
1804
Oliver Smithee6a0882019-03-08 11:05:46 +01001805 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1806 testcase TC_pdp46_act_deact() runs on GT_CT {
1807 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001808 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001809 f_pdp_ctx_act(ctx);
1810 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001811 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001812 }
1813
1814 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1815 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1816 f_init();
1817 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1818 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001819 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001820 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1821 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001822 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001823 /* verify IPCP is at all contained */
1824 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1825 setverdict(fail, "IPCP not found in PCO");
1826 }
Harald Welte79737b42019-04-10 10:39:30 +02001827 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001828 /* verify IPCP contains both primary and secondary IPv4 DNS */
1829 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1830 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1831 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1832 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1833 } else {
1834 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1835 }
1836 }
1837 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001838 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001839 }
1840
1841 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1842 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1843 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001844 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001845 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1846 f_pdp_ctx_act(ctx);
1847
1848 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1849 f_wait_rtr_adv(ctx);
1850 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1851
1852 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001853 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001854 }
1855
1856 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1857 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1858 f_init();
1859
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001860 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001861 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1862 f_pdp_ctx_act(ctx);
1863
Harald Welte79737b42019-04-10 10:39:30 +02001864 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001865 /* verify PCO contains both primary and secondary IPv4 DNS */
1866 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1867 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1868 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1869 }
1870
1871 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1872 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1873 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1874 }
1875
1876 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001877 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001878 }
1879
1880 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1881 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1882 f_init();
1883
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001884 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001885 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1886 f_pdp_ctx_act(ctx);
1887
Harald Welte79737b42019-04-10 10:39:30 +02001888 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001889 /* verify PCO contains both primary and secondary IPv6 DNS */
1890 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1891 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1892 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1893 }
1894
1895 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1896 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1897 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1898 }
1899
1900 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001901 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001902 }
1903
1904 /* Test PDP context activation for dynamic IPv4v6 EUA.
1905 Test we can send ICMPv6 ping over GTPU to DNS server. */
1906 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1907 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001908 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001909 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1910 f_pdp_ctx_act(ctx);
1911
1912 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1913
1914 /* Check if we can use valid global src addr, should work */
1915 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1916 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1917 f_wait_icmp4_echo_reply(ctx);
1918
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001919 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001920 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001921 }
1922
1923 /* Assert that packets with wrong ipv4 src addr are dropped by GGSN on APN IPv4v6 */
1924 testcase TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4() runs on GT_CT {
1925 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001926 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001927 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1928 f_pdp_ctx_act(ctx);
1929
1930 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1931 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
Oliver Smithee6a0882019-03-08 11:05:46 +01001932 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1933 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1934 f_wait_gtpu_fail(ctx);
1935
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001936 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001937 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001938 }
1939
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001940 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1941 testcase TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6() runs on GT_CT {
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001942 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001943 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 +01001944 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1945 f_pdp_ctx_act(ctx);
1946
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001947 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1948 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1949 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1950 f_wait_gtpu_fail(ctx);
1951
1952 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001953 f_shutdown_helper();
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001954 }
1955
1956 /* Assert that packets with wrong ipv6 global src addr are dropped by GGSN on APN IPv4v6 */
1957 testcase TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6() runs on GT_CT {
1958 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001959 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 +01001960 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1961 f_pdp_ctx_act(ctx);
1962
1963 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1964 f_wait_rtr_adv(ctx);
1965 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1966
1967 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1968 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1969 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1970 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
Oliver Smithee6a0882019-03-08 11:05:46 +01001971 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001972
Oliver Smithee6a0882019-03-08 11:05:46 +01001973 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001974 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001975 }
1976
1977 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1978 testcase TC_pdp46_clients_interact() runs on GT_CT {
1979 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02001980 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1981 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
Oliver Smithee6a0882019-03-08 11:05:46 +01001982 f_pdp_ctx_act(ctxA);
1983 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1984 f_wait_rtr_adv(ctxA);
1985 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1986
1987 f_pdp_ctx_act(ctxB);
1988 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1989 f_wait_rtr_adv(ctxB);
1990 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1991
1992 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1993 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1994 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1995 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1996
1997 /* Validate if clients can interact using ll addr. */
1998 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1999 f_wait_gtpu_fail(ctxB);
2000
2001 /* Validate if clients can interact using global addr. */
2002 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
2003 f_wait_gtpu_fail(ctxB);
2004
2005 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02002006 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002007 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01002008 }
2009
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002010 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
2011 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002012 const OCT1 cause_accept := '80'O; /* Normal accept cause */
2013 const OCT1 cause_new_pdp_type := '81'O; /* Cause: New PDP type due to network preference */
2014 const OCT1 cause_unknown_pdp := 'DC'O; /* Cause: Unknown PDP address or PDP type */
2015 var CreatePDPContextResponse cpr;
2016
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002017 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002018 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 +01002019 cpr := f_pdp_ctx_act(ctx46, (cause_unknown_pdp, cause_new_pdp_type));
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002020
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002021 if (cpr.cause.causevalue == cause_new_pdp_type) {
2022 /* 3GPP TS 23.060 sec 9.2.1: "If the MS requests PDP type IPv4v6,
2023 * but the operator preferences dictate the use of a single IP
2024 * version only, the PDP type shall be changed to a single address
2025 * PDP type (IPv4 or IPv6) and a reason cause shall be returned to
2026 * the MS indicating that only the assigned PDP type is allowed. In
2027 * this case, the MS shall not request another PDP context for the
2028 * other PDP type during the existence of the PDP context." */
2029 f_pdp_ctx_del(ctx46, '1'B);
2030 } else {
2031 /* 3GPP TS 23.060 sec 9.2.1 NOTE 5: If the MS requests PDP type
2032 * IPv4v6, and the PDP context is rejected due to "unknown PDP
2033 * type", the MS can attempt to establish dual-stack connectivity
2034 * by performing two PDP context request procedures to activate an
2035 * IPv4 PDP context and an IPv6 PDP context, both to the same APN. A
2036 * typical MS first attempts v4v6, and if rejected, then tries v4
2037 * and v6 separetly */
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002038 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 +01002039 f_pdp_ctx_act(ctx4, cause_accept); /* Normal accept cause */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002040
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002041 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 +01002042 f_pdp_ctx_act(ctx6, cause_unknown_pdp); /* Cause: Unknown PDP address or PDP type */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002043
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01002044 f_pdp_ctx_del(ctx4, '1'B);
2045 }
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002046 f_shutdown_helper();
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002047 }
2048
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002049 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
2050 testcase TC_pdp_act2_recovery() runs on GT_CT {
2051 var Gtp1cUnitdata ud;
2052 var default d;
2053 var boolean ctxA_deleted := false;
2054 var boolean ctxB_created := false;
2055
2056 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002057 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2058 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 +02002059 f_pdp_ctx_act(ctxA);
2060
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06002061 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002062
2063 log("sending 2nd CreatePDP (recovery increased)");
2064 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
2065 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
2066 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
2067 T_default.start;
2068 d := activate(pingpong());
2069 alt {
2070 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
2071 f_handle_create_req(ctxB, ud);
2072 if (not ctxB_created) {
2073 ctxB_created := true;
2074 setverdict(pass);
2075 } else {
2076 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
2077 }
2078
2079 if (not ctxA_deleted) {
2080 repeat;
2081 }
2082 }
2083 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
2084 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
2085 setverdict(pass);
2086 } else {
2087 setverdict(fail);
2088 }
2089
2090 if (not ctxA_deleted) {
2091 ctxA_deleted := true;
2092 setverdict(pass);
2093 } else {
2094 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
2095 }
2096
2097 if (not ctxB_created) {
2098 repeat;
2099 }
2100 }
2101 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
2102 setverdict(fail, "GGSN dropping still valid pdp ctx");
2103 }
2104 }
2105 deactivate(d);
2106 T_default.stop;
2107
2108 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002109 f_shutdown_helper();
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002110 }
2111
2112
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +01002113 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent responses (T3-RESPONSE * N3-REQUESTS):
2114 * 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 +02002115 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
2116 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002117 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 +02002118 f_pdp_ctx_act(ctx);
2119 f_pdp_ctx_del(ctx, '1'B);
2120 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
Pau Espin Pedrolbfad97f2022-11-04 12:03:17 +01002121 f_sleep(int2float(mp_t3_response));
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002122 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
2123 duplicate. If it was not a duplicate, osmo-ggsn would answer
2124 with a failure since that PDP ctx was already deleted. */
Pau Espin Pedrold6b51332022-05-19 17:47:11 +02002125 if (g_c_seq_nr == 0) {
2126 g_c_seq_nr := 65535;
2127 } else {
2128 g_c_seq_nr := g_c_seq_nr - 1;
2129 }
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01002130 f_pdp_ctx_del(ctx, '1'B, expect_diameter := false);
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002131
2132 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
2133 var OCT1 cause_nonexistent := 'C0'O;
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01002134 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent, expect_diameter := false);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002135 f_shutdown_helper();
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002136 }
2137
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002138 /* Activate PDP context + trigger Recovery procedure through EchoResp */
2139 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
2140 var Gtp1cUnitdata ud;
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002141 g_use_echo_intval := 5;
2142 timer T_echo;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002143 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002144 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 +02002145 f_pdp_ctx_act(ctx);
2146
2147 /* Wait to receive echo request and send initial Restart counter */
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002148 T_echo.start(int2float(g_use_echo_intval) + 1.0);
2149 alt {
2150 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002151 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
2152 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002153 }
2154 [] T_echo.timeout {
2155 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2156 "Timeout waiting for ping");
2157 }
2158 }
2159 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002160
2161 /* Wait to receive second echo request and send incremented Restart
2162 counter. This will fake a restarted SGSN, and pdp ctx allocated
2163 should be released by GGSN */
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06002164 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002165 T_echo.start(int2float(g_use_echo_intval) + 1.0);
2166 alt {
2167 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002168 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
2169 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01002170 }
2171 [] T_echo.timeout {
2172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2173 "Timeout waiting for ping");
2174 }
2175 }
2176 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002177 f_pdp_ctx_exp_del_req(ctx, omit, true);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002178 f_shutdown_helper();
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002179 }
2180
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002181 /* Test creation, user plane and deletion of big amount (1000) of concurrent PDP context */
2182 testcase TC_lots_of_concurrent_pdp_ctx() runs on GT_CT {
2183 var Gtp1cUnitdata udc;
2184 var Gtp1uUnitdata udu;
2185 const integer num_ctx := 1000;
2186 var PdpContext ctx[num_ctx];
2187 timer T_next := 0.01;
2188 var integer next_req_ctx := 0;
2189 var integer rx_resp_ctx := 0;
2190 var integer rx_pong := 0;
2191 var OCT4 dns1_addr;
2192 var OCT4 saddr;
2193 var integer teic;
2194 var integer idx;
2195
2196 f_init();
2197
2198 for (var integer i := 0; i < num_ctx; i := i + 1) {
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002199 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 +01002200 ctx[i].teic := int2oct(i+1, 4); /* +1: skip TEIC=0 */
2201 ctx[i].teid := int2oct(i+1, 4); /* +1: skip TEID=0 */
2202 ctx[i].pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2203 }
2204
2205 T_default.start(60.0);
2206
2207 T_next.start;
2208 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002209 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002210 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, INITIAL_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002211 [] pingpong();
2212 [] T_next.timeout {
2213 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx[next_req_ctx].imsi, g_restart_ctr,
2214 ctx[next_req_ctx].teid, ctx[next_req_ctx].teic, ctx[next_req_ctx].nsapi,
2215 ctx[next_req_ctx].eua, ctx[next_req_ctx].apn, g_sgsn_ip_c, g_sgsn_ip_u,
2216 ctx[next_req_ctx].msisdn, ctx[next_req_ctx].pco_req, ctx[next_req_ctx].ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002217 ctx[next_req_ctx].uli, ctx[next_req_ctx].charging_char, ctx[next_req_ctx].imeisv,
2218 ctx[next_req_ctx].ms_tz));
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002219 next_req_ctx := next_req_ctx + 1;
2220 if (next_req_ctx < num_ctx) {
2221 T_next.start;
2222 }
2223 repeat;
2224 }
2225 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2226 teic := oct2int(udc.gtpc.teid);
2227 if (not match(teic, (1 .. num_ctx))) {
2228 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2229 "Rx Unexpected TEIC");
2230 }
2231 idx := teic - 1;
2232 f_handle_create_req(ctx[idx], udc);
2233 rx_resp_ctx := rx_resp_ctx + 1;
2234
2235 dns1_addr := f_PCO_extract_proto(ctx[idx].pco_neg, '000d'O);
2236 saddr := ctx[idx].eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2237 f_send_gtpu(ctx[idx], f_gen_icmpv4_echo(saddr, dns1_addr));
2238 repeat;
2239 }
2240 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value udu {
2241 var octetstring gpdu := udu.gtpu.gtpu_IEs.g_PDU_IEs.data;
2242 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
2243 if (ip4.header.ver != 4) {
2244 repeat;
2245 }
2246 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
2247 if (not match(icmp4, (tr_ICMPv4_ERP, tr_ICMPv4_DU))) {
2248 repeat;
2249 }
2250 rx_pong := rx_pong + 1;
2251 if (rx_pong < num_ctx) {
2252 repeat;
2253 }
2254 setverdict(pass);
2255 }
2256 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2257 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2258 }
2259
2260 /* Let's close them now: */
2261 next_req_ctx := 0;
2262 rx_resp_ctx := 0;
2263 T_next.start;
2264 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002265 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002266 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002267 [] pingpong();
2268 [] T_next.timeout {
2269 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));
2270 next_req_ctx := next_req_ctx + 1;
2271 if (next_req_ctx < num_ctx) {
2272 T_next.start;
2273 }
2274 repeat;
2275 }
2276 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2277 teic := oct2int(udc.gtpc.teid);
2278 if (not match(teic, (1 .. num_ctx))) {
2279 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2280 "Rx Unexpected TEIC");
2281 }
2282 rx_resp_ctx := rx_resp_ctx + 1;
2283 if (rx_resp_ctx < num_ctx) {
2284 repeat;
2285 }
2286 setverdict(pass);
2287 }
2288 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2289 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2290 }
2291 T_next.stop;
2292
2293 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002294 f_shutdown_helper();
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002295 }
2296
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002297 /* Test callocation of PDP contexts until reaching addr pool exhaustion */
2298 type record of OCT4 TEIClist;
2299 testcase TC_addr_pool_exhaustion() runs on GT_CT {
2300 var Gtp1cUnitdata udc;
2301 var Gtp1uUnitdata udu;
2302 var PdpContext ctx;
2303 timer T_next := 0.005;
2304 var integer next_req_ctx := 0;
2305 var integer rx_resp_ctx := 0;
2306 var integer num_ctx;
2307 var boolean cont_req := true;
2308 var CreatePDPContextResponse cpr;
2309 var TEIClist teic_list := {};
2310 var integer teic;
2311
2312 f_init();
2313
2314 T_default.start(120.0);
2315
2316 T_next.start;
2317 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002318 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002319 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, INITIAL_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002320 [] pingpong();
2321 [] T_next.timeout {
2322 if (cont_req) {
2323 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 +02002324 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 +01002325 ctx.nsapi := '0001'B;
2326 ctx.teic := int2oct(next_req_ctx+1, 4); /* +1: skip TEIC=0 */
2327 ctx.teid := int2oct(next_req_ctx+1, 4); /* +1: skip TEID=0 */
2328 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx.imsi, g_restart_ctr,
2329 ctx.teid, ctx.teic, ctx.nsapi,
2330 ctx.eua, ctx.apn, g_sgsn_ip_c, g_sgsn_ip_u,
2331 ctx.msisdn, ctx.pco_req, ctx.ratType,
Pau Espin Pedrol535ca262022-05-16 14:07:17 +02002332 ctx.uli, ctx.charging_char, ctx.imeisv,
2333 ctx.ms_tz));
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002334 next_req_ctx := next_req_ctx + 1;
2335 }
2336 T_next.start;
2337 }
2338 repeat;
2339 }
2340 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2341 cpr := udc.gtpc.gtpc_pdu.createPDPContextResponse;
2342
2343 if (cpr.cause.causevalue == '80'O) {
2344 teic_list := teic_list & {cpr.teidControlPlane.teidControlPlane};
2345 } else {
2346 if (cont_req == true) {
2347 num_ctx := rx_resp_ctx;
2348 log("Successfully created ", num_ctx, " PDP contexts before exhausting the pool");
2349 setverdict(pass);
2350 }
2351 cont_req := false;
2352 }
2353 rx_resp_ctx := rx_resp_ctx + 1;
2354 if (not cont_req and next_req_ctx == rx_resp_ctx) {
2355 break;
2356 } else {
2357 repeat;
2358 }
2359 }
2360 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2361 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2362 }
2363
2364 /* Let's close them now: */
2365 next_req_ctx := 0;
2366 rx_resp_ctx := 0;
2367 T_next.start;
2368 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002369 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002370 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(omit, TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002371 [] pingpong();
2372 [] T_next.timeout {
2373 f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, teic_list[next_req_ctx], '0001'B, '1'B));
2374 next_req_ctx := next_req_ctx + 1;
2375 if (next_req_ctx < num_ctx) {
2376 T_next.start;
2377 }
2378 repeat;
2379 }
2380 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2381 teic := oct2int(udc.gtpc.teid);
2382 if (not match(teic, (1 .. num_ctx))) {
2383 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2384 "Rx Unexpected TEIC");
2385 }
2386 rx_resp_ctx := rx_resp_ctx + 1;
2387 if (rx_resp_ctx < num_ctx) {
2388 repeat;
2389 }
2390 setverdict(pass);
2391 }
2392 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2393 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2394 }
2395 T_next.stop;
2396
2397 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002398 f_shutdown_helper();
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002399 }
2400
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002401 /* Test charging over Gy interface. */
2402 testcase TC_gy_charging_cc_time() runs on GT_CT {
2403 var default d;
2404
2405 g_gy_validity_time := 3; /* Grant access for 3 seconds, needs to be re-validated afterwards */
2406 f_init();
Pau Espin Pedrold25095f2022-05-18 16:29:05 +02002407 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 +01002408 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2409 f_pdp_ctx_act(ctx);
2410
2411 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2412
2413 /* Send some UL traffic: */
2414 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2415 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2416 f_wait_icmp4_echo_reply(ctx);
2417
2418 T_default.start(10.0);
2419 d := activate(pingpong());
2420
2421 g_gy_validity_time := 2;
2422 /* First update reports octests/pkt on both UL/DL (see icmp ping-pong above) */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002423 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002424 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (3..4), 28, 28);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002425
2426 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002427 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002428 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (2..3), 0, 0);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002429
2430 /* Third update: make sure report contains again octets/pkts for both UL/DL: */
2431 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2432 f_wait_icmp4_echo_reply(ctx);
2433 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2434 f_wait_icmp4_echo_reply(ctx);
Pau Espin Pedrola2af5782022-05-18 16:34:29 +02002435 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002436 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (2..3), 56, 56);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002437
2438 /* Let the CCA reach the GGSN */
2439 f_sleep(0.5);
2440 deactivate(d);
2441 T_default.stop;
2442
2443 /* Send some data and validate it is reported in the TERMINATION_REQUEST
2444 * (triggered by PFCP Session Deletion Response): */
2445 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2446 f_wait_icmp4_echo_reply(ctx);
2447
2448 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrol8fa22842022-05-20 14:47:55 +02002449 f_validate_gy_cc_report(g_rx_gy, FINAL, (0..2), 28, 28);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002450
2451
2452 f_shutdown_helper();
2453 }
2454
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002455 /* Test Volume-Quota-Thresold AVP triggers request before Validity-Time */
2456 testcase TC_gy_charging_volume_quota_threshold() runs on GT_CT {
2457 var default d;
2458 timer Tout;
2459 g_gy_volume_threshold := 1000; /* Will make a trigger when we send bigger payload below */
2460 g_gy_validity_time := 8; /* Grant access for 8 seconds, needs to be re-validated afterwards */
2461 f_init();
2462 var float tout_sec := int2float(g_gy_validity_time) / 2.0;
2463 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), "1234", c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2464 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2465 f_pdp_ctx_act(ctx);
2466
2467 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2468
2469 T_default.start(40.0);
2470 d := activate(pingpong());
2471
2472 /* Send some UL traffic: */
2473 var octetstring payload := f_rnd_octstring(1200);
2474 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2475 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr, payload));
2476 f_wait_icmp4_echo_reply(ctx);
2477
2478 /* ICMP Req generates one report: */
2479 Tout.start(tout_sec);
2480 alt {
2481 [] as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
2482 [] Tout.timeout {
2483 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2484 "TImeout waiting for Gy UPDATE triggered by Volume-Quota-Threshold");
2485 }
2486 }
Pau Espin Pedrol5fa8f782022-10-03 13:57:54 +02002487 f_validate_gy_cc_report(g_rx_gy, THRESHOLD, (0..6), (1200..1400), 0);
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002488
2489 /* ICMP Resp (echo back) generates one report: */
2490 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
Pau Espin Pedrol5fa8f782022-10-03 13:57:54 +02002491 f_validate_gy_cc_report(g_rx_gy, THRESHOLD, (0..1), 0, (1200..1400));
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002492
2493 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
2494 as_DIA_Gy_CCR(ctx, UPDATE_REQUEST);
2495 f_validate_gy_cc_report(g_rx_gy, VALIDITY_TIME, (8..9), 0, 0);
2496
2497 /* Let the CCA reach the GGSN */
2498 f_sleep(0.5);
2499 deactivate(d);
2500 T_default.stop;
2501
2502 f_pdp_ctx_del(ctx, '1'B);
2503 f_validate_gy_cc_report(g_rx_gy, FINAL, (0..2), 0, 0);
2504
2505
2506 f_shutdown_helper();
2507 }
2508
Harald Welte94ade362017-08-04 00:36:55 +02002509 control {
Harald Welteed7a1772017-08-09 20:26:20 +02002510 execute(TC_pdp4_act_deact());
2511 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02002512 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02002513 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002514 execute(TC_pdp4_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002515 execute(TC_pdp4_act_deact_gtpu_access_wrong_saddr());
2516 execute(TC_pdp4_act_deact_gtpu_access_ipv6_apn4());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02002517 execute(TC_pdp4_clients_interact_with_txseq());
2518 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02002519 execute(TC_pdp4_act_deact_with_single_dns());
2520 execute(TC_pdp4_act_deact_with_separate_dns());
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01002521 execute(TC_pdp4_act_update_teic());
2522 execute(TC_pdp4_act_update_teid());
Harald Welteed7a1772017-08-09 20:26:20 +02002523
2524 execute(TC_pdp6_act_deact());
2525 execute(TC_pdp6_act_deact_pcodns());
2526 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002527 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002528 execute(TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr());
2529 execute(TC_pdp6_act_deact_gtpu_access_wrong_global_saddr());
2530 execute(TC_pdp6_act_deact_gtpu_access_ipv4_apn6());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01002531 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02002532
Oliver Smithee6a0882019-03-08 11:05:46 +01002533 execute(TC_pdp46_act_deact());
2534 execute(TC_pdp46_act_deact_ipcp());
2535 execute(TC_pdp46_act_deact_icmp6());
2536 execute(TC_pdp46_act_deact_pcodns4());
2537 execute(TC_pdp46_act_deact_pcodns6());
2538 execute(TC_pdp46_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002539 execute(TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4());
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01002540 execute(TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002541 execute(TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6());
Oliver Smithee6a0882019-03-08 11:05:46 +01002542 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002543 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01002544
Harald Weltedca80052017-08-13 20:01:38 +02002545 execute(TC_echo_req_resp());
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01002546 execute(TC_echo_req_resp_gtpu());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002547 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002548 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002549
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01002550 execute(TC_pdp_act_restart_ctr_echo());
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002551
2552 execute(TC_lots_of_concurrent_pdp_ctx());
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002553 /* Keep at the end, crashes older osmo-ggsn versions (OS#5469): */
2554 execute(TC_addr_pool_exhaustion());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002555
2556 /* open5gs specific tests: */
2557 if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
2558 execute(TC_gy_charging_cc_time());
Pau Espin Pedrol52562c92022-05-23 15:45:46 +02002559 execute(TC_gy_charging_volume_quota_threshold());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002560 }
Harald Welte94ade362017-08-04 00:36:55 +02002561 }
Harald Welte379d45a2017-08-03 09:55:15 +02002562}