blob: 7f6f67ce34ad70f51609bb7776c4091ce0de6146 [file] [log] [blame]
Harald Welte379d45a2017-08-03 09:55:15 +02001module GGSN_Tests {
2
Harald Welte34b5a952019-05-27 11:54:11 +02003/* GGSN test suite in TTCN-3
4 * (C) 2017-2019 Harald Welte <laforge@gnumonks.org>
5 * (C) 2018-2019 sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
14
Harald Welte94ade362017-08-04 00:36:55 +020015 import from General_Types all;
Harald Welte811651e2017-08-05 15:25:06 +020016 import from Osmocom_Types all;
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +010017 import from Misc_Helpers all;
Harald Welte94ade362017-08-04 00:36:55 +020018 import from IPL4asp_PortType all;
19 import from IPL4asp_Types all;
20 import from GTP_CodecPort all;
21 import from GTP_CodecPort_CtrlFunct all;
Harald Weltec69cf4e2018-02-17 20:57:02 +010022 import from GTP_Templates all;
Harald Welte94ade362017-08-04 00:36:55 +020023 import from GTPC_Types all;
24 import from GTPU_Types all;
Harald Welte71a36022017-12-04 18:55:58 +010025 import from IPCP_Types all;
Harald Weltef8298542019-04-10 10:15:28 +020026 import from PAP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020027 import from IP_Types all;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +010028 import from ICMP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020029 import from ICMPv6_Types all;
Harald Welteddeecbb2017-08-18 22:53:30 +020030 import from Native_Functions all;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +020031 import from Osmocom_VTY_Functions all;
32 import from TELNETasp_PortType all;
Harald Welte94ade362017-08-04 00:36:55 +020033
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010034 import from DIAMETER_Types all;
35 import from DIAMETER_Templates all;
36 import from DIAMETER_Emulation all;
37
Harald Welte94ade362017-08-04 00:36:55 +020038 const integer GTP0_PORT := 3386;
39 const integer GTP1C_PORT := 2123;
40 const integer GTP1U_PORT := 2152;
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +010041 const integer PCRF_PORT := 3868;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +010042 const integer OCS_PORT := 3869;
Harald Welteddeecbb2017-08-18 22:53:30 +020043
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010044 type enumerated GGSN_Impl {
45 GGSN_IMPL_OSMOCOM,
46 GGSN_IMPL_OPEN5GS
47 };
48
Harald Welteddeecbb2017-08-18 22:53:30 +020049 modulepar {
Stefan Sperlingcb782b92018-04-03 16:03:15 +020050 /* Default IP addresses. May be overridden by GGSN_Tests configuration files. */
51
52 /* The SGSN simulated by TTCN3 will bind to these addresses for GTP control and GTP user planes. */
Harald Welteddeecbb2017-08-18 22:53:30 +020053 charstring m_bind_ip_gtpc := "127.23.42.1";
54 charstring m_bind_ip_gtpu := "127.23.42.1";
55
Stefan Sperlingcb782b92018-04-03 16:03:15 +020056 /* Addresses the GGSN which is being tested is listening on for SGSN connections. */
Harald Welteddeecbb2017-08-18 22:53:30 +020057 charstring m_ggsn_ip_gtpc := "127.0.0.6";
58 charstring m_ggsn_ip_gtpu := "127.0.0.6";
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010059
Stefan Sperlingcb782b92018-04-03 16:03:15 +020060 /*
61 * Our tests expect to see these DNS servers in 'Create PDP context responses' sent by the GGSN.
62 * These addresses must therefore match 'ip[v6] dns' options configured in osmo-ggsn.conf.
63 *
64 * These addresses are not expected to serve actual DNS requests. However, tests may expect to be
65 * able to ping these addresses (currently, IPv4 addresses must respond with an ICMP 'echo reply',
66 * and IPv6 addresses may respond with either ICMPv6 'echo reply' or 'destination unreachable').
67 */
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010068 charstring m_ggsn_ip4_dns1 := "192.168.100.1"
69 charstring m_ggsn_ip4_dns2 := "8.8.8.8"
Pau Espin Pedrol363ba482018-01-29 18:42:00 +010070 charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888"
71 charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844"
Stefan Sperlingcb782b92018-04-03 16:03:15 +020072
73 /*
74 * Additional address ranges are defined in osmo-ggsn.conf from which addresses are assigned
75 * to MS "behind" the simulated SGSN. These addresses appear on tun devices used by osmo-ggsn.
76 * The tests expect to be able to send ping packets between any two simulated MS within the same
77 * address range. This requires IP forwarding to be enabled on the corresponding tun interfaces.
78 */
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010079
80 GGSN_Impl m_ggsn_impl := GGSN_IMPL_OSMOCOM;
Harald Welteddeecbb2017-08-18 22:53:30 +020081 }
Harald Welte94ade362017-08-04 00:36:55 +020082
Harald Welte811651e2017-08-05 15:25:06 +020083 type set PdpContext {
84 hexstring imsi,
85 octetstring msisdn optional,
86 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020087 ProtConfigOptions pco_req optional,
88 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020089 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020090 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020091 BIT4 nsapi,
92 /* TEI (Data) local side */
93 OCT4 teid,
94 /* TEI (Control) local side */
95 OCT4 teic,
96 /* TEI (Data) remote side */
97 OCT4 teid_remote,
98 /* TEI (Control) remote side */
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +010099 OCT4 teic_remote,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100100 OCT1 ratType optional,
101 UserLocationInformation uli optional
Harald Welte811651e2017-08-05 15:25:06 +0200102 }
103
Harald Welte94ade362017-08-04 00:36:55 +0200104 type component GT_CT {
105 port GTPC_PT GTPC;
106 port GTPU_PT GTPU;
107
Harald Welte0be142b2017-08-13 13:28:10 +0200108 var boolean g_initialized := false;
109
Harald Welte94ade362017-08-04 00:36:55 +0200110 var OCT1 g_restart_ctr := '01'O;
111 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200112 var OCT4 g_sgsn_ip_c;
113 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +0200114 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200115 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
116 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200117 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200118
119 /* next to-be-sent GTP-C sequence number */
120 var uint16_t g_c_seq_nr;
121 /* next to-be-sent GTP-U sequence number */
122 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200123
124 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200125 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100126 var integer g_use_echo_intval := 0; /* 0 = disabled */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100127
128 /* emulated PCRF, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100129 var DIAMETER_Emulation_CT vc_Gx;
130 port DIAMETER_PT Gx_UNIT;
131 port DIAMETEREM_PROC_PT Gx_PROC;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100132 var DIAMETER_Emulation_CT vc_Gy;
133 port DIAMETER_PT Gy_UNIT;
134 port DIAMETEREM_PROC_PT Gy_PROC;
135 var integer g_gy_validity_time := 0; /* In seconds. 0 => disabled, !0 => grant over CC-Time period */
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200136 }
137
138 private function f_init_vty() runs on GT_CT {
139 map(self:GGSNVTY, system:GGSNVTY);
140 f_vty_set_prompts(GGSNVTY);
141 f_vty_transceive(GGSNVTY, "enable");
142 }
143
144 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
145 f_vty_enter_config(GGSNVTY);
146 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200147
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200148 f_vty_transceive(GGSNVTY, "apn internet");
149 if (enable) {
150 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
151 } else {
152 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
153 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200154 f_vty_transceive(GGSNVTY, "exit");
155
156 f_vty_transceive(GGSNVTY, "apn inet6");
157 if (enable) {
158 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
159 } else {
160 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
161 }
162 f_vty_transceive(GGSNVTY, "exit");
163
164 f_vty_transceive(GGSNVTY, "apn inet46");
165 if (enable) {
166 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
167 } else {
168 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
169 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200170 f_vty_transceive(GGSNVTY, "end");
171 }
172
173 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
174 if (expect_gptu_txseq) {
175 if (gtpu.s_bit != '1'B) {
176 log("GTPU sequence number expected but not present")
177 return false;
178 }
179 } else {
180 if (gtpu.s_bit != '0'B) {
181 log("GTPU sequence number not expected but present")
182 return false;
183 }
184 }
185 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200186 }
187
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100188 private function f_vty_enable_echo_interval(integer intval_sec) runs on GT_CT {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200189 f_vty_enter_config(GGSNVTY);
190 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100191 if (intval_sec > 0) {
192 f_vty_transceive(GGSNVTY, "echo-interval " & int2str(intval_sec));
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200193 } else {
194 f_vty_transceive(GGSNVTY, "no echo-interval");
195 }
196 f_vty_transceive(GGSNVTY, "end");
197 }
198
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100199 private function DiameterForwardUnitdataCallback(PDU_DIAMETER msg)
200 runs on DIAMETER_Emulation_CT return template PDU_DIAMETER {
201 DIAMETER_UNIT.send(msg);
202 return omit;
203 }
204
205 private function f_init_diameter(charstring id) runs on GT_CT {
206 var DIAMETEROps ops := {
207 create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback),
208 unitdata_cb := refers(DiameterForwardUnitdataCallback),
209 raw := true /* handler mode (single component for all IMSI)) */
210 };
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100211 var DIAMETER_conn_parameters pars;
212
213 /* Gx setup: */
214 pars := {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100215 remote_ip := m_ggsn_ip_gtpc,
216 remote_sctp_port := -1,
217 local_ip := m_bind_ip_gtpc,
218 local_sctp_port := PCRF_PORT,
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100219 origin_host := "pcrf.localdomain",
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100220 origin_realm := "localdomain",
Pau Espin Pedrol33b47492022-03-08 17:43:01 +0100221 auth_app_id := omit,
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100222 vendor_app_id := c_DIAMETER_3GPP_Gx_AID
223 };
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100224 vc_Gx := DIAMETER_Emulation_CT.create(id);
225 map(vc_Gx:DIAMETER, system:DIAMETER_CODEC_PT);
226 connect(vc_Gx:DIAMETER_UNIT, self:Gx_UNIT);
227 connect(vc_Gx:DIAMETER_PROC, self:Gx_PROC);
228 vc_Gx.start(DIAMETER_Emulation.main(ops, pars, id));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100229
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100230 /* Gy setup: */
231 pars := {
232 remote_ip := m_ggsn_ip_gtpc,
233 remote_sctp_port := -1,
234 local_ip := m_bind_ip_gtpc,
235 local_sctp_port := OCS_PORT,
236 origin_host := "ocs.localdomain",
237 origin_realm := "localdomain",
238 auth_app_id := c_DIAMETER_CREDIT_CONTROL_AID,
239 vendor_app_id := omit
240 };
241 vc_Gy := DIAMETER_Emulation_CT.create(id);
242 map(vc_Gy:DIAMETER, system:DIAMETER_CODEC_PT);
243 connect(vc_Gy:DIAMETER_UNIT, self:Gy_UNIT);
244 connect(vc_Gy:DIAMETER_PROC, self:Gy_PROC);
245 vc_Gy.start(DIAMETER_Emulation.main(ops, pars, id));
246
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100247 f_diameter_wait_capability(Gx_UNIT);
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100248 f_diameter_wait_capability(Gy_UNIT);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100249 /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdong ping-pongs):
250 * RFC6733 sec 5.1
251 * RFC3539 sec 3.4.1 [5]
252 * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49
253 */
254 f_sleep(1.0);
255 }
256
Harald Welte94ade362017-08-04 00:36:55 +0200257 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200258 if (g_initialized == true) {
259 return;
260 }
261 g_initialized := true;
262
Harald Welteddeecbb2017-08-18 22:53:30 +0200263 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
264 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
265
Harald Welte94ade362017-08-04 00:36:55 +0200266 var Result res;
267 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +0200268 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200269 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200270 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200271
272 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +0200273 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200274 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200275
276 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200277 g_c_seq_nr := f_rnd_int(65535);
278 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200279
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100280 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
281 f_init_vty();
282 f_vty_set_gpdu_txseq(use_gtpu_txseq);
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100283 f_vty_enable_echo_interval(g_use_echo_intval);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100284 } else if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
285 f_init_diameter(testcasename());
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100286 }
Harald Welte94ade362017-08-04 00:36:55 +0200287 }
288
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +0100289 function f_shutdown_helper() runs on GT_CT {
290 /* Sleep N3_REQUESTS * T3_REQUEST seconds, nowadays 5*3=15s.
291 * This ensures all retransmit queues are cleared before jumping
292 * into next tests, hence avoding situation where a test resuses
293 * a seqnum still in the GGSN's resp queue (dup req detector).
294 * See OS#5485 avout decreasing time. We could also add a new
295 * VTY command that calls gtp_clear_queues() */
296 f_sleep(15.0);
297 setverdict(pass);
298 }
299
Harald Welte94ade362017-08-04 00:36:55 +0200300 /* Altstep implementing responses to any incoming echo requests */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100301 private altstep pingpong() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200302 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200303 var Gtp1uUnitdata udu;
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100304 [g_use_echo_intval > 0] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200305 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200306 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200307 repeat;
308 };
Pau Espin Pedrol05118022022-02-17 19:49:13 +0100309 [g_use_echo_intval == 0] GTPC.receive(tr_GTPC_PING(?)) {
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100310 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
311 "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200312 };
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100313 [] T_default.timeout {
314 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
315 "pinpong T_default timeout");
316 };
Harald Welte94ade362017-08-04 00:36:55 +0200317 }
318
Harald Welte811651e2017-08-05 15:25:06 +0200319 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200320 const octetstring c_ApnInternet := '08696E7465726E6574'O;
321 const octetstring c_ApnInet6 := '05696E657436'O;
322 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200323
Harald Welte811651e2017-08-05 15:25:06 +0200324 /* return random NSAPI */
325 function f_rnd_nsapi() return BIT4 {
326 return int2bit(f_rnd_int(16), 4);
327 }
328
329 /* return random TEI[DC] */
330 function f_rnd_tei() return OCT4 {
331 return int2oct(f_rnd_int(4294967296), 4);
332 }
333
334 /* define an (internal) representation of a PDP context */
335 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100336 EndUserAddress eua, OCT1 ratType := '02'O /* GERAN */) := {
Harald Welte811651e2017-08-05 15:25:06 +0200337 imsi := imsi,
338 msisdn := msisdn,
339 nsapi := f_rnd_nsapi(),
340 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200341 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200342 eua := eua,
343 teid := f_rnd_tei(),
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100344 teic := f_rnd_tei(),
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100345 ratType := ratType,
346 uli := {
347 type_gtpc := '98'O,
348 lengthf := 0 /* filled in by encoder */,
349 geographicLocationType := '00'O /* CGI */,
350 geographicLocation := {
351 geographicLocationCGI := ts_GeographicLocationCGI('262'H, '42F'H, '0001'O, '0002'O)
352 }
353 }
Harald Welte811651e2017-08-05 15:25:06 +0200354 }
355
356 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200357 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200358 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200359 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200360 }
361
362 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200363 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200364 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200365 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
366 g_d_seq_nr := g_d_seq_nr + 1;
367 } else {
368 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
369 }
Harald Welte811651e2017-08-05 15:25:06 +0200370 }
371
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100372 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 +0200373 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100374
375 if (not match(cpr.cause.causevalue, exp_cause)) {
376 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
377 "CreatePDPContextResp: cause expectancies didn't match");
378 }
379
380 if (cpr.cause.causevalue == '80'O) { /* Accepted */
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200381 /* Check if EUA type corresponds to requested type */
382 if (match(ctx.eua, t_EuaIPv4(?)) and
383 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100384 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
385 "EUAv4 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200386 }
387 if (match(ctx.eua, t_EuaIPv6(?)) and
388 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100389 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
390 "EUAv6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200391 }
392 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
393 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100394 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
395 "EUAv4v6 expectancies didn't match");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200396 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100397 } else if (cpr.cause.causevalue == '81'O) { /* Cause: New PDP type due to network preference */
398 /* ETSI TS 129 060 7.3.2 Create PDP Context Response. OS#5449 */
399 /* This should only happen if EUA requested type is v4v6: */
400 if (not ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
401 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
402 "Cause not expected when requesting a non v4v6 EUA");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200403 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100404 if (not match(cpr.endUserAddress, (tr_EuaIPv4(?), tr_EuaIPv6(?)))) {
405 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
406 "Cause not expected when requesting+receiving EUAv4v6");
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200407 }
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200408 } else {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100409 if (ispresent(cpr.endUserAddress)) {
410 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
411 "EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
412 }
413 setverdict(pass);
414 return;
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200415 }
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100416
417 /* Check if PCO response corresponds to request */
418 if (ispresent(ctx.pco_req)) {
419 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
420 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
421 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
422 "IPv4 DNS Container requested, but missing");
423 }
424 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
425 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
426 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
427 "IPv6 DNS Container requested, but missing");
428 }
429 }
430 ctx.teid_remote := cpr.teidDataI.teidDataI;
431 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
432 ctx.eua := cpr.endUserAddress;
433 ctx.pco_neg := cpr.protConfigOptions;
434 setverdict(pass);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200435 }
436
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100437 function f_handle_update_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
438 var UpdatePDPContextResponseGGSN upr := ud.gtpc.gtpc_pdu.updatePDPContextResponse.updatePDPContextResponseGGSN;
439 if (exp_cause == '80'O and exp_cause == upr.cause.causevalue) {
440 ctx.teid_remote := upr.teidDataI.teidDataI;
441 ctx.teic_remote := upr.teidControlPlane.teidControlPlane;
442 if (ispresent(upr.protConfigOptions)) {
443 ctx.pco_neg := upr.protConfigOptions;
444 }
445 setverdict(pass);
446 } else if (exp_cause != '80'O and exp_cause == upr.cause.causevalue) {
447 setverdict(pass);
448 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100449 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
450 "UpdatePDPContextResp: cause expectancies didn't match");
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100451 }
452 }
453
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100454 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 +0100455 var PDU_DIAMETER rx_dia;
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100456 [] Gx_UNIT.receive(tr_DIA_Gx_CCR(req_type := req_type)) -> value rx_dia {
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100457 var template (omit) AVP avp;
458 var octetstring sess_id;
459 var AVP_Unsigned32 req_num;
460
461 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
462 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
463
464 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
465 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
466
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100467 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 +0100468 req_type, req_num));
469 }
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100470 [] Gx_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100471 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
472 log2str("Received unexpected DIAMETER ", rx_dia));
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100473 }
474 }
475
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100476 private altstep as_DIA_Gy_CCR(DCC_NONE_CC_Request_Type req_type) runs on GT_CT {
477 var PDU_DIAMETER rx_dia;
478 [] Gy_UNIT.receive(tr_DIA_Gy_CCR(req_type := req_type)) -> value rx_dia {
479 var template (value) PDU_DIAMETER tx_dia;
480 var template (omit) AVP avp;
481 var octetstring sess_id;
482 var AVP_Unsigned32 req_num;
483
484 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
485 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
486
487 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
488 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
489 if (g_gy_validity_time > 0) {
490 tx_dia := ts_DIA_Gy_CCA_ValidityTime(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id,
491 req_type, req_num, g_gy_validity_time);
492 } else {
493 tx_dia := ts_DIA_Gy_CCA(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id,
494 req_type, req_num);
495 }
496 Gy_UNIT.send(tx_dia);
497 }
498 [] Gy_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
499 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
500 log2str("Received unexpected DIAMETER Gy", rx_dia));
501 }
502 }
503
Harald Welte811651e2017-08-05 15:25:06 +0200504 /* send a PDP context activation */
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100505 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 +0200506 var Gtp1cUnitdata ud;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100507 var CreatePDPContextResponse cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200508 var default d;
509
510 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200511 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 +0200512 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100513 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req, ctx.ratType, ctx.uli));
Harald Welte94ade362017-08-04 00:36:55 +0200514 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200515 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100516 if (Gx_PROC.checkstate("Connected")) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100517 as_DIA_Gx_CCR(INITIAL_REQUEST);
518 }
519 if (Gy_PROC.checkstate("Connected")) {
520 as_DIA_Gy_CCR(INITIAL_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100521 }
Harald Welte94ade362017-08-04 00:36:55 +0200522 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200523 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200524 f_handle_create_req(ctx, ud, exp_cause);
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100525 cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
Harald Welte94ade362017-08-04 00:36:55 +0200526 }
527 }
528 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200529 T_default.stop;
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +0100530 return cpr;
Harald Welte94ade362017-08-04 00:36:55 +0200531 }
532
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200533 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
534 var Gtp1cUnitdata ud;
535 var default d;
536
537 T_default.start;
538 d := activate(pingpong());
539 alt {
540 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
541 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
542 setverdict(pass);
543 } else if (not istemplatekind(expect_cause, "omit") and
544 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
545 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
546 setverdict(pass);
547 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100548 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
549 "DeletePDPContextReq: cause expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200550 }
551
552 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
553 setverdict(pass);
554 } else {
555 setverdict(fail);
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100556 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
557 "DeletePDPContextReq: tearDownIndicator expectancies didn't match");
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200558 }
559 }
560 }
561 deactivate(d);
562 T_default.stop;
563 }
564
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +0100565 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 +0200566 var Gtp1cUnitdata ud;
567 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200568 var OCT4 expect_teid;
569
570 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
571 message with cause value "Non existent" shall be zero. */
572 if (expect_causevalue == 'C0'O) {
573 expect_teid := '00000000'O;
574 } else {
575 expect_teid := ctx.teic;
576 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200577
Harald Welte41575e92017-08-13 13:49:57 +0200578 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 +0200579 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200580 d := activate(pingpong());
Pau Espin Pedrol45d57022022-03-08 13:49:02 +0100581 if (Gx_PROC.checkstate("Connected") and expect_diameter) {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +0100582 as_DIA_Gx_CCR(TERMINATION_REQUEST);
583 }
584 if (Gy_PROC.checkstate("Connected") and expect_diameter) {
585 as_DIA_Gy_CCR(TERMINATION_REQUEST);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100586 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200587 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200588 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
589 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200590 setverdict(pass);
591 } else {
Pau Espin Pedrol8ad031a2022-02-16 17:33:43 +0100592 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
593 "DeletePDPContextResp: cause expectancies didn't match");
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200594 }
595 }
596 }
597 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200598 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200599 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100600
601 /* send a Update PdP Context Request, expect Response */
602 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 {
603 var Gtp1cUnitdata ud;
604 var default d;
605
606 if (not istemplatekind(new_teid, "omit")) {
607 ctx.teid := valueof(new_teid);
608 }
609 if (not istemplatekind(new_teic, "omit")) {
610 ctx.teic := valueof(new_teic);
611 }
612
613 log("sending UpdatePDP");
614 f_send_gtpc(ts_GTPC_UpdatePDP(g_peer_c, ctx.teic_remote, g_c_seq_nr, ctx.imsi, g_restart_ctr,
615 ctx.teid, ctx.teic, ctx.nsapi, g_sgsn_ip_c, g_sgsn_ip_u,
616 ctx.pco_req, ctx.ratType, ctx.uli));
617 T_default.start;
618 d := activate(pingpong());
619 alt {
620 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, updatePDPContextResponse, ctx.teic)) -> value ud {
621 f_handle_update_req(ctx, ud, exp_cause);
622 }
623 }
624 deactivate(d);
625 T_default.stop;
626 }
627
Harald Welte811651e2017-08-05 15:25:06 +0200628 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
629 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
630 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
631 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200632
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200633 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100634 template PDU_ICMP ts_ICMPv4_ERQ := {
635 echo := {
636 type_field := 8,
637 code := 0,
638 checksum := '0000'O,
639 identifier := '0345'O,
640 sequence_number := '0001'O,
641 data := ''O
642 }
643 }
644
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200645 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100646 template PDU_ICMP tr_ICMPv4_ERQ := {
647 echo := {
648 type_field := 8,
649 code := 0,
650 checksum := ?,
651 identifier := ?,
652 sequence_number := ?,
653 data := ?
654 }
655 }
656
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200657 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100658 template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
659 echo_reply := {
660 type_field := 0,
661 code := 0,
662 checksum := ?,
663 identifier := ?,
664 sequence_number := ?,
665 data := data
666 }
667 }
668
669 /* template for receiving/matching an ICMPv6 Destination Unreachable */
670 template PDU_ICMP tr_ICMPv4_DU := {
671 destination_unreachable := {
672 type_field := 1,
673 code := ?,
674 checksum := ?,
675 unused := ?,
676 original_ip_msg := ?
677 }
678 }
679
680 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
681 template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
682 header := {
683 ver := 4,
684 hlen := 5,
685 tos := 0,
686 tlen := tlen,
687 id := 35902,
688 res := '0'B,
689 dfrag := '1'B,
690 mfrag := '0'B,
691 foffset := 0,
692 ttl := 64,
693 proto := proto,
694 cksum := 0,
695 srcaddr := srcaddr,
696 dstaddr := dstaddr
697 },
698 ext_headers := omit,
699 payload := payload
700 }
701
Harald Welte231b9412017-08-09 17:16:31 +0200702 /* template to generate a 'Prefix Information' ICMPv6 option */
703 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
704 prefixInformation := {
705 typeField := 3,
706 lengthIndicator := 8,
707 prefixLength := prefix_len,
708 reserved1 := '000000'B,
709 a_Bit := '0'B,
710 l_Bit := '0'B,
711 validLifetime := oct2int('FFFFFFFF'O),
712 preferredLifetime := oct2int('FFFFFFFF'O),
713 reserved2 := '00000000'O,
714 prefix := prefix
715 }
716 }
717
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200718 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100719 template PDU_ICMPv6 ts_ICMPv6_ERQ := {
720 echoRequest := {
721 typeField := 128,
722 code := 0,
723 checksum := '0000'O,
724 identifier := 0,
725 sequenceNr := 0,
726 data := ''O
727 }
728 }
729
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200730 /* template for sending an ICMPv6 router solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200731 template PDU_ICMPv6 ts_ICMPv6_RS := {
732 routerSolicitation := {
733 typeField := 133,
734 code := 0,
735 checksum := '0000'O,
736 reserved := '00000000'O,
737 /* TODO: do we need 'Source link-layer address' ? */
738 options := omit
739 }
740 }
741
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200742 /* template for sending an ICMPv6 router advertisement */
Harald Welte231b9412017-08-09 17:16:31 +0200743 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
744 routerAdvertisement := {
745 typeField := 134,
746 code := 0,
747 checksum := '0000'O,
748 curHopLimit := ?,
749 reserved := '000000'B,
750 o_Bit := '0'B,
751 m_Bit := '0'B,
752 routerLifetime := oct2int('FFFF'O),
753 reachableTime := oct2int('FFFFFFFF'O),
754 retransTimer := oct2int('FFFFFFFF'O),
755 options := {
756 ts_ICMP6_OptPrefix(prefix, prefix_len)
757 }
758 }
759 }
760
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200761 /* template for sending an ICMPv6 neighbor solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200762 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
763 neighborSolicitation := {
764 typeField := 135,
765 code := 0,
766 checksum := '0000'O,
767 reserved := '00000000'O,
768 targetAddress := target_addr,
769 /* TODO: do we need 'Source link-layer address' ? */
770 options := omit
771 }
772 }
773
774 /* derive ICMPv6 link-local address from lower 64bit of link_id */
775 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
776 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
777 prefixInformation := {
778 typeField := 3,
779 lengthIndicator := 4,
780 prefixLength := prefix_len,
781 reserved1 := ?,
782 a_Bit := ?,
783 l_Bit := ?,
784 validLifetime := ?,
785 preferredLifetime := ?,
786 reserved2 := ?,
787 prefix := prefix
788 }
789 }
790
791 /* template for receiving/matching an ICMPv6 router advertisement */
792 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
793 routerAdvertisement := {
794 typeField := 134,
795 code := 0,
796 checksum := ?,
797 curHopLimit := ?,
798 reserved := ?,
799 o_Bit := '0'B,
800 m_Bit := '0'B,
801 routerLifetime := ?,
802 reachableTime := ?,
803 retransTimer := ?,
804 options := {
805 tr_ICMP6_OptPrefix(prefix, prefix_len)
806 }
807 }
808 }
809
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100810 /* template for receiving/matching an ICMPv6 Destination Unreachable */
811 template PDU_ICMPv6 tr_ICMPv6_DU := {
812 destinationUnreachable := {
813 typeField := 1,
814 code := ?,
815 checksum := ?,
816 unused := ?,
817 originalIpMsg := ?
818 }
819 }
820
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200821 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100822 template PDU_ICMPv6 tr_ICMPv6_ERQ := {
823 echoRequest := {
824 typeField := 128,
825 code := 0,
826 checksum := ?,
827 identifier := ?,
828 sequenceNr := ?,
829 data := ?
830 }
831 }
832
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100833 /* template for receiving/matching an ICMPv6 echo reply */
834 template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
835 echoReply := {
836 typeField := 129,
837 code := 0,
838 checksum := ?,
839 identifier := ?,
840 sequenceNr := ?,
841 data := data
842 }
843 }
844
Harald Welte231b9412017-08-09 17:16:31 +0200845 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
846 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
847 header := {
848 ver := 6,
849 trclass := 0,
850 flabel := 0,
851 plen := 0,
852 nexthead := nexthead,
853 hlim := hlim,
854 srcaddr := srcaddr,
855 dstaddr := dstaddr
856 },
857 ext_headers := omit,
858 payload := payload
859 }
860
861 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
862 return 'FE80000000000000'O & substr(link_id, 8, 8);
863 }
864
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100865 function f_ipv6_global(in OCT16 link_id) return OCT16 {
866 return substr(link_id, 0, 8) & '1234123412341234'O;
867 }
868
869 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
870 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
871 var integer i;
872 var octetstring res := substr(addr, 0, prefix);
873 for (i := prefix; i < lengthof(addr); i := i + 1) {
874 var octetstring a := addr[i] xor4b '11'O;
875 res := res & a;
876 }
877 return res;
878 }
879
Harald Welte231b9412017-08-09 17:16:31 +0200880 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
881 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
882 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
883 }
884
885 /* generate and encode ICMPv6 router solicitation */
886 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
887 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
888 var OCT16 saddr := f_ipv6_link_local(link_id);
889
890 var octetstring tmp;
891 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
892 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
893
894 return f_IPv6_enc(ip6);
895 }
896
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100897 /* Get link-id from PDP Context EUA */
898 function f_ctx_get_ipv6_interface_id(in PdpContext ctx) return OCT16 {
899 var OCT16 interface_id;
900 if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
901 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
902 } else if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv6)) {
903 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
904 } else {
905 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected request to submit icmpv6 rs in IPv4 PDP context");
906 }
907 return interface_id;
908 }
909
Harald Welte231b9412017-08-09 17:16:31 +0200910 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
911 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100912 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200913 return f_gen_icmpv6_router_solicitation(interface_id);
914 }
915
916 /* generate and encode ICMPv6 neighbor solicitation */
917 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
918 var octetstring tmp;
919 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
920 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
921 return f_IPv6_enc(ip6);
922 }
923
924 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
925 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100926 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200927 var OCT16 link_local := f_ipv6_link_local(interface_id);
928 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
929
930 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
931 }
932
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100933 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
934 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring {
935 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ));
936 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
937 var octetstring data := f_IPv4_enc(ip4);
938 var OCT2 cksum := f_IPv4_checksum(data);
939 data[10] := cksum[0];
940 data[11] := cksum[1];
941 return data;
942 }
943
944 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
945 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
946 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
947 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
948 var octetstring data := f_IPv6_enc(ip6);
949 return data;
950 }
951
952 /* Wait for ICMPv4 from GTP */
953 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +0200954 var Gtp1uUnitdata ud;
955 T_default.start;
956 alt {
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100957 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ctx.teid)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200958 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200959 setverdict(fail);
960 stop;
961 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100962 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
963 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
964 if (ip4.header.ver != 4) {
965 repeat;
966 }
967 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
968 if (not match(icmp4, expected)) {
969 repeat;
970 }
971 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100972 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
973 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
974 "Received wrong local TEID");
975 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100976 [] GTPU.receive { setverdict(fail); }
977 [] T_default.timeout { setverdict(fail); }
978 }
979 T_default.stop;
980 }
981
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100982 /* Wait for ICMPv4 echo request from GTP */
983 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
984 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
985 }
986
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100987 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
988 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
989 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
990 }
991
992 /* Wait for ICMPv6 from GTP */
993 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
994 var Gtp1uUnitdata ud;
995 T_default.start;
996 alt {
Harald Welte231b9412017-08-09 17:16:31 +0200997 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200998 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200999 setverdict(fail);
1000 stop;
1001 }
Harald Welte231b9412017-08-09 17:16:31 +02001002 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1003 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001004 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +02001005 repeat;
1006 }
1007 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001008 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +02001009 repeat;
1010 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001011 /* We are waiting for RA, update ctx */
1012 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
1013 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
1014 log("RA with /64 prefix ", ctx.ip6_prefix);
1015 }
Harald Welte231b9412017-08-09 17:16:31 +02001016 }
1017 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
1018 [] GTPU.receive { setverdict(fail); }
1019 [] T_default.timeout { setverdict(fail); }
1020 }
1021 T_default.stop;
1022 }
1023
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001024 /* wait for GGSN to send us an ICMPv6 router advertisement */
1025 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
1026 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
1027 }
1028
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001029 /* Wait for ICMPv6 echo request from GTP */
1030 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
1031 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
1032 }
1033
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001034 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
1035 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
1036 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
1037 }
1038
Oliver Smithee6a0882019-03-08 11:05:46 +01001039 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
1040 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
1041 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1042 return f_gen_icmpv6_router_solicitation(interface_id);
1043 }
1044
1045 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
1046 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
1047 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
1048 var OCT16 link_local := f_ipv6_link_local(interface_id);
1049 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
1050
1051 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
1052 }
1053
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001054 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
1055 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
1056 T_default.start;
1057 alt {
1058 [] GTPU.receive { setverdict(fail); }
1059 [] T_default.timeout { }
1060 }
1061 T_default.stop;
1062 }
1063
Harald Welte79737b42019-04-10 10:39:30 +02001064 /* list of protocols where we don't accept duplicates */
1065 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
1066 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
1067 var integer i;
1068 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
1069 if (id == protocol_ids_nodupes[i]) {
1070 return false;
1071 }
1072 }
1073 return true;
1074 }
1075
1076 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
1077 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
1078 var OCT2List protocol_ids := {};
1079 var integer i, j;
1080 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
1081 var OCT2 id := pco.protocols[i].protocolID;
1082 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
1083 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
1084 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
1085 }
1086 }
1087 protocol_ids := protocol_ids & { id };
1088 }
1089 }
1090
Harald Welte0ef285b2017-08-13 20:06:01 +02001091 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +02001092 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +02001093 f_init();
Harald Welte231b9412017-08-09 17:16:31 +02001094
Harald Welteed097432017-08-13 13:28:49 +02001095 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welte811651e2017-08-05 15:25:06 +02001096 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +02001097 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001098 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001099 }
1100
Harald Welte0ef285b2017-08-13 20:06:01 +02001101 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001102 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
1103 f_init();
1104
Harald Welteed097432017-08-13 13:28:49 +02001105 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001106 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1107 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001108
Harald Welte79737b42019-04-10 10:39:30 +02001109 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001110 /* verify PCO contains both primary and secondary DNS */
1111 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1112 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1113 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1114 }
1115
1116 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1117 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1118 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1119 }
1120
Harald Welteed7a1772017-08-09 20:26:20 +02001121 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001122 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001123 }
1124
Harald Welte0ef285b2017-08-13 20:06:01 +02001125 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +02001126 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
1127 f_init();
1128
Harald Welteed097432017-08-13 13:28:49 +02001129 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001130 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1131 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001132
Harald Welte79737b42019-04-10 10:39:30 +02001133 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +02001134 //f_send_gtpu(ctx, c_router_solicit);
1135 //f_send_gtpu(ctx, c_neigh_solicit);
1136
1137 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1138 f_wait_rtr_adv(ctx);
1139 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1140
Harald Welte811651e2017-08-05 15:25:06 +02001141 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001142 f_shutdown_helper();
Harald Welte94ade362017-08-04 00:36:55 +02001143 }
1144
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001145 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
1146 Test we can send ICMPv6 ping over GTPU to DNS server. */
1147 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
1148 f_init();
1149 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1150 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1151 f_pdp_ctx_act(ctx);
1152
1153 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1154 f_wait_rtr_adv(ctx);
1155 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1156
1157 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1158
1159 /* Check if we can use valid link-local src addr. */
1160 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1161 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
Pau Espin Pedrolb63d85f2022-02-07 16:11:47 +01001162 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
1163 f_wait_icmp6_echo_reply(ctx);
1164 } else {
1165 f_wait_gtpu_fail(ctx);
1166 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001167
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001168 /* Check if we can use valid global src addr, should work */
1169 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1170 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
1171 f_wait_icmp6_echo_reply(ctx);
1172
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001173 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001174 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001175 }
1176
1177 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1178 testcase TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr() runs on GT_CT {
1179 f_init();
1180 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1181 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1182 f_pdp_ctx_act(ctx);
1183
1184 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1185 f_wait_rtr_adv(ctx);
1186 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1187
1188 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1189 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1190 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1191 f_wait_gtpu_fail(ctx);
1192
1193 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001194 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001195 }
1196
1197 /* Assert that packets with wrong global src addr are dropped by GGSN */
1198 testcase TC_pdp6_act_deact_gtpu_access_wrong_global_saddr() runs on GT_CT {
1199 f_init();
1200 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1201 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1202 f_pdp_ctx_act(ctx);
1203
1204 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1205 f_wait_rtr_adv(ctx);
1206 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1207
1208 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1209 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001210 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1211 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
1212 f_wait_gtpu_fail(ctx);
1213
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001214 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001215 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001216 }
1217
1218 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped */
1219 testcase TC_pdp6_act_deact_gtpu_access_ipv4_apn6() runs on GT_CT {
1220 f_init();
1221 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1222 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1223 f_pdp_ctx_act(ctx);
1224
1225 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1226 f_wait_rtr_adv(ctx);
1227 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1228
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001229 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
1230 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
1231 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
1232 f_wait_gtpu_fail(ctx);
1233
1234 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001235 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001236 }
1237
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001238 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1239 testcase TC_pdp6_clients_interact() runs on GT_CT {
1240 f_init();
1241 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1242 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1243 f_pdp_ctx_act(ctxA);
1244 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
1245 f_wait_rtr_adv(ctxA);
1246 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
1247
1248 f_pdp_ctx_act(ctxB);
1249 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
1250 f_wait_rtr_adv(ctxB);
1251 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
1252
1253 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1254 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1255 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1256 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1257
1258 /* Validate if clients can interact using ll addr. */
1259 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1260 f_wait_gtpu_fail(ctxB);
1261
1262 /* Validate if clients can interact using global addr. */
1263 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1264 f_wait_gtpu_fail(ctxB);
1265
1266 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001267 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001268 f_shutdown_helper();
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001269 }
1270
Harald Welte0ef285b2017-08-13 20:06:01 +02001271 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +02001272 testcase TC_pdp4_act_deact() runs on GT_CT {
1273 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001274 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001275 f_pdp_ctx_act(ctx);
1276 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001277 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001278 }
1279
Harald Welte0ef285b2017-08-13 20:06:01 +02001280 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +02001281 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
1282 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001283 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1284 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +02001285 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001286 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +02001287 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001288 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +01001289 /* verify IPCP is at all contained */
1290 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1291 setverdict(fail, "IPCP not found in PCO");
1292 }
1293 /* verify IPCP contains both primary and secondary DNS */
1294 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001295 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1296 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1297 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1298 } else {
1299 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1300 }
Harald Welte71a36022017-12-04 18:55:58 +01001301 }
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 Weltef8298542019-04-10 10:15:28 +02001306 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
1307 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
1308 f_init();
1309 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1310 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1311 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1312 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1313 f_pdp_ctx_act(ctx);
1314 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1315 /* verify IPCP is at all contained */
1316 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1317 setverdict(fail, "IPCP not found in PCO");
1318 }
1319 /* verify IPCP contains both primary and secondary DNS */
1320 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1321 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1322 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1323 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1324 } else {
1325 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1326 }
1327 }
1328 /* verify that PAP is contained */
1329 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1330 setverdict(fail, "PAP not found in PCO");
1331 }
1332 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1333 if (not match(pap, tr_PAP_AuthAck)) {
1334 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1335 }
1336 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001337 f_shutdown_helper();
Harald Weltef8298542019-04-10 10:15:28 +02001338 }
1339
Harald Welte0ef285b2017-08-13 20:06:01 +02001340 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001341 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1342 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001343 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001344 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001345 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001346
Harald Welte79737b42019-04-10 10:39:30 +02001347 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001348 /* verify PCO contains both primary and secondary DNS */
1349 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1350 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1351 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1352 }
1353
1354 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1355 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1356 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1357 }
1358
Harald Welteed7a1772017-08-09 20:26:20 +02001359 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001360 f_shutdown_helper();
Harald Welteed7a1772017-08-09 20:26:20 +02001361 }
1362
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001363 /* Test PDP context activation for dynamic IPv4 EUA.
1364 Test we can send ICMPv6 ping over GTPU to DNS server. */
1365 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1366 f_init();
1367 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1368 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1369 f_pdp_ctx_act(ctx);
1370
Harald Welte79737b42019-04-10 10:39:30 +02001371 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001372 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1373
1374 /* Check if we can use valid global src addr, should work */
1375 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1376 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1377 f_wait_icmp4_echo_reply(ctx);
1378
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001379 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001380 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001381 }
1382
1383 /* Assert that packets with wrong global src addr are dropped by GGSN */
1384 testcase TC_pdp4_act_deact_gtpu_access_wrong_saddr() runs on GT_CT {
1385 f_init();
1386 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1387 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1388 f_pdp_ctx_act(ctx);
1389
1390 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1391 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1392 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001393 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1394 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1395 f_wait_gtpu_fail(ctx);
1396
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001397 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001398 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001399 }
1400
1401 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1402 testcase TC_pdp4_act_deact_gtpu_access_ipv6_apn4() runs on GT_CT {
1403 f_init();
1404 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1405 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1406 f_pdp_ctx_act(ctx);
1407
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001408 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1409 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1410 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1411 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001412
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001413 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001414 f_shutdown_helper();
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001415 }
1416
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001417 /* Helper function for tests below. */
1418 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001419 f_init();
1420 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1421 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1422 f_pdp_ctx_act(ctxA);
1423 f_pdp_ctx_act(ctxB);
1424 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1425 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1426 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1427 f_wait_icmp4_echo_request(ctxB);
1428
1429 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001430 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001431 }
1432
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001433 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1434 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001435 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001436 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001437 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001438 }
1439
1440 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1441 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001442 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001443 f_pdp4_clients_interact();
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001444 f_shutdown_helper();
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001445 }
1446
Harald Weltedca80052017-08-13 20:01:38 +02001447 testcase TC_echo_req_resp() runs on GT_CT {
1448 f_init();
1449 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1450 T_default.start;
1451 alt {
1452 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1453 [] GTPC.receive { repeat; };
1454 [] T_default.timeout { setverdict(fail); }
1455 }
1456 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001457 f_shutdown_helper();
Harald Weltedca80052017-08-13 20:01:38 +02001458 }
1459
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001460 testcase TC_echo_req_resp_gtpu() runs on GT_CT {
1461 f_init();
1462 GTPU.send(ts_GTPU_PING(g_peer_u, g_d_seq_nr));
1463 T_default.start;
1464 alt {
1465 [] GTPU.receive(tr_GTPU_PONG(g_peer_u)) { setverdict(pass); };
1466 [] GTPU.receive { repeat; };
1467 [] T_default.timeout { setverdict(fail); }
1468 }
1469 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001470 f_shutdown_helper();
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001471 }
1472
Philipp Maier33e52612018-05-30 17:22:02 +02001473 /* Test if the parser can cope with PCO that only contain either a
1474 * single primary DNS or a secondary DNS. */
1475 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1476
1477 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1478 * the test is executed.
1479 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1480
1481 f_init();
1482 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1483 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1484 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1485 var octetstring pco_neg_dns;
1486 var octetstring pco_neg_dns_expected;
1487
1488 /* PCO with primary DNS only */
1489 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1490 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001491 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001492 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1493 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1494 /* Note: The prepended hex bytes encode the following information:
1495 * 0x02 = Configuration ACK
1496 * 0x00 = Identifier
1497 * 0x000a = Length
1498 * 0x81 = Type (Primary DNS Server Address)
1499 * 0x06 = Length
1500 * (4 byte IP-Address appended) */
1501 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1502 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1503 }
1504 f_pdp_ctx_del(ctx, '1'B);
1505
1506 /* PCO with secondary DNS only */
Harald Welte7ef6d102021-04-01 21:24:35 +02001507 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001508 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1509 f_pdp_ctx_act(ctx);
1510 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1511 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1512 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1513 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1514 }
1515 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001516 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001517 }
1518
1519 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1520 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1521 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1522 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1523
1524 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1525 * the test is executed.
1526 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1527
1528 f_init();
1529 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1530 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1531 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1532 var octetstring pco_neg_dns;
1533 var octetstring pco_neg_dns_expected;
1534
1535 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1536 f_pdp_ctx_act(ctx);
1537
1538 /* Check if primary DNS is contained */
1539 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1540 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1541 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1542 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1543 }
Philipp Maier33e52612018-05-30 17:22:02 +02001544
1545 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001546 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1547 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001548 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1549 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1550 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1551 }
1552 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001553 f_shutdown_helper();
Philipp Maier33e52612018-05-30 17:22:02 +02001554 }
1555
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001556 /* Validate that SUT updates remote TEIC when requested through UpdatePDPContextRequest */
1557 testcase TC_pdp4_act_update_teic() runs on GT_CT {
1558 f_init();
1559 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1560 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1561 f_pdp_ctx_act(ctx);
1562
1563 /* UpdatePDPContestRequest changing the local TEIC */
1564 var OCT4 new_teic := ctx.teic;
1565 new_teic[3] := new_teic[3] xor4b '11'O;
1566 f_pdp_ctx_update(ctx, new_teic := new_teic);
1567
1568 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001569 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001570 }
1571
1572 /* Validate that SUT updates remote TEID when requested through UpdatePDPContextRequest */
1573 testcase TC_pdp4_act_update_teid() runs on GT_CT {
1574 f_init();
1575 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1576 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1577 f_pdp_ctx_act(ctx);
1578
1579 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1580 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1581 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1582
1583 /* Data is sent (back) to the local TEID established during CreatePDPContext */
1584 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1585 f_wait_icmp4_echo_reply(ctx);
1586
1587 /* UpdatePDPContestRequest changing the local TEID */
1588 var OCT4 new_teid := ctx.teid;
1589 new_teid[3] := new_teid[3] xor4b '11'O;
1590 f_pdp_ctx_update(ctx, new_teid := new_teid);
1591
1592 /* Check if we can send data after updating the PDP context. Answer should be sent to the new TEID */
1593 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1594 f_wait_icmp4_echo_reply(ctx);
1595
1596 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001597 f_shutdown_helper();
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001598 }
1599
Oliver Smithee6a0882019-03-08 11:05:46 +01001600 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1601 testcase TC_pdp46_act_deact() runs on GT_CT {
1602 f_init();
1603 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1604 f_pdp_ctx_act(ctx);
1605 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001606 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001607 }
1608
1609 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1610 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1611 f_init();
1612 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1613 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1614 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1615 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1616 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001617 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001618 /* verify IPCP is at all contained */
1619 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1620 setverdict(fail, "IPCP not found in PCO");
1621 }
Harald Welte79737b42019-04-10 10:39:30 +02001622 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001623 /* verify IPCP contains both primary and secondary IPv4 DNS */
1624 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1625 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1626 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1627 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1628 } else {
1629 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1630 }
1631 }
1632 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001633 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001634 }
1635
1636 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1637 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1638 f_init();
1639 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1640 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1641 f_pdp_ctx_act(ctx);
1642
1643 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1644 f_wait_rtr_adv(ctx);
1645 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1646
1647 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001648 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001649 }
1650
1651 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1652 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1653 f_init();
1654
1655 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1656 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1657 f_pdp_ctx_act(ctx);
1658
Harald Welte79737b42019-04-10 10:39:30 +02001659 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001660 /* verify PCO contains both primary and secondary IPv4 DNS */
1661 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1662 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1663 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1664 }
1665
1666 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1667 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1668 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1669 }
1670
1671 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001672 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001673 }
1674
1675 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1676 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1677 f_init();
1678
1679 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1680 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1681 f_pdp_ctx_act(ctx);
1682
Harald Welte79737b42019-04-10 10:39:30 +02001683 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001684 /* verify PCO contains both primary and secondary IPv6 DNS */
1685 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1686 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1687 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1688 }
1689
1690 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1691 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1692 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1693 }
1694
1695 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001696 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001697 }
1698
1699 /* Test PDP context activation for dynamic IPv4v6 EUA.
1700 Test we can send ICMPv6 ping over GTPU to DNS server. */
1701 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1702 f_init();
1703 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1704 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1705 f_pdp_ctx_act(ctx);
1706
1707 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1708
1709 /* Check if we can use valid global src addr, should work */
1710 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1711 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1712 f_wait_icmp4_echo_reply(ctx);
1713
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001714 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001715 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001716 }
1717
1718 /* Assert that packets with wrong ipv4 src addr are dropped by GGSN on APN IPv4v6 */
1719 testcase TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4() runs on GT_CT {
1720 f_init();
1721 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1722 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1723 f_pdp_ctx_act(ctx);
1724
1725 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1726 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
Oliver Smithee6a0882019-03-08 11:05:46 +01001727 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1728 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1729 f_wait_gtpu_fail(ctx);
1730
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001731 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001732 f_shutdown_helper();
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001733 }
1734
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001735 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1736 testcase TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6() runs on GT_CT {
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001737 f_init();
1738 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1739 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1740 f_pdp_ctx_act(ctx);
1741
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001742 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1743 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1744 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1745 f_wait_gtpu_fail(ctx);
1746
1747 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001748 f_shutdown_helper();
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001749 }
1750
1751 /* Assert that packets with wrong ipv6 global src addr are dropped by GGSN on APN IPv4v6 */
1752 testcase TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6() runs on GT_CT {
1753 f_init();
1754 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1755 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1756 f_pdp_ctx_act(ctx);
1757
1758 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1759 f_wait_rtr_adv(ctx);
1760 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1761
1762 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1763 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1764 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1765 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
Oliver Smithee6a0882019-03-08 11:05:46 +01001766 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001767
Oliver Smithee6a0882019-03-08 11:05:46 +01001768 f_pdp_ctx_del(ctx, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001769 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001770 }
1771
1772 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1773 testcase TC_pdp46_clients_interact() runs on GT_CT {
1774 f_init();
1775 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1776 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1777 f_pdp_ctx_act(ctxA);
1778 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1779 f_wait_rtr_adv(ctxA);
1780 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1781
1782 f_pdp_ctx_act(ctxB);
1783 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1784 f_wait_rtr_adv(ctxB);
1785 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1786
1787 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1788 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1789 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1790 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1791
1792 /* Validate if clients can interact using ll addr. */
1793 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1794 f_wait_gtpu_fail(ctxB);
1795
1796 /* Validate if clients can interact using global addr. */
1797 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1798 f_wait_gtpu_fail(ctxB);
1799
1800 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001801 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001802 f_shutdown_helper();
Oliver Smithee6a0882019-03-08 11:05:46 +01001803 }
1804
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001805 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
1806 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001807 const OCT1 cause_accept := '80'O; /* Normal accept cause */
1808 const OCT1 cause_new_pdp_type := '81'O; /* Cause: New PDP type due to network preference */
1809 const OCT1 cause_unknown_pdp := 'DC'O; /* Cause: Unknown PDP address or PDP type */
1810 var CreatePDPContextResponse cpr;
1811
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001812 f_init();
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001813 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001814 cpr := f_pdp_ctx_act(ctx46, (cause_unknown_pdp, cause_new_pdp_type));
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001815
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001816 if (cpr.cause.causevalue == cause_new_pdp_type) {
1817 /* 3GPP TS 23.060 sec 9.2.1: "If the MS requests PDP type IPv4v6,
1818 * but the operator preferences dictate the use of a single IP
1819 * version only, the PDP type shall be changed to a single address
1820 * PDP type (IPv4 or IPv6) and a reason cause shall be returned to
1821 * the MS indicating that only the assigned PDP type is allowed. In
1822 * this case, the MS shall not request another PDP context for the
1823 * other PDP type during the existence of the PDP context." */
1824 f_pdp_ctx_del(ctx46, '1'B);
1825 } else {
1826 /* 3GPP TS 23.060 sec 9.2.1 NOTE 5: If the MS requests PDP type
1827 * IPv4v6, and the PDP context is rejected due to "unknown PDP
1828 * type", the MS can attempt to establish dual-stack connectivity
1829 * by performing two PDP context request procedures to activate an
1830 * IPv4 PDP context and an IPv6 PDP context, both to the same APN. A
1831 * typical MS first attempts v4v6, and if rejected, then tries v4
1832 * and v6 separetly */
1833 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1834 f_pdp_ctx_act(ctx4, cause_accept); /* Normal accept cause */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001835
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001836 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv6Dyn)));
1837 f_pdp_ctx_act(ctx6, cause_unknown_pdp); /* Cause: Unknown PDP address or PDP type */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001838
Pau Espin Pedrol0f464d62022-02-23 14:04:29 +01001839 f_pdp_ctx_del(ctx4, '1'B);
1840 }
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001841 f_shutdown_helper();
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001842 }
1843
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001844 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
1845 testcase TC_pdp_act2_recovery() runs on GT_CT {
1846 var Gtp1cUnitdata ud;
1847 var default d;
1848 var boolean ctxA_deleted := false;
1849 var boolean ctxB_created := false;
1850
1851 f_init();
1852 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1853 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1854 f_pdp_ctx_act(ctxA);
1855
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06001856 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001857
1858 log("sending 2nd CreatePDP (recovery increased)");
1859 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
1860 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
1861 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
1862 T_default.start;
1863 d := activate(pingpong());
1864 alt {
1865 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
1866 f_handle_create_req(ctxB, ud);
1867 if (not ctxB_created) {
1868 ctxB_created := true;
1869 setverdict(pass);
1870 } else {
1871 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
1872 }
1873
1874 if (not ctxA_deleted) {
1875 repeat;
1876 }
1877 }
1878 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
1879 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
1880 setverdict(pass);
1881 } else {
1882 setverdict(fail);
1883 }
1884
1885 if (not ctxA_deleted) {
1886 ctxA_deleted := true;
1887 setverdict(pass);
1888 } else {
1889 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
1890 }
1891
1892 if (not ctxB_created) {
1893 repeat;
1894 }
1895 }
1896 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
1897 setverdict(fail, "GGSN dropping still valid pdp ctx");
1898 }
1899 }
1900 deactivate(d);
1901 T_default.stop;
1902
1903 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001904 f_shutdown_helper();
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001905 }
1906
1907
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001908 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent
1909 responses (60 seconds): If same delete req is sent and duplicate is
1910 detected, saved duplicate response should be sent back. */
1911 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
1912 f_init();
1913 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1914 f_pdp_ctx_act(ctx);
1915 f_pdp_ctx_del(ctx, '1'B);
1916 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
1917 f_sleep(1.0);
1918 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
1919 duplicate. If it was not a duplicate, osmo-ggsn would answer
1920 with a failure since that PDP ctx was already deleted. */
1921 g_c_seq_nr := g_c_seq_nr - 1;
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01001922 f_pdp_ctx_del(ctx, '1'B, expect_diameter := false);
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001923
1924 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
1925 var OCT1 cause_nonexistent := 'C0'O;
Pau Espin Pedrol10ec96e2022-02-09 17:03:15 +01001926 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent, expect_diameter := false);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001927 f_shutdown_helper();
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001928 }
1929
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001930 /* Activate PDP context + trigger Recovery procedure through EchoResp */
1931 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
1932 var Gtp1cUnitdata ud;
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001933 g_use_echo_intval := 5;
1934 timer T_echo;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001935 f_init();
1936 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1937 f_pdp_ctx_act(ctx);
1938
1939 /* Wait to receive echo request and send initial Restart counter */
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001940 T_echo.start(int2float(g_use_echo_intval) + 1.0);
1941 alt {
1942 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001943 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1944 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001945 }
1946 [] T_echo.timeout {
1947 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1948 "Timeout waiting for ping");
1949 }
1950 }
1951 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001952
1953 /* Wait to receive second echo request and send incremented Restart
1954 counter. This will fake a restarted SGSN, and pdp ctx allocated
1955 should be released by GGSN */
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06001956 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001957 T_echo.start(int2float(g_use_echo_intval) + 1.0);
1958 alt {
1959 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001960 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1961 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Pau Espin Pedrol05118022022-02-17 19:49:13 +01001962 }
1963 [] T_echo.timeout {
1964 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
1965 "Timeout waiting for ping");
1966 }
1967 }
1968 T_echo.stop;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001969 f_pdp_ctx_exp_del_req(ctx, omit, true);
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01001970 f_shutdown_helper();
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001971 }
1972
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01001973 /* Test creation, user plane and deletion of big amount (1000) of concurrent PDP context */
1974 testcase TC_lots_of_concurrent_pdp_ctx() runs on GT_CT {
1975 var Gtp1cUnitdata udc;
1976 var Gtp1uUnitdata udu;
1977 const integer num_ctx := 1000;
1978 var PdpContext ctx[num_ctx];
1979 timer T_next := 0.01;
1980 var integer next_req_ctx := 0;
1981 var integer rx_resp_ctx := 0;
1982 var integer rx_pong := 0;
1983 var OCT4 dns1_addr;
1984 var OCT4 saddr;
1985 var integer teic;
1986 var integer idx;
1987
1988 f_init();
1989
1990 for (var integer i := 0; i < num_ctx; i := i + 1) {
1991 ctx[i] := valueof(t_DefinePDP(f_rnd_imsi('26242'H), f_rnd_msisdn('1234'O), c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1992 ctx[i].teic := int2oct(i+1, 4); /* +1: skip TEIC=0 */
1993 ctx[i].teid := int2oct(i+1, 4); /* +1: skip TEID=0 */
1994 ctx[i].pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1995 }
1996
1997 T_default.start(60.0);
1998
1999 T_next.start;
2000 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002001 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
2002 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002003 [] pingpong();
2004 [] T_next.timeout {
2005 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx[next_req_ctx].imsi, g_restart_ctr,
2006 ctx[next_req_ctx].teid, ctx[next_req_ctx].teic, ctx[next_req_ctx].nsapi,
2007 ctx[next_req_ctx].eua, ctx[next_req_ctx].apn, g_sgsn_ip_c, g_sgsn_ip_u,
2008 ctx[next_req_ctx].msisdn, ctx[next_req_ctx].pco_req, ctx[next_req_ctx].ratType,
2009 ctx[next_req_ctx].uli));
2010 next_req_ctx := next_req_ctx + 1;
2011 if (next_req_ctx < num_ctx) {
2012 T_next.start;
2013 }
2014 repeat;
2015 }
2016 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2017 teic := oct2int(udc.gtpc.teid);
2018 if (not match(teic, (1 .. num_ctx))) {
2019 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2020 "Rx Unexpected TEIC");
2021 }
2022 idx := teic - 1;
2023 f_handle_create_req(ctx[idx], udc);
2024 rx_resp_ctx := rx_resp_ctx + 1;
2025
2026 dns1_addr := f_PCO_extract_proto(ctx[idx].pco_neg, '000d'O);
2027 saddr := ctx[idx].eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2028 f_send_gtpu(ctx[idx], f_gen_icmpv4_echo(saddr, dns1_addr));
2029 repeat;
2030 }
2031 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value udu {
2032 var octetstring gpdu := udu.gtpu.gtpu_IEs.g_PDU_IEs.data;
2033 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
2034 if (ip4.header.ver != 4) {
2035 repeat;
2036 }
2037 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
2038 if (not match(icmp4, (tr_ICMPv4_ERP, tr_ICMPv4_DU))) {
2039 repeat;
2040 }
2041 rx_pong := rx_pong + 1;
2042 if (rx_pong < num_ctx) {
2043 repeat;
2044 }
2045 setverdict(pass);
2046 }
2047 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2048 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2049 }
2050
2051 /* Let's close them now: */
2052 next_req_ctx := 0;
2053 rx_resp_ctx := 0;
2054 T_next.start;
2055 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002056 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
2057 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002058 [] pingpong();
2059 [] T_next.timeout {
2060 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));
2061 next_req_ctx := next_req_ctx + 1;
2062 if (next_req_ctx < num_ctx) {
2063 T_next.start;
2064 }
2065 repeat;
2066 }
2067 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2068 teic := oct2int(udc.gtpc.teid);
2069 if (not match(teic, (1 .. num_ctx))) {
2070 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2071 "Rx Unexpected TEIC");
2072 }
2073 rx_resp_ctx := rx_resp_ctx + 1;
2074 if (rx_resp_ctx < num_ctx) {
2075 repeat;
2076 }
2077 setverdict(pass);
2078 }
2079 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2080 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2081 }
2082 T_next.stop;
2083
2084 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002085 f_shutdown_helper();
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002086 }
2087
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002088 /* Test callocation of PDP contexts until reaching addr pool exhaustion */
2089 type record of OCT4 TEIClist;
2090 testcase TC_addr_pool_exhaustion() runs on GT_CT {
2091 var Gtp1cUnitdata udc;
2092 var Gtp1uUnitdata udu;
2093 var PdpContext ctx;
2094 timer T_next := 0.005;
2095 var integer next_req_ctx := 0;
2096 var integer rx_resp_ctx := 0;
2097 var integer num_ctx;
2098 var boolean cont_req := true;
2099 var CreatePDPContextResponse cpr;
2100 var TEIClist teic_list := {};
2101 var integer teic;
2102
2103 f_init();
2104
2105 T_default.start(120.0);
2106
2107 T_next.start;
2108 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002109 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(INITIAL_REQUEST) { repeat; }
2110 [Gy_PROC.checkstate("Connected")] as_DIA_Gy_CCR(INITIAL_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002111 [] pingpong();
2112 [] T_next.timeout {
2113 if (cont_req) {
2114 if (next_req_ctx - rx_resp_ctx < 100) { /* if we have too many in progress, wait a bit to continue */
2115 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), f_rnd_msisdn('1234'O), c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2116 ctx.nsapi := '0001'B;
2117 ctx.teic := int2oct(next_req_ctx+1, 4); /* +1: skip TEIC=0 */
2118 ctx.teid := int2oct(next_req_ctx+1, 4); /* +1: skip TEID=0 */
2119 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx.imsi, g_restart_ctr,
2120 ctx.teid, ctx.teic, ctx.nsapi,
2121 ctx.eua, ctx.apn, g_sgsn_ip_c, g_sgsn_ip_u,
2122 ctx.msisdn, ctx.pco_req, ctx.ratType,
2123 ctx.uli));
2124 next_req_ctx := next_req_ctx + 1;
2125 }
2126 T_next.start;
2127 }
2128 repeat;
2129 }
2130 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc {
2131 cpr := udc.gtpc.gtpc_pdu.createPDPContextResponse;
2132
2133 if (cpr.cause.causevalue == '80'O) {
2134 teic_list := teic_list & {cpr.teidControlPlane.teidControlPlane};
2135 } else {
2136 if (cont_req == true) {
2137 num_ctx := rx_resp_ctx;
2138 log("Successfully created ", num_ctx, " PDP contexts before exhausting the pool");
2139 setverdict(pass);
2140 }
2141 cont_req := false;
2142 }
2143 rx_resp_ctx := rx_resp_ctx + 1;
2144 if (not cont_req and next_req_ctx == rx_resp_ctx) {
2145 break;
2146 } else {
2147 repeat;
2148 }
2149 }
2150 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2151 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2152 }
2153
2154 /* Let's close them now: */
2155 next_req_ctx := 0;
2156 rx_resp_ctx := 0;
2157 T_next.start;
2158 alt {
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002159 [Gx_PROC.checkstate("Connected")] as_DIA_Gx_CCR(TERMINATION_REQUEST) { repeat; }
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002160 [] pingpong();
2161 [] T_next.timeout {
2162 f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, teic_list[next_req_ctx], '0001'B, '1'B));
2163 next_req_ctx := next_req_ctx + 1;
2164 if (next_req_ctx < num_ctx) {
2165 T_next.start;
2166 }
2167 repeat;
2168 }
2169 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc {
2170 teic := oct2int(udc.gtpc.teid);
2171 if (not match(teic, (1 .. num_ctx))) {
2172 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
2173 "Rx Unexpected TEIC");
2174 }
2175 rx_resp_ctx := rx_resp_ctx + 1;
2176 if (rx_resp_ctx < num_ctx) {
2177 repeat;
2178 }
2179 setverdict(pass);
2180 }
2181 [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); }
2182 [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); }
2183 }
2184 T_next.stop;
2185
2186 T_default.stop;
Pau Espin Pedrolc441ce02022-03-07 14:35:45 +01002187 f_shutdown_helper();
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002188 }
2189
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002190 /* Test charging over Gy interface. */
2191 testcase TC_gy_charging_cc_time() runs on GT_CT {
2192 var default d;
2193
2194 g_gy_validity_time := 3; /* Grant access for 3 seconds, needs to be re-validated afterwards */
2195 f_init();
2196 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
2197 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
2198 f_pdp_ctx_act(ctx);
2199
2200 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
2201
2202 /* Send some UL traffic: */
2203 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
2204 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2205 f_wait_icmp4_echo_reply(ctx);
2206
2207 T_default.start(10.0);
2208 d := activate(pingpong());
2209
2210 g_gy_validity_time := 2;
2211 /* First update reports octests/pkt on both UL/DL (see icmp ping-pong above) */
2212 as_DIA_Gy_CCR(UPDATE_REQUEST);
2213
2214 /* Second update: 0 ul/dl pkt/octet should be reported, since nothing was sent */
2215 as_DIA_Gy_CCR(UPDATE_REQUEST);
2216
2217 /* Third update: make sure report contains again octets/pkts for both UL/DL: */
2218 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2219 f_wait_icmp4_echo_reply(ctx);
2220 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2221 f_wait_icmp4_echo_reply(ctx);
2222 as_DIA_Gy_CCR(UPDATE_REQUEST);
2223
2224 /* Let the CCA reach the GGSN */
2225 f_sleep(0.5);
2226 deactivate(d);
2227 T_default.stop;
2228
2229 /* Send some data and validate it is reported in the TERMINATION_REQUEST
2230 * (triggered by PFCP Session Deletion Response): */
2231 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
2232 f_wait_icmp4_echo_reply(ctx);
2233
2234 f_pdp_ctx_del(ctx, '1'B);
2235
2236
2237 f_shutdown_helper();
2238 }
2239
Harald Welte94ade362017-08-04 00:36:55 +02002240 control {
Harald Welteed7a1772017-08-09 20:26:20 +02002241 execute(TC_pdp4_act_deact());
2242 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02002243 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02002244 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002245 execute(TC_pdp4_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002246 execute(TC_pdp4_act_deact_gtpu_access_wrong_saddr());
2247 execute(TC_pdp4_act_deact_gtpu_access_ipv6_apn4());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02002248 execute(TC_pdp4_clients_interact_with_txseq());
2249 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02002250 execute(TC_pdp4_act_deact_with_single_dns());
2251 execute(TC_pdp4_act_deact_with_separate_dns());
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01002252 execute(TC_pdp4_act_update_teic());
2253 execute(TC_pdp4_act_update_teid());
Harald Welteed7a1772017-08-09 20:26:20 +02002254
2255 execute(TC_pdp6_act_deact());
2256 execute(TC_pdp6_act_deact_pcodns());
2257 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01002258 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002259 execute(TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr());
2260 execute(TC_pdp6_act_deact_gtpu_access_wrong_global_saddr());
2261 execute(TC_pdp6_act_deact_gtpu_access_ipv4_apn6());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01002262 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02002263
Oliver Smithee6a0882019-03-08 11:05:46 +01002264 execute(TC_pdp46_act_deact());
2265 execute(TC_pdp46_act_deact_ipcp());
2266 execute(TC_pdp46_act_deact_icmp6());
2267 execute(TC_pdp46_act_deact_pcodns4());
2268 execute(TC_pdp46_act_deact_pcodns6());
2269 execute(TC_pdp46_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002270 execute(TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4());
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01002271 execute(TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01002272 execute(TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6());
Oliver Smithee6a0882019-03-08 11:05:46 +01002273 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02002274 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01002275
Harald Weltedca80052017-08-13 20:01:38 +02002276 execute(TC_echo_req_resp());
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01002277 execute(TC_echo_req_resp_gtpu());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02002278 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02002279 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02002280
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01002281 execute(TC_pdp_act_restart_ctr_echo());
Pau Espin Pedrol68c2af52022-02-25 11:56:17 +01002282
2283 execute(TC_lots_of_concurrent_pdp_ctx());
Pau Espin Pedrolbfea8352022-02-28 12:11:26 +01002284 /* Keep at the end, crashes older osmo-ggsn versions (OS#5469): */
2285 execute(TC_addr_pool_exhaustion());
Pau Espin Pedrol77fdd0b2022-03-08 14:03:33 +01002286
2287 /* open5gs specific tests: */
2288 if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
2289 execute(TC_gy_charging_cc_time());
2290 }
Harald Welte94ade362017-08-04 00:36:55 +02002291 }
Harald Welte379d45a2017-08-03 09:55:15 +02002292}