blob: 48e87bf91c6df90c5807345fa72c9e12941f81e4 [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;
Harald Welteddeecbb2017-08-18 22:53:30 +020042
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010043 type enumerated GGSN_Impl {
44 GGSN_IMPL_OSMOCOM,
45 GGSN_IMPL_OPEN5GS
46 };
47
Harald Welteddeecbb2017-08-18 22:53:30 +020048 modulepar {
Stefan Sperlingcb782b92018-04-03 16:03:15 +020049 /* Default IP addresses. May be overridden by GGSN_Tests configuration files. */
50
51 /* The SGSN simulated by TTCN3 will bind to these addresses for GTP control and GTP user planes. */
Harald Welteddeecbb2017-08-18 22:53:30 +020052 charstring m_bind_ip_gtpc := "127.23.42.1";
53 charstring m_bind_ip_gtpu := "127.23.42.1";
54
Stefan Sperlingcb782b92018-04-03 16:03:15 +020055 /* Addresses the GGSN which is being tested is listening on for SGSN connections. */
Harald Welteddeecbb2017-08-18 22:53:30 +020056 charstring m_ggsn_ip_gtpc := "127.0.0.6";
57 charstring m_ggsn_ip_gtpu := "127.0.0.6";
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010058
Stefan Sperlingcb782b92018-04-03 16:03:15 +020059 /*
60 * Our tests expect to see these DNS servers in 'Create PDP context responses' sent by the GGSN.
61 * These addresses must therefore match 'ip[v6] dns' options configured in osmo-ggsn.conf.
62 *
63 * These addresses are not expected to serve actual DNS requests. However, tests may expect to be
64 * able to ping these addresses (currently, IPv4 addresses must respond with an ICMP 'echo reply',
65 * and IPv6 addresses may respond with either ICMPv6 'echo reply' or 'destination unreachable').
66 */
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010067 charstring m_ggsn_ip4_dns1 := "192.168.100.1"
68 charstring m_ggsn_ip4_dns2 := "8.8.8.8"
Pau Espin Pedrol363ba482018-01-29 18:42:00 +010069 charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888"
70 charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844"
Stefan Sperlingcb782b92018-04-03 16:03:15 +020071
72 /*
73 * Additional address ranges are defined in osmo-ggsn.conf from which addresses are assigned
74 * to MS "behind" the simulated SGSN. These addresses appear on tun devices used by osmo-ggsn.
75 * The tests expect to be able to send ping packets between any two simulated MS within the same
76 * address range. This requires IP forwarding to be enabled on the corresponding tun interfaces.
77 */
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +010078
79 GGSN_Impl m_ggsn_impl := GGSN_IMPL_OSMOCOM;
Harald Welteddeecbb2017-08-18 22:53:30 +020080 }
Harald Welte94ade362017-08-04 00:36:55 +020081
Harald Welte811651e2017-08-05 15:25:06 +020082 type set PdpContext {
83 hexstring imsi,
84 octetstring msisdn optional,
85 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020086 ProtConfigOptions pco_req optional,
87 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020088 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020089 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020090 BIT4 nsapi,
91 /* TEI (Data) local side */
92 OCT4 teid,
93 /* TEI (Control) local side */
94 OCT4 teic,
95 /* TEI (Data) remote side */
96 OCT4 teid_remote,
97 /* TEI (Control) remote side */
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +010098 OCT4 teic_remote,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +010099 OCT1 ratType optional,
100 UserLocationInformation uli optional
Harald Welte811651e2017-08-05 15:25:06 +0200101 }
102
Harald Welte94ade362017-08-04 00:36:55 +0200103 type component GT_CT {
104 port GTPC_PT GTPC;
105 port GTPU_PT GTPU;
106
Harald Welte0be142b2017-08-13 13:28:10 +0200107 var boolean g_initialized := false;
108
Harald Welte94ade362017-08-04 00:36:55 +0200109 var OCT1 g_restart_ctr := '01'O;
110 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200111 var OCT4 g_sgsn_ip_c;
112 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +0200113 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200114 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
115 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200116 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200117
118 /* next to-be-sent GTP-C sequence number */
119 var uint16_t g_c_seq_nr;
120 /* next to-be-sent GTP-U sequence number */
121 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200122
123 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200124 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200125 var boolean g_use_echo := false;
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100126
127 /* emulated PCRF, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */
128 var DIAMETER_Emulation_CT vc_DIAMETER;
129 port DIAMETER_PT DIAMETER_UNIT;
130 port DIAMETEREM_PROC_PT DIAMETER_PROC;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200131 }
132
133 private function f_init_vty() runs on GT_CT {
134 map(self:GGSNVTY, system:GGSNVTY);
135 f_vty_set_prompts(GGSNVTY);
136 f_vty_transceive(GGSNVTY, "enable");
137 }
138
139 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
140 f_vty_enter_config(GGSNVTY);
141 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200142
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200143 f_vty_transceive(GGSNVTY, "apn internet");
144 if (enable) {
145 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
146 } else {
147 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
148 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200149 f_vty_transceive(GGSNVTY, "exit");
150
151 f_vty_transceive(GGSNVTY, "apn inet6");
152 if (enable) {
153 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
154 } else {
155 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
156 }
157 f_vty_transceive(GGSNVTY, "exit");
158
159 f_vty_transceive(GGSNVTY, "apn inet46");
160 if (enable) {
161 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
162 } else {
163 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
164 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200165 f_vty_transceive(GGSNVTY, "end");
166 }
167
168 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
169 if (expect_gptu_txseq) {
170 if (gtpu.s_bit != '1'B) {
171 log("GTPU sequence number expected but not present")
172 return false;
173 }
174 } else {
175 if (gtpu.s_bit != '0'B) {
176 log("GTPU sequence number not expected but present")
177 return false;
178 }
179 }
180 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200181 }
182
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200183 private function f_vty_enable_echo_interval(boolean enable) runs on GT_CT {
184 f_vty_enter_config(GGSNVTY);
185 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
186 if (enable) {
187 f_vty_transceive(GGSNVTY, "echo-interval 5");
188 } else {
189 f_vty_transceive(GGSNVTY, "no echo-interval");
190 }
191 f_vty_transceive(GGSNVTY, "end");
192 }
193
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100194 private function DiameterForwardUnitdataCallback(PDU_DIAMETER msg)
195 runs on DIAMETER_Emulation_CT return template PDU_DIAMETER {
196 DIAMETER_UNIT.send(msg);
197 return omit;
198 }
199
200 private function f_init_diameter(charstring id) runs on GT_CT {
201 var DIAMETEROps ops := {
202 create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback),
203 unitdata_cb := refers(DiameterForwardUnitdataCallback),
204 raw := true /* handler mode (single component for all IMSI)) */
205 };
206 var DIAMETER_conn_parameters pars := {
207 remote_ip := m_ggsn_ip_gtpc,
208 remote_sctp_port := -1,
209 local_ip := m_bind_ip_gtpc,
210 local_sctp_port := PCRF_PORT,
211 origin_host := "ttcn3ggsntest.localdomain",
212 origin_realm := "localdomain",
213 vendor_app_id := c_DIAMETER_3GPP_Gx_AID
214 };
215 vc_DIAMETER := DIAMETER_Emulation_CT.create(id);
216 map(vc_DIAMETER:DIAMETER, system:DIAMETER_CODEC_PT);
217 connect(vc_DIAMETER:DIAMETER_UNIT, self:DIAMETER_UNIT);
218 connect(vc_DIAMETER:DIAMETER_PROC, self:DIAMETER_PROC);
219 vc_DIAMETER.start(DIAMETER_Emulation.main(ops, pars, id));
220
221 f_diameter_wait_capability(DIAMETER_UNIT);
222 /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdong ping-pongs):
223 * RFC6733 sec 5.1
224 * RFC3539 sec 3.4.1 [5]
225 * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49
226 */
227 f_sleep(1.0);
228 }
229
Harald Welte94ade362017-08-04 00:36:55 +0200230 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200231 if (g_initialized == true) {
232 return;
233 }
234 g_initialized := true;
235
Harald Welteddeecbb2017-08-18 22:53:30 +0200236 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
237 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
238
Harald Welte94ade362017-08-04 00:36:55 +0200239 var Result res;
240 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +0200241 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200242 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200243 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200244
245 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +0200246 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200247 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200248
249 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200250 g_c_seq_nr := f_rnd_int(65535);
251 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200252
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100253 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
254 f_init_vty();
255 f_vty_set_gpdu_txseq(use_gtpu_txseq);
256 f_vty_enable_echo_interval(g_use_echo);
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100257 } else if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) {
258 f_init_diameter(testcasename());
Pau Espin Pedrolc1b1ddf2022-01-19 18:10:30 +0100259 }
Harald Welte94ade362017-08-04 00:36:55 +0200260 }
261
Harald Welte94ade362017-08-04 00:36:55 +0200262 /* Altstep implementing responses to any incoming echo requests */
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100263 private altstep pingpong() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200264 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200265 var Gtp1uUnitdata udu;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200266 [g_use_echo] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200267 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200268 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200269 repeat;
270 };
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200271 [not g_use_echo] GTPC.receive(tr_GTPC_PING(?)) {
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100272 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
273 "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200274 };
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100275 [] T_default.timeout {
276 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
277 "pinpong T_default timeout");
278 };
Harald Welte94ade362017-08-04 00:36:55 +0200279 }
280
Harald Welte811651e2017-08-05 15:25:06 +0200281 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200282 const octetstring c_ApnInternet := '08696E7465726E6574'O;
283 const octetstring c_ApnInet6 := '05696E657436'O;
284 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200285
Harald Welte811651e2017-08-05 15:25:06 +0200286 /* return random NSAPI */
287 function f_rnd_nsapi() return BIT4 {
288 return int2bit(f_rnd_int(16), 4);
289 }
290
291 /* return random TEI[DC] */
292 function f_rnd_tei() return OCT4 {
293 return int2oct(f_rnd_int(4294967296), 4);
294 }
295
296 /* define an (internal) representation of a PDP context */
297 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100298 EndUserAddress eua, OCT1 ratType := '02'O /* GERAN */) := {
Harald Welte811651e2017-08-05 15:25:06 +0200299 imsi := imsi,
300 msisdn := msisdn,
301 nsapi := f_rnd_nsapi(),
302 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200303 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200304 eua := eua,
305 teid := f_rnd_tei(),
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100306 teic := f_rnd_tei(),
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100307 ratType := ratType,
308 uli := {
309 type_gtpc := '98'O,
310 lengthf := 0 /* filled in by encoder */,
311 geographicLocationType := '00'O /* CGI */,
312 geographicLocation := {
313 geographicLocationCGI := ts_GeographicLocationCGI('262'H, '42F'H, '0001'O, '0002'O)
314 }
315 }
Harald Welte811651e2017-08-05 15:25:06 +0200316 }
317
318 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200319 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200320 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200321 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200322 }
323
324 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200325 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200326 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200327 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
328 g_d_seq_nr := g_d_seq_nr + 1;
329 } else {
330 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
331 }
Harald Welte811651e2017-08-05 15:25:06 +0200332 }
333
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200334 function f_handle_create_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
335 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
336 if (exp_cause == '80'O and exp_cause == cpr.cause.causevalue) {
337 /* Check if EUA type corresponds to requested type */
338 if (match(ctx.eua, t_EuaIPv4(?)) and
339 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
340 setverdict(fail);
341 }
342 if (match(ctx.eua, t_EuaIPv6(?)) and
343 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
344 setverdict(fail);
345 }
346 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
347 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
348 setverdict(fail);
349 }
350 /* Check if PCO response corresponds to request */
351 if (ispresent(ctx.pco_req)) {
352 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
353 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
354 log("IPv4 DNS Container requested, but missing");
355 setverdict(fail);
356 }
357 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
358 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
359 log("IPv6 DNS Container requested, but missing");
360 setverdict(fail);
361 }
362 }
363 ctx.teid_remote := cpr.teidDataI.teidDataI;
364 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
365 ctx.eua := cpr.endUserAddress;
366 ctx.pco_neg := cpr.protConfigOptions;
367 setverdict(pass);
368 } else if (exp_cause != '80'O and exp_cause == cpr.cause.causevalue) {
369 if (ispresent(cpr.endUserAddress)) {
370 log("EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
371 setverdict(fail);
372 }
373 setverdict(pass);
374 } else {
375 setverdict(fail);
376 }
377 }
378
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100379 function f_handle_update_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
380 var UpdatePDPContextResponseGGSN upr := ud.gtpc.gtpc_pdu.updatePDPContextResponse.updatePDPContextResponseGGSN;
381 if (exp_cause == '80'O and exp_cause == upr.cause.causevalue) {
382 ctx.teid_remote := upr.teidDataI.teidDataI;
383 ctx.teic_remote := upr.teidControlPlane.teidControlPlane;
384 if (ispresent(upr.protConfigOptions)) {
385 ctx.pco_neg := upr.protConfigOptions;
386 }
387 setverdict(pass);
388 } else if (exp_cause != '80'O and exp_cause == upr.cause.causevalue) {
389 setverdict(pass);
390 } else {
391 setverdict(fail);
392 }
393 }
394
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100395 private altstep as_DIA_CCR(DCC_NONE_CC_Request_Type req_type) runs on GT_CT {
396 var PDU_DIAMETER rx_dia;
397 [] DIAMETER_UNIT.receive(tr_DIA_CCR(req_type := req_type)) -> value rx_dia {
398 var template (omit) AVP avp;
399 var octetstring sess_id;
400 var AVP_Unsigned32 req_num;
401
402 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
403 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
404
405 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
406 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
407
408 DIAMETER_UNIT.send(ts_DIA_CCA(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id,
409 req_type, req_num));
410 }
411 [] DIAMETER_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
412 setverdict(fail, "Received unexpected DIAMETER ", rx_dia);
413 self.stop;
414 }
415 }
416
Harald Welte811651e2017-08-05 15:25:06 +0200417 /* send a PDP context activation */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +0200418 function f_pdp_ctx_act(inout PdpContext ctx, OCT1 exp_cause := '80'O) runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200419 var Gtp1cUnitdata ud;
Harald Welte94ade362017-08-04 00:36:55 +0200420 var default d;
421
422 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200423 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 +0200424 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100425 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req, ctx.ratType, ctx.uli));
Harald Welte94ade362017-08-04 00:36:55 +0200426 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200427 d := activate(pingpong());
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100428 if (DIAMETER_PROC.checkstate("Connected")) {
429 as_DIA_CCR(INITIAL_REQUEST);
430 }
Harald Welte94ade362017-08-04 00:36:55 +0200431 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200432 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200433 f_handle_create_req(ctx, ud, exp_cause);
Harald Welte94ade362017-08-04 00:36:55 +0200434 }
435 }
436 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200437 T_default.stop;
Harald Welte94ade362017-08-04 00:36:55 +0200438 }
439
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200440 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
441 var Gtp1cUnitdata ud;
442 var default d;
443
444 T_default.start;
445 d := activate(pingpong());
446 alt {
447 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
448 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
449 setverdict(pass);
450 } else if (not istemplatekind(expect_cause, "omit") and
451 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
452 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
453 setverdict(pass);
454 } else {
455 setverdict(fail);
456 }
457
458 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
459 setverdict(pass);
460 } else {
461 setverdict(fail);
462 }
463 }
464 }
465 deactivate(d);
466 T_default.stop;
467 }
468
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200469 function f_pdp_ctx_del(PdpContext ctx, template BIT1 teardown_ind, OCT1 expect_causevalue := '80'O) runs on GT_CT {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200470 var Gtp1cUnitdata ud;
471 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200472 var OCT4 expect_teid;
473
474 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
475 message with cause value "Non existent" shall be zero. */
476 if (expect_causevalue == 'C0'O) {
477 expect_teid := '00000000'O;
478 } else {
479 expect_teid := ctx.teic;
480 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200481
Harald Welte41575e92017-08-13 13:49:57 +0200482 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 +0200483 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200484 d := activate(pingpong());
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100485 if (DIAMETER_PROC.checkstate("Connected")) {
486 as_DIA_CCR(TERMINATION_REQUEST);
487 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200488 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200489 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
490 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200491 setverdict(pass);
492 } else {
493 setverdict(fail);
494 }
495 }
496 }
497 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200498 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200499 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100500
501 /* send a Update PdP Context Request, expect Response */
502 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 {
503 var Gtp1cUnitdata ud;
504 var default d;
505
506 if (not istemplatekind(new_teid, "omit")) {
507 ctx.teid := valueof(new_teid);
508 }
509 if (not istemplatekind(new_teic, "omit")) {
510 ctx.teic := valueof(new_teic);
511 }
512
513 log("sending UpdatePDP");
514 f_send_gtpc(ts_GTPC_UpdatePDP(g_peer_c, ctx.teic_remote, g_c_seq_nr, ctx.imsi, g_restart_ctr,
515 ctx.teid, ctx.teic, ctx.nsapi, g_sgsn_ip_c, g_sgsn_ip_u,
516 ctx.pco_req, ctx.ratType, ctx.uli));
517 T_default.start;
518 d := activate(pingpong());
519 alt {
520 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, updatePDPContextResponse, ctx.teic)) -> value ud {
521 f_handle_update_req(ctx, ud, exp_cause);
522 }
523 }
524 deactivate(d);
525 T_default.stop;
526 }
527
Harald Welte811651e2017-08-05 15:25:06 +0200528 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
529 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
530 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
531 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200532
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200533 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100534 template PDU_ICMP ts_ICMPv4_ERQ := {
535 echo := {
536 type_field := 8,
537 code := 0,
538 checksum := '0000'O,
539 identifier := '0345'O,
540 sequence_number := '0001'O,
541 data := ''O
542 }
543 }
544
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200545 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100546 template PDU_ICMP tr_ICMPv4_ERQ := {
547 echo := {
548 type_field := 8,
549 code := 0,
550 checksum := ?,
551 identifier := ?,
552 sequence_number := ?,
553 data := ?
554 }
555 }
556
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200557 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100558 template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
559 echo_reply := {
560 type_field := 0,
561 code := 0,
562 checksum := ?,
563 identifier := ?,
564 sequence_number := ?,
565 data := data
566 }
567 }
568
569 /* template for receiving/matching an ICMPv6 Destination Unreachable */
570 template PDU_ICMP tr_ICMPv4_DU := {
571 destination_unreachable := {
572 type_field := 1,
573 code := ?,
574 checksum := ?,
575 unused := ?,
576 original_ip_msg := ?
577 }
578 }
579
580 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
581 template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
582 header := {
583 ver := 4,
584 hlen := 5,
585 tos := 0,
586 tlen := tlen,
587 id := 35902,
588 res := '0'B,
589 dfrag := '1'B,
590 mfrag := '0'B,
591 foffset := 0,
592 ttl := 64,
593 proto := proto,
594 cksum := 0,
595 srcaddr := srcaddr,
596 dstaddr := dstaddr
597 },
598 ext_headers := omit,
599 payload := payload
600 }
601
Harald Welte231b9412017-08-09 17:16:31 +0200602 /* template to generate a 'Prefix Information' ICMPv6 option */
603 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
604 prefixInformation := {
605 typeField := 3,
606 lengthIndicator := 8,
607 prefixLength := prefix_len,
608 reserved1 := '000000'B,
609 a_Bit := '0'B,
610 l_Bit := '0'B,
611 validLifetime := oct2int('FFFFFFFF'O),
612 preferredLifetime := oct2int('FFFFFFFF'O),
613 reserved2 := '00000000'O,
614 prefix := prefix
615 }
616 }
617
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200618 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100619 template PDU_ICMPv6 ts_ICMPv6_ERQ := {
620 echoRequest := {
621 typeField := 128,
622 code := 0,
623 checksum := '0000'O,
624 identifier := 0,
625 sequenceNr := 0,
626 data := ''O
627 }
628 }
629
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200630 /* template for sending an ICMPv6 router solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200631 template PDU_ICMPv6 ts_ICMPv6_RS := {
632 routerSolicitation := {
633 typeField := 133,
634 code := 0,
635 checksum := '0000'O,
636 reserved := '00000000'O,
637 /* TODO: do we need 'Source link-layer address' ? */
638 options := omit
639 }
640 }
641
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200642 /* template for sending an ICMPv6 router advertisement */
Harald Welte231b9412017-08-09 17:16:31 +0200643 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
644 routerAdvertisement := {
645 typeField := 134,
646 code := 0,
647 checksum := '0000'O,
648 curHopLimit := ?,
649 reserved := '000000'B,
650 o_Bit := '0'B,
651 m_Bit := '0'B,
652 routerLifetime := oct2int('FFFF'O),
653 reachableTime := oct2int('FFFFFFFF'O),
654 retransTimer := oct2int('FFFFFFFF'O),
655 options := {
656 ts_ICMP6_OptPrefix(prefix, prefix_len)
657 }
658 }
659 }
660
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200661 /* template for sending an ICMPv6 neighbor solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200662 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
663 neighborSolicitation := {
664 typeField := 135,
665 code := 0,
666 checksum := '0000'O,
667 reserved := '00000000'O,
668 targetAddress := target_addr,
669 /* TODO: do we need 'Source link-layer address' ? */
670 options := omit
671 }
672 }
673
674 /* derive ICMPv6 link-local address from lower 64bit of link_id */
675 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
676 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
677 prefixInformation := {
678 typeField := 3,
679 lengthIndicator := 4,
680 prefixLength := prefix_len,
681 reserved1 := ?,
682 a_Bit := ?,
683 l_Bit := ?,
684 validLifetime := ?,
685 preferredLifetime := ?,
686 reserved2 := ?,
687 prefix := prefix
688 }
689 }
690
691 /* template for receiving/matching an ICMPv6 router advertisement */
692 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
693 routerAdvertisement := {
694 typeField := 134,
695 code := 0,
696 checksum := ?,
697 curHopLimit := ?,
698 reserved := ?,
699 o_Bit := '0'B,
700 m_Bit := '0'B,
701 routerLifetime := ?,
702 reachableTime := ?,
703 retransTimer := ?,
704 options := {
705 tr_ICMP6_OptPrefix(prefix, prefix_len)
706 }
707 }
708 }
709
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100710 /* template for receiving/matching an ICMPv6 Destination Unreachable */
711 template PDU_ICMPv6 tr_ICMPv6_DU := {
712 destinationUnreachable := {
713 typeField := 1,
714 code := ?,
715 checksum := ?,
716 unused := ?,
717 originalIpMsg := ?
718 }
719 }
720
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200721 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100722 template PDU_ICMPv6 tr_ICMPv6_ERQ := {
723 echoRequest := {
724 typeField := 128,
725 code := 0,
726 checksum := ?,
727 identifier := ?,
728 sequenceNr := ?,
729 data := ?
730 }
731 }
732
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100733 /* template for receiving/matching an ICMPv6 echo reply */
734 template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
735 echoReply := {
736 typeField := 129,
737 code := 0,
738 checksum := ?,
739 identifier := ?,
740 sequenceNr := ?,
741 data := data
742 }
743 }
744
Harald Welte231b9412017-08-09 17:16:31 +0200745 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
746 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
747 header := {
748 ver := 6,
749 trclass := 0,
750 flabel := 0,
751 plen := 0,
752 nexthead := nexthead,
753 hlim := hlim,
754 srcaddr := srcaddr,
755 dstaddr := dstaddr
756 },
757 ext_headers := omit,
758 payload := payload
759 }
760
761 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
762 return 'FE80000000000000'O & substr(link_id, 8, 8);
763 }
764
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100765 function f_ipv6_global(in OCT16 link_id) return OCT16 {
766 return substr(link_id, 0, 8) & '1234123412341234'O;
767 }
768
769 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
770 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
771 var integer i;
772 var octetstring res := substr(addr, 0, prefix);
773 for (i := prefix; i < lengthof(addr); i := i + 1) {
774 var octetstring a := addr[i] xor4b '11'O;
775 res := res & a;
776 }
777 return res;
778 }
779
Harald Welte231b9412017-08-09 17:16:31 +0200780 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
781 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
782 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
783 }
784
785 /* generate and encode ICMPv6 router solicitation */
786 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
787 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
788 var OCT16 saddr := f_ipv6_link_local(link_id);
789
790 var octetstring tmp;
791 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
792 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
793
794 return f_IPv6_enc(ip6);
795 }
796
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100797 /* Get link-id from PDP Context EUA */
798 function f_ctx_get_ipv6_interface_id(in PdpContext ctx) return OCT16 {
799 var OCT16 interface_id;
800 if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
801 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
802 } else if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv6)) {
803 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
804 } else {
805 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected request to submit icmpv6 rs in IPv4 PDP context");
806 }
807 return interface_id;
808 }
809
Harald Welte231b9412017-08-09 17:16:31 +0200810 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
811 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100812 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200813 return f_gen_icmpv6_router_solicitation(interface_id);
814 }
815
816 /* generate and encode ICMPv6 neighbor solicitation */
817 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
818 var octetstring tmp;
819 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
820 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
821 return f_IPv6_enc(ip6);
822 }
823
824 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
825 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100826 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200827 var OCT16 link_local := f_ipv6_link_local(interface_id);
828 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
829
830 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
831 }
832
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100833 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
834 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring {
835 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ));
836 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
837 var octetstring data := f_IPv4_enc(ip4);
838 var OCT2 cksum := f_IPv4_checksum(data);
839 data[10] := cksum[0];
840 data[11] := cksum[1];
841 return data;
842 }
843
844 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
845 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
846 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
847 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
848 var octetstring data := f_IPv6_enc(ip6);
849 return data;
850 }
851
852 /* Wait for ICMPv4 from GTP */
853 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +0200854 var Gtp1uUnitdata ud;
855 T_default.start;
856 alt {
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100857 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ctx.teid)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200858 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200859 setverdict(fail);
860 stop;
861 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100862 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
863 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
864 if (ip4.header.ver != 4) {
865 repeat;
866 }
867 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
868 if (not match(icmp4, expected)) {
869 repeat;
870 }
871 }
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +0100872 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
873 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
874 "Received wrong local TEID");
875 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100876 [] GTPU.receive { setverdict(fail); }
877 [] T_default.timeout { setverdict(fail); }
878 }
879 T_default.stop;
880 }
881
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100882 /* Wait for ICMPv4 echo request from GTP */
883 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
884 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
885 }
886
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100887 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
888 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
889 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
890 }
891
892 /* Wait for ICMPv6 from GTP */
893 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
894 var Gtp1uUnitdata ud;
895 T_default.start;
896 alt {
Harald Welte231b9412017-08-09 17:16:31 +0200897 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200898 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200899 setverdict(fail);
900 stop;
901 }
Harald Welte231b9412017-08-09 17:16:31 +0200902 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
903 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100904 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +0200905 repeat;
906 }
907 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100908 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +0200909 repeat;
910 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100911 /* We are waiting for RA, update ctx */
912 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
913 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
914 log("RA with /64 prefix ", ctx.ip6_prefix);
915 }
Harald Welte231b9412017-08-09 17:16:31 +0200916 }
917 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
918 [] GTPU.receive { setverdict(fail); }
919 [] T_default.timeout { setverdict(fail); }
920 }
921 T_default.stop;
922 }
923
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100924 /* wait for GGSN to send us an ICMPv6 router advertisement */
925 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
926 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
927 }
928
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100929 /* Wait for ICMPv6 echo request from GTP */
930 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
931 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
932 }
933
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100934 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
935 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
936 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
937 }
938
Oliver Smithee6a0882019-03-08 11:05:46 +0100939 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
940 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
941 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
942 return f_gen_icmpv6_router_solicitation(interface_id);
943 }
944
945 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
946 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
947 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
948 var OCT16 link_local := f_ipv6_link_local(interface_id);
949 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
950
951 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
952 }
953
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100954 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
955 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
956 T_default.start;
957 alt {
958 [] GTPU.receive { setverdict(fail); }
959 [] T_default.timeout { }
960 }
961 T_default.stop;
962 }
963
Harald Welte79737b42019-04-10 10:39:30 +0200964 /* list of protocols where we don't accept duplicates */
965 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
966 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
967 var integer i;
968 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
969 if (id == protocol_ids_nodupes[i]) {
970 return false;
971 }
972 }
973 return true;
974 }
975
976 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
977 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
978 var OCT2List protocol_ids := {};
979 var integer i, j;
980 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
981 var OCT2 id := pco.protocols[i].protocolID;
982 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
983 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
984 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
985 }
986 }
987 protocol_ids := protocol_ids & { id };
988 }
989 }
990
Harald Welte0ef285b2017-08-13 20:06:01 +0200991 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +0200992 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200993 f_init();
Harald Welte231b9412017-08-09 17:16:31 +0200994
Harald Welteed097432017-08-13 13:28:49 +0200995 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 +0200996 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +0200997 f_pdp_ctx_del(ctx, '1'B);
998 }
999
Harald Welte0ef285b2017-08-13 20:06:01 +02001000 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001001 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
1002 f_init();
1003
Harald Welteed097432017-08-13 13:28:49 +02001004 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 +02001005 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1006 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001007
Harald Welte79737b42019-04-10 10:39:30 +02001008 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001009 /* verify PCO contains both primary and secondary DNS */
1010 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1011 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1012 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1013 }
1014
1015 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1016 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1017 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1018 }
1019
Harald Welteed7a1772017-08-09 20:26:20 +02001020 f_pdp_ctx_del(ctx, '1'B);
1021 }
1022
Harald Welte0ef285b2017-08-13 20:06:01 +02001023 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +02001024 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
1025 f_init();
1026
Harald Welteed097432017-08-13 13:28:49 +02001027 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 +02001028 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1029 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001030
Harald Welte79737b42019-04-10 10:39:30 +02001031 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +02001032 //f_send_gtpu(ctx, c_router_solicit);
1033 //f_send_gtpu(ctx, c_neigh_solicit);
1034
1035 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1036 f_wait_rtr_adv(ctx);
1037 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1038
Harald Welte811651e2017-08-05 15:25:06 +02001039 f_pdp_ctx_del(ctx, '1'B);
Harald Welte94ade362017-08-04 00:36:55 +02001040 }
1041
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001042 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
1043 Test we can send ICMPv6 ping over GTPU to DNS server. */
1044 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
1045 f_init();
1046 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1047 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1048 f_pdp_ctx_act(ctx);
1049
1050 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1051 f_wait_rtr_adv(ctx);
1052 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1053
1054 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1055
1056 /* Check if we can use valid link-local src addr. */
1057 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1058 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
Pau Espin Pedrolb63d85f2022-02-07 16:11:47 +01001059 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
1060 f_wait_icmp6_echo_reply(ctx);
1061 } else {
1062 f_wait_gtpu_fail(ctx);
1063 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001064
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001065 /* Check if we can use valid global src addr, should work */
1066 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1067 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
1068 f_wait_icmp6_echo_reply(ctx);
1069
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001070 f_pdp_ctx_del(ctx, '1'B);
1071 }
1072
1073 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1074 testcase TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr() runs on GT_CT {
1075 f_init();
1076 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1077 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1078 f_pdp_ctx_act(ctx);
1079
1080 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1081 f_wait_rtr_adv(ctx);
1082 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1083
1084 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1085 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1086 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1087 f_wait_gtpu_fail(ctx);
1088
1089 f_pdp_ctx_del(ctx, '1'B);
1090 }
1091
1092 /* Assert that packets with wrong global src addr are dropped by GGSN */
1093 testcase TC_pdp6_act_deact_gtpu_access_wrong_global_saddr() runs on GT_CT {
1094 f_init();
1095 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1096 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1097 f_pdp_ctx_act(ctx);
1098
1099 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1100 f_wait_rtr_adv(ctx);
1101 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1102
1103 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1104 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001105 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1106 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
1107 f_wait_gtpu_fail(ctx);
1108
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001109 f_pdp_ctx_del(ctx, '1'B);
1110 }
1111
1112 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped */
1113 testcase TC_pdp6_act_deact_gtpu_access_ipv4_apn6() runs on GT_CT {
1114 f_init();
1115 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1116 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1117 f_pdp_ctx_act(ctx);
1118
1119 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1120 f_wait_rtr_adv(ctx);
1121 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1122
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001123 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
1124 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
1125 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
1126 f_wait_gtpu_fail(ctx);
1127
1128 f_pdp_ctx_del(ctx, '1'B);
1129 }
1130
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001131 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1132 testcase TC_pdp6_clients_interact() runs on GT_CT {
1133 f_init();
1134 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1135 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1136 f_pdp_ctx_act(ctxA);
1137 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
1138 f_wait_rtr_adv(ctxA);
1139 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
1140
1141 f_pdp_ctx_act(ctxB);
1142 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
1143 f_wait_rtr_adv(ctxB);
1144 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
1145
1146 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1147 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1148 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1149 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1150
1151 /* Validate if clients can interact using ll addr. */
1152 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1153 f_wait_gtpu_fail(ctxB);
1154
1155 /* Validate if clients can interact using global addr. */
1156 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1157 f_wait_gtpu_fail(ctxB);
1158
1159 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001160 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001161 }
1162
Harald Welte0ef285b2017-08-13 20:06:01 +02001163 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +02001164 testcase TC_pdp4_act_deact() runs on GT_CT {
1165 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001166 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 +02001167 f_pdp_ctx_act(ctx);
1168 f_pdp_ctx_del(ctx, '1'B);
1169 }
1170
Harald Welte0ef285b2017-08-13 20:06:01 +02001171 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +02001172 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
1173 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001174 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1175 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +02001176 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 +02001177 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +02001178 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001179 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +01001180 /* verify IPCP is at all contained */
1181 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1182 setverdict(fail, "IPCP not found in PCO");
1183 }
1184 /* verify IPCP contains both primary and secondary DNS */
1185 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001186 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1187 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1188 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1189 } else {
1190 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1191 }
Harald Welte71a36022017-12-04 18:55:58 +01001192 }
Harald Welteed7a1772017-08-09 20:26:20 +02001193 f_pdp_ctx_del(ctx, '1'B);
1194 }
1195
Harald Weltef8298542019-04-10 10:15:28 +02001196 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
1197 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
1198 f_init();
1199 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1200 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1201 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1202 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1203 f_pdp_ctx_act(ctx);
1204 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1205 /* verify IPCP is at all contained */
1206 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1207 setverdict(fail, "IPCP not found in PCO");
1208 }
1209 /* verify IPCP contains both primary and secondary DNS */
1210 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1211 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1212 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1213 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1214 } else {
1215 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1216 }
1217 }
1218 /* verify that PAP is contained */
1219 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1220 setverdict(fail, "PAP not found in PCO");
1221 }
1222 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1223 if (not match(pap, tr_PAP_AuthAck)) {
1224 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1225 }
1226 f_pdp_ctx_del(ctx, '1'B);
1227 }
1228
Harald Welte0ef285b2017-08-13 20:06:01 +02001229 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001230 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1231 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001232 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 +02001233 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001234 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001235
Harald Welte79737b42019-04-10 10:39:30 +02001236 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001237 /* verify PCO contains both primary and secondary DNS */
1238 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1239 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1240 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1241 }
1242
1243 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1244 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1245 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1246 }
1247
Harald Welteed7a1772017-08-09 20:26:20 +02001248 f_pdp_ctx_del(ctx, '1'B);
1249 }
1250
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001251 /* Test PDP context activation for dynamic IPv4 EUA.
1252 Test we can send ICMPv6 ping over GTPU to DNS server. */
1253 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1254 f_init();
1255 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1256 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1257 f_pdp_ctx_act(ctx);
1258
Harald Welte79737b42019-04-10 10:39:30 +02001259 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001260 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1261
1262 /* Check if we can use valid global src addr, should work */
1263 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1264 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1265 f_wait_icmp4_echo_reply(ctx);
1266
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001267 f_pdp_ctx_del(ctx, '1'B);
1268 }
1269
1270 /* Assert that packets with wrong global src addr are dropped by GGSN */
1271 testcase TC_pdp4_act_deact_gtpu_access_wrong_saddr() runs on GT_CT {
1272 f_init();
1273 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1274 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1275 f_pdp_ctx_act(ctx);
1276
1277 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1278 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1279 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001280 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1281 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1282 f_wait_gtpu_fail(ctx);
1283
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001284 f_pdp_ctx_del(ctx, '1'B);
1285 }
1286
1287 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1288 testcase TC_pdp4_act_deact_gtpu_access_ipv6_apn4() runs on GT_CT {
1289 f_init();
1290 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1291 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1292 f_pdp_ctx_act(ctx);
1293
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001294 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1295 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1296 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1297 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001298
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001299 f_pdp_ctx_del(ctx, '1'B);
1300 }
1301
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001302 /* Helper function for tests below. */
1303 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001304 f_init();
1305 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1306 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1307 f_pdp_ctx_act(ctxA);
1308 f_pdp_ctx_act(ctxB);
1309 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1310 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1311 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1312 f_wait_icmp4_echo_request(ctxB);
1313
1314 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001315 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001316 }
1317
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001318 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1319 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001320 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001321 f_pdp4_clients_interact();
1322 }
1323
1324 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1325 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001326 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001327 f_pdp4_clients_interact();
1328 }
1329
Harald Weltedca80052017-08-13 20:01:38 +02001330 testcase TC_echo_req_resp() runs on GT_CT {
1331 f_init();
1332 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1333 T_default.start;
1334 alt {
1335 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1336 [] GTPC.receive { repeat; };
1337 [] T_default.timeout { setverdict(fail); }
1338 }
1339 T_default.stop;
1340 }
1341
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001342 testcase TC_echo_req_resp_gtpu() runs on GT_CT {
1343 f_init();
1344 GTPU.send(ts_GTPU_PING(g_peer_u, g_d_seq_nr));
1345 T_default.start;
1346 alt {
1347 [] GTPU.receive(tr_GTPU_PONG(g_peer_u)) { setverdict(pass); };
1348 [] GTPU.receive { repeat; };
1349 [] T_default.timeout { setverdict(fail); }
1350 }
1351 T_default.stop;
1352 }
1353
Philipp Maier33e52612018-05-30 17:22:02 +02001354 /* Test if the parser can cope with PCO that only contain either a
1355 * single primary DNS or a secondary DNS. */
1356 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1357
1358 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1359 * the test is executed.
1360 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1361
1362 f_init();
1363 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1364 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1365 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1366 var octetstring pco_neg_dns;
1367 var octetstring pco_neg_dns_expected;
1368
1369 /* PCO with primary DNS only */
1370 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1371 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001372 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001373 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1374 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1375 /* Note: The prepended hex bytes encode the following information:
1376 * 0x02 = Configuration ACK
1377 * 0x00 = Identifier
1378 * 0x000a = Length
1379 * 0x81 = Type (Primary DNS Server Address)
1380 * 0x06 = Length
1381 * (4 byte IP-Address appended) */
1382 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1383 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1384 }
1385 f_pdp_ctx_del(ctx, '1'B);
1386
1387 /* PCO with secondary DNS only */
Harald Welte7ef6d102021-04-01 21:24:35 +02001388 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001389 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1390 f_pdp_ctx_act(ctx);
1391 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1392 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1393 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1394 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1395 }
1396 f_pdp_ctx_del(ctx, '1'B);
1397 }
1398
1399 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1400 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1401 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1402 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1403
1404 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1405 * the test is executed.
1406 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1407
1408 f_init();
1409 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1410 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1411 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1412 var octetstring pco_neg_dns;
1413 var octetstring pco_neg_dns_expected;
1414
1415 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1416 f_pdp_ctx_act(ctx);
1417
1418 /* Check if primary DNS is contained */
1419 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1420 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1421 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1422 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1423 }
Philipp Maier33e52612018-05-30 17:22:02 +02001424
1425 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001426 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1427 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001428 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1429 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1430 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1431 }
1432 f_pdp_ctx_del(ctx, '1'B);
1433 }
1434
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001435 /* Validate that SUT updates remote TEIC when requested through UpdatePDPContextRequest */
1436 testcase TC_pdp4_act_update_teic() runs on GT_CT {
1437 f_init();
1438 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1439 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1440 f_pdp_ctx_act(ctx);
1441
1442 /* UpdatePDPContestRequest changing the local TEIC */
1443 var OCT4 new_teic := ctx.teic;
1444 new_teic[3] := new_teic[3] xor4b '11'O;
1445 f_pdp_ctx_update(ctx, new_teic := new_teic);
1446
1447 f_pdp_ctx_del(ctx, '1'B);
1448 }
1449
1450 /* Validate that SUT updates remote TEID when requested through UpdatePDPContextRequest */
1451 testcase TC_pdp4_act_update_teid() runs on GT_CT {
1452 f_init();
1453 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1454 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1455 f_pdp_ctx_act(ctx);
1456
1457 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1458 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1459 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1460
1461 /* Data is sent (back) to the local TEID established during CreatePDPContext */
1462 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1463 f_wait_icmp4_echo_reply(ctx);
1464
1465 /* UpdatePDPContestRequest changing the local TEID */
1466 var OCT4 new_teid := ctx.teid;
1467 new_teid[3] := new_teid[3] xor4b '11'O;
1468 f_pdp_ctx_update(ctx, new_teid := new_teid);
1469
1470 /* Check if we can send data after updating the PDP context. Answer should be sent to the new TEID */
1471 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1472 f_wait_icmp4_echo_reply(ctx);
1473
1474 f_pdp_ctx_del(ctx, '1'B);
1475 }
1476
Oliver Smithee6a0882019-03-08 11:05:46 +01001477 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1478 testcase TC_pdp46_act_deact() runs on GT_CT {
1479 f_init();
1480 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1481 f_pdp_ctx_act(ctx);
1482 f_pdp_ctx_del(ctx, '1'B);
1483 }
1484
1485 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1486 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1487 f_init();
1488 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1489 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1490 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1491 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1492 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001493 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001494 /* verify IPCP is at all contained */
1495 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1496 setverdict(fail, "IPCP not found in PCO");
1497 }
Harald Welte79737b42019-04-10 10:39:30 +02001498 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001499 /* verify IPCP contains both primary and secondary IPv4 DNS */
1500 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1501 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1502 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1503 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1504 } else {
1505 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1506 }
1507 }
1508 f_pdp_ctx_del(ctx, '1'B);
1509 }
1510
1511 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1512 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1513 f_init();
1514 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1515 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1516 f_pdp_ctx_act(ctx);
1517
1518 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1519 f_wait_rtr_adv(ctx);
1520 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1521
1522 f_pdp_ctx_del(ctx, '1'B);
1523 }
1524
1525 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1526 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1527 f_init();
1528
1529 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1530 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1531 f_pdp_ctx_act(ctx);
1532
Harald Welte79737b42019-04-10 10:39:30 +02001533 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001534 /* verify PCO contains both primary and secondary IPv4 DNS */
1535 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1536 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1537 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1538 }
1539
1540 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1541 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1542 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1543 }
1544
1545 f_pdp_ctx_del(ctx, '1'B);
1546 }
1547
1548 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1549 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1550 f_init();
1551
1552 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1553 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1554 f_pdp_ctx_act(ctx);
1555
Harald Welte79737b42019-04-10 10:39:30 +02001556 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001557 /* verify PCO contains both primary and secondary IPv6 DNS */
1558 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1559 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1560 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1561 }
1562
1563 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1564 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1565 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1566 }
1567
1568 f_pdp_ctx_del(ctx, '1'B);
1569 }
1570
1571 /* Test PDP context activation for dynamic IPv4v6 EUA.
1572 Test we can send ICMPv6 ping over GTPU to DNS server. */
1573 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1574 f_init();
1575 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1576 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1577 f_pdp_ctx_act(ctx);
1578
1579 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1580
1581 /* Check if we can use valid global src addr, should work */
1582 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1583 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1584 f_wait_icmp4_echo_reply(ctx);
1585
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001586 f_pdp_ctx_del(ctx, '1'B);
1587 }
1588
1589 /* Assert that packets with wrong ipv4 src addr are dropped by GGSN on APN IPv4v6 */
1590 testcase TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4() runs on GT_CT {
1591 f_init();
1592 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1593 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1594 f_pdp_ctx_act(ctx);
1595
1596 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1597 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
Oliver Smithee6a0882019-03-08 11:05:46 +01001598 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1599 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1600 f_wait_gtpu_fail(ctx);
1601
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001602 f_pdp_ctx_del(ctx, '1'B);
1603 }
1604
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001605 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1606 testcase TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6() runs on GT_CT {
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001607 f_init();
1608 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1609 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1610 f_pdp_ctx_act(ctx);
1611
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001612 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1613 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1614 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1615 f_wait_gtpu_fail(ctx);
1616
1617 f_pdp_ctx_del(ctx, '1'B);
1618 }
1619
1620 /* Assert that packets with wrong ipv6 global src addr are dropped by GGSN on APN IPv4v6 */
1621 testcase TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6() runs on GT_CT {
1622 f_init();
1623 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1624 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1625 f_pdp_ctx_act(ctx);
1626
1627 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1628 f_wait_rtr_adv(ctx);
1629 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1630
1631 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1632 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1633 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1634 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
Oliver Smithee6a0882019-03-08 11:05:46 +01001635 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001636
Oliver Smithee6a0882019-03-08 11:05:46 +01001637 f_pdp_ctx_del(ctx, '1'B);
1638 }
1639
1640 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1641 testcase TC_pdp46_clients_interact() runs on GT_CT {
1642 f_init();
1643 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1644 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1645 f_pdp_ctx_act(ctxA);
1646 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1647 f_wait_rtr_adv(ctxA);
1648 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1649
1650 f_pdp_ctx_act(ctxB);
1651 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1652 f_wait_rtr_adv(ctxB);
1653 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1654
1655 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1656 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1657 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1658 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1659
1660 /* Validate if clients can interact using ll addr. */
1661 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1662 f_wait_gtpu_fail(ctxB);
1663
1664 /* Validate if clients can interact using global addr. */
1665 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1666 f_wait_gtpu_fail(ctxB);
1667
1668 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001669 f_pdp_ctx_del(ctxB, '1'B);
Oliver Smithee6a0882019-03-08 11:05:46 +01001670 }
1671
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001672 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
1673 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
1674 f_init();
1675 /* A typical MS first attempts v4v6, and if rejected, then tries v4 and v6 separetly */
1676 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
1677 f_pdp_ctx_act(ctx46, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1678
1679 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1680 f_pdp_ctx_act(ctx4, '80'O); /* Normal accept cause */
1681
1682 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv6Dyn)));
1683 f_pdp_ctx_act(ctx6, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1684
1685 f_pdp_ctx_del(ctx4, '1'B);
1686 }
1687
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001688 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
1689 testcase TC_pdp_act2_recovery() runs on GT_CT {
1690 var Gtp1cUnitdata ud;
1691 var default d;
1692 var boolean ctxA_deleted := false;
1693 var boolean ctxB_created := false;
1694
1695 f_init();
1696 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1697 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1698 f_pdp_ctx_act(ctxA);
1699
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06001700 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001701
1702 log("sending 2nd CreatePDP (recovery increased)");
1703 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
1704 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
1705 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
1706 T_default.start;
1707 d := activate(pingpong());
1708 alt {
1709 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
1710 f_handle_create_req(ctxB, ud);
1711 if (not ctxB_created) {
1712 ctxB_created := true;
1713 setverdict(pass);
1714 } else {
1715 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
1716 }
1717
1718 if (not ctxA_deleted) {
1719 repeat;
1720 }
1721 }
1722 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
1723 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
1724 setverdict(pass);
1725 } else {
1726 setverdict(fail);
1727 }
1728
1729 if (not ctxA_deleted) {
1730 ctxA_deleted := true;
1731 setverdict(pass);
1732 } else {
1733 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
1734 }
1735
1736 if (not ctxB_created) {
1737 repeat;
1738 }
1739 }
1740 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
1741 setverdict(fail, "GGSN dropping still valid pdp ctx");
1742 }
1743 }
1744 deactivate(d);
1745 T_default.stop;
1746
1747 f_pdp_ctx_del(ctxB, '1'B);
1748 }
1749
1750
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001751 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent
1752 responses (60 seconds): If same delete req is sent and duplicate is
1753 detected, saved duplicate response should be sent back. */
1754 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
1755 f_init();
1756 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1757 f_pdp_ctx_act(ctx);
1758 f_pdp_ctx_del(ctx, '1'B);
1759 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
1760 f_sleep(1.0);
1761 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
1762 duplicate. If it was not a duplicate, osmo-ggsn would answer
1763 with a failure since that PDP ctx was already deleted. */
1764 g_c_seq_nr := g_c_seq_nr - 1;
1765 f_pdp_ctx_del(ctx, '1'B);
1766
1767 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
1768 var OCT1 cause_nonexistent := 'C0'O;
1769 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent);
1770 }
1771
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001772 /* Activate PDP context + trigger Recovery procedure through EchoResp */
1773 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
1774 var Gtp1cUnitdata ud;
1775 g_use_echo := true;
1776 f_init();
1777 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1778 f_pdp_ctx_act(ctx);
1779
1780 /* Wait to receive echo request and send initial Restart counter */
1781 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1782 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1783 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1784 };
1785
1786 /* Wait to receive second echo request and send incremented Restart
1787 counter. This will fake a restarted SGSN, and pdp ctx allocated
1788 should be released by GGSN */
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06001789 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001790 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1791 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1792 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1793 };
1794 f_pdp_ctx_exp_del_req(ctx, omit, true);
1795 setverdict(pass);
1796 }
1797
Harald Welte94ade362017-08-04 00:36:55 +02001798 control {
Harald Welteed7a1772017-08-09 20:26:20 +02001799 execute(TC_pdp4_act_deact());
1800 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02001801 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02001802 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001803 execute(TC_pdp4_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001804 execute(TC_pdp4_act_deact_gtpu_access_wrong_saddr());
1805 execute(TC_pdp4_act_deact_gtpu_access_ipv6_apn4());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001806 execute(TC_pdp4_clients_interact_with_txseq());
1807 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02001808 execute(TC_pdp4_act_deact_with_single_dns());
1809 execute(TC_pdp4_act_deact_with_separate_dns());
Pau Espin Pedrolcd326c52022-02-14 18:57:43 +01001810 execute(TC_pdp4_act_update_teic());
1811 execute(TC_pdp4_act_update_teid());
Harald Welteed7a1772017-08-09 20:26:20 +02001812
1813 execute(TC_pdp6_act_deact());
1814 execute(TC_pdp6_act_deact_pcodns());
1815 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001816 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001817 execute(TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr());
1818 execute(TC_pdp6_act_deact_gtpu_access_wrong_global_saddr());
1819 execute(TC_pdp6_act_deact_gtpu_access_ipv4_apn6());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001820 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02001821
Oliver Smithee6a0882019-03-08 11:05:46 +01001822 execute(TC_pdp46_act_deact());
1823 execute(TC_pdp46_act_deact_ipcp());
1824 execute(TC_pdp46_act_deact_icmp6());
1825 execute(TC_pdp46_act_deact_pcodns4());
1826 execute(TC_pdp46_act_deact_pcodns6());
1827 execute(TC_pdp46_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001828 execute(TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4());
Pau Espin Pedrolc6ac6952022-02-14 11:19:23 +01001829 execute(TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001830 execute(TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6());
Oliver Smithee6a0882019-03-08 11:05:46 +01001831 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001832 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01001833
Harald Weltedca80052017-08-13 20:01:38 +02001834 execute(TC_echo_req_resp());
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001835 execute(TC_echo_req_resp_gtpu());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001836 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001837 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001838
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01001839 execute(TC_pdp_act_restart_ctr_echo());
Harald Welte94ade362017-08-04 00:36:55 +02001840 }
Harald Welte379d45a2017-08-03 09:55:15 +02001841}