blob: 4ea7cf4653364fe1b849dcb1b9e47ed90ef728c5 [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 Pedrol0bcfd9d2022-02-02 11:01:35 +0100379 private altstep as_DIA_CCR(DCC_NONE_CC_Request_Type req_type) runs on GT_CT {
380 var PDU_DIAMETER rx_dia;
381 [] DIAMETER_UNIT.receive(tr_DIA_CCR(req_type := req_type)) -> value rx_dia {
382 var template (omit) AVP avp;
383 var octetstring sess_id;
384 var AVP_Unsigned32 req_num;
385
386 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id);
387 sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id);
388
389 avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number);
390 req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number);
391
392 DIAMETER_UNIT.send(ts_DIA_CCA(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id,
393 req_type, req_num));
394 }
395 [] DIAMETER_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia {
396 setverdict(fail, "Received unexpected DIAMETER ", rx_dia);
397 self.stop;
398 }
399 }
400
Harald Welte811651e2017-08-05 15:25:06 +0200401 /* send a PDP context activation */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +0200402 function f_pdp_ctx_act(inout PdpContext ctx, OCT1 exp_cause := '80'O) runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200403 var Gtp1cUnitdata ud;
Harald Welte94ade362017-08-04 00:36:55 +0200404 var default d;
405
406 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200407 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 +0200408 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100409 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req, ctx.ratType, ctx.uli));
Harald Welte94ade362017-08-04 00:36:55 +0200410 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200411 d := activate(pingpong());
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100412 if (DIAMETER_PROC.checkstate("Connected")) {
413 as_DIA_CCR(INITIAL_REQUEST);
414 }
Harald Welte94ade362017-08-04 00:36:55 +0200415 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200416 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200417 f_handle_create_req(ctx, ud, exp_cause);
Harald Welte94ade362017-08-04 00:36:55 +0200418 }
419 }
420 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200421 T_default.stop;
Harald Welte94ade362017-08-04 00:36:55 +0200422 }
423
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200424 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
425 var Gtp1cUnitdata ud;
426 var default d;
427
428 T_default.start;
429 d := activate(pingpong());
430 alt {
431 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
432 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
433 setverdict(pass);
434 } else if (not istemplatekind(expect_cause, "omit") and
435 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
436 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
437 setverdict(pass);
438 } else {
439 setverdict(fail);
440 }
441
442 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
443 setverdict(pass);
444 } else {
445 setverdict(fail);
446 }
447 }
448 }
449 deactivate(d);
450 T_default.stop;
451 }
452
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200453 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 +0200454 var Gtp1cUnitdata ud;
455 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200456 var OCT4 expect_teid;
457
458 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
459 message with cause value "Non existent" shall be zero. */
460 if (expect_causevalue == 'C0'O) {
461 expect_teid := '00000000'O;
462 } else {
463 expect_teid := ctx.teic;
464 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200465
Harald Welte41575e92017-08-13 13:49:57 +0200466 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 +0200467 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200468 d := activate(pingpong());
Pau Espin Pedrol0bcfd9d2022-02-02 11:01:35 +0100469 if (DIAMETER_PROC.checkstate("Connected")) {
470 as_DIA_CCR(TERMINATION_REQUEST);
471 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200472 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200473 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
474 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200475 setverdict(pass);
476 } else {
477 setverdict(fail);
478 }
479 }
480 }
481 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200482 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200483 }
Harald Welte811651e2017-08-05 15:25:06 +0200484 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
485 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
486 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
487 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200488
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200489 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100490 template PDU_ICMP ts_ICMPv4_ERQ := {
491 echo := {
492 type_field := 8,
493 code := 0,
494 checksum := '0000'O,
495 identifier := '0345'O,
496 sequence_number := '0001'O,
497 data := ''O
498 }
499 }
500
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200501 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100502 template PDU_ICMP tr_ICMPv4_ERQ := {
503 echo := {
504 type_field := 8,
505 code := 0,
506 checksum := ?,
507 identifier := ?,
508 sequence_number := ?,
509 data := ?
510 }
511 }
512
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200513 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100514 template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
515 echo_reply := {
516 type_field := 0,
517 code := 0,
518 checksum := ?,
519 identifier := ?,
520 sequence_number := ?,
521 data := data
522 }
523 }
524
525 /* template for receiving/matching an ICMPv6 Destination Unreachable */
526 template PDU_ICMP tr_ICMPv4_DU := {
527 destination_unreachable := {
528 type_field := 1,
529 code := ?,
530 checksum := ?,
531 unused := ?,
532 original_ip_msg := ?
533 }
534 }
535
536 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
537 template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
538 header := {
539 ver := 4,
540 hlen := 5,
541 tos := 0,
542 tlen := tlen,
543 id := 35902,
544 res := '0'B,
545 dfrag := '1'B,
546 mfrag := '0'B,
547 foffset := 0,
548 ttl := 64,
549 proto := proto,
550 cksum := 0,
551 srcaddr := srcaddr,
552 dstaddr := dstaddr
553 },
554 ext_headers := omit,
555 payload := payload
556 }
557
Harald Welte231b9412017-08-09 17:16:31 +0200558 /* template to generate a 'Prefix Information' ICMPv6 option */
559 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
560 prefixInformation := {
561 typeField := 3,
562 lengthIndicator := 8,
563 prefixLength := prefix_len,
564 reserved1 := '000000'B,
565 a_Bit := '0'B,
566 l_Bit := '0'B,
567 validLifetime := oct2int('FFFFFFFF'O),
568 preferredLifetime := oct2int('FFFFFFFF'O),
569 reserved2 := '00000000'O,
570 prefix := prefix
571 }
572 }
573
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200574 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100575 template PDU_ICMPv6 ts_ICMPv6_ERQ := {
576 echoRequest := {
577 typeField := 128,
578 code := 0,
579 checksum := '0000'O,
580 identifier := 0,
581 sequenceNr := 0,
582 data := ''O
583 }
584 }
585
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200586 /* template for sending an ICMPv6 router solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200587 template PDU_ICMPv6 ts_ICMPv6_RS := {
588 routerSolicitation := {
589 typeField := 133,
590 code := 0,
591 checksum := '0000'O,
592 reserved := '00000000'O,
593 /* TODO: do we need 'Source link-layer address' ? */
594 options := omit
595 }
596 }
597
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200598 /* template for sending an ICMPv6 router advertisement */
Harald Welte231b9412017-08-09 17:16:31 +0200599 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
600 routerAdvertisement := {
601 typeField := 134,
602 code := 0,
603 checksum := '0000'O,
604 curHopLimit := ?,
605 reserved := '000000'B,
606 o_Bit := '0'B,
607 m_Bit := '0'B,
608 routerLifetime := oct2int('FFFF'O),
609 reachableTime := oct2int('FFFFFFFF'O),
610 retransTimer := oct2int('FFFFFFFF'O),
611 options := {
612 ts_ICMP6_OptPrefix(prefix, prefix_len)
613 }
614 }
615 }
616
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200617 /* template for sending an ICMPv6 neighbor solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200618 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
619 neighborSolicitation := {
620 typeField := 135,
621 code := 0,
622 checksum := '0000'O,
623 reserved := '00000000'O,
624 targetAddress := target_addr,
625 /* TODO: do we need 'Source link-layer address' ? */
626 options := omit
627 }
628 }
629
630 /* derive ICMPv6 link-local address from lower 64bit of link_id */
631 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
632 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
633 prefixInformation := {
634 typeField := 3,
635 lengthIndicator := 4,
636 prefixLength := prefix_len,
637 reserved1 := ?,
638 a_Bit := ?,
639 l_Bit := ?,
640 validLifetime := ?,
641 preferredLifetime := ?,
642 reserved2 := ?,
643 prefix := prefix
644 }
645 }
646
647 /* template for receiving/matching an ICMPv6 router advertisement */
648 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
649 routerAdvertisement := {
650 typeField := 134,
651 code := 0,
652 checksum := ?,
653 curHopLimit := ?,
654 reserved := ?,
655 o_Bit := '0'B,
656 m_Bit := '0'B,
657 routerLifetime := ?,
658 reachableTime := ?,
659 retransTimer := ?,
660 options := {
661 tr_ICMP6_OptPrefix(prefix, prefix_len)
662 }
663 }
664 }
665
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100666 /* template for receiving/matching an ICMPv6 Destination Unreachable */
667 template PDU_ICMPv6 tr_ICMPv6_DU := {
668 destinationUnreachable := {
669 typeField := 1,
670 code := ?,
671 checksum := ?,
672 unused := ?,
673 originalIpMsg := ?
674 }
675 }
676
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200677 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100678 template PDU_ICMPv6 tr_ICMPv6_ERQ := {
679 echoRequest := {
680 typeField := 128,
681 code := 0,
682 checksum := ?,
683 identifier := ?,
684 sequenceNr := ?,
685 data := ?
686 }
687 }
688
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100689 /* template for receiving/matching an ICMPv6 echo reply */
690 template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
691 echoReply := {
692 typeField := 129,
693 code := 0,
694 checksum := ?,
695 identifier := ?,
696 sequenceNr := ?,
697 data := data
698 }
699 }
700
Harald Welte231b9412017-08-09 17:16:31 +0200701 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
702 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
703 header := {
704 ver := 6,
705 trclass := 0,
706 flabel := 0,
707 plen := 0,
708 nexthead := nexthead,
709 hlim := hlim,
710 srcaddr := srcaddr,
711 dstaddr := dstaddr
712 },
713 ext_headers := omit,
714 payload := payload
715 }
716
717 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
718 return 'FE80000000000000'O & substr(link_id, 8, 8);
719 }
720
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100721 function f_ipv6_global(in OCT16 link_id) return OCT16 {
722 return substr(link_id, 0, 8) & '1234123412341234'O;
723 }
724
725 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
726 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
727 var integer i;
728 var octetstring res := substr(addr, 0, prefix);
729 for (i := prefix; i < lengthof(addr); i := i + 1) {
730 var octetstring a := addr[i] xor4b '11'O;
731 res := res & a;
732 }
733 return res;
734 }
735
Harald Welte231b9412017-08-09 17:16:31 +0200736 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
737 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
738 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
739 }
740
741 /* generate and encode ICMPv6 router solicitation */
742 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
743 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
744 var OCT16 saddr := f_ipv6_link_local(link_id);
745
746 var octetstring tmp;
747 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
748 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
749
750 return f_IPv6_enc(ip6);
751 }
752
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100753 /* Get link-id from PDP Context EUA */
754 function f_ctx_get_ipv6_interface_id(in PdpContext ctx) return OCT16 {
755 var OCT16 interface_id;
756 if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) {
757 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
758 } else if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv6)) {
759 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
760 } else {
761 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected request to submit icmpv6 rs in IPv4 PDP context");
762 }
763 return interface_id;
764 }
765
Harald Welte231b9412017-08-09 17:16:31 +0200766 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
767 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100768 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200769 return f_gen_icmpv6_router_solicitation(interface_id);
770 }
771
772 /* generate and encode ICMPv6 neighbor solicitation */
773 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
774 var octetstring tmp;
775 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
776 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
777 return f_IPv6_enc(ip6);
778 }
779
780 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
781 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
Pau Espin Pedrol57604212022-02-14 16:54:18 +0100782 var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200783 var OCT16 link_local := f_ipv6_link_local(interface_id);
784 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
785
786 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
787 }
788
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100789 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
790 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring {
791 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ));
792 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
793 var octetstring data := f_IPv4_enc(ip4);
794 var OCT2 cksum := f_IPv4_checksum(data);
795 data[10] := cksum[0];
796 data[11] := cksum[1];
797 return data;
798 }
799
800 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
801 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
802 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
803 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
804 var octetstring data := f_IPv6_enc(ip6);
805 return data;
806 }
807
808 /* Wait for ICMPv4 from GTP */
809 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +0200810 var Gtp1uUnitdata ud;
811 T_default.start;
812 alt {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100813 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200814 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200815 setverdict(fail);
816 stop;
817 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100818 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
819 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
820 if (ip4.header.ver != 4) {
821 repeat;
822 }
823 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
824 if (not match(icmp4, expected)) {
825 repeat;
826 }
827 }
828 [] GTPU.receive { setverdict(fail); }
829 [] T_default.timeout { setverdict(fail); }
830 }
831 T_default.stop;
832 }
833
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100834 /* Wait for ICMPv4 echo request from GTP */
835 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
836 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
837 }
838
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100839 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
840 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
841 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
842 }
843
844 /* Wait for ICMPv6 from GTP */
845 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
846 var Gtp1uUnitdata ud;
847 T_default.start;
848 alt {
Harald Welte231b9412017-08-09 17:16:31 +0200849 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200850 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200851 setverdict(fail);
852 stop;
853 }
Harald Welte231b9412017-08-09 17:16:31 +0200854 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
855 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100856 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +0200857 repeat;
858 }
859 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100860 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +0200861 repeat;
862 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100863 /* We are waiting for RA, update ctx */
864 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
865 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
866 log("RA with /64 prefix ", ctx.ip6_prefix);
867 }
Harald Welte231b9412017-08-09 17:16:31 +0200868 }
869 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
870 [] GTPU.receive { setverdict(fail); }
871 [] T_default.timeout { setverdict(fail); }
872 }
873 T_default.stop;
874 }
875
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100876 /* wait for GGSN to send us an ICMPv6 router advertisement */
877 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
878 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
879 }
880
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100881 /* Wait for ICMPv6 echo request from GTP */
882 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
883 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
884 }
885
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100886 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
887 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
888 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
889 }
890
Oliver Smithee6a0882019-03-08 11:05:46 +0100891 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
892 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
893 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
894 return f_gen_icmpv6_router_solicitation(interface_id);
895 }
896
897 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
898 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
899 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
900 var OCT16 link_local := f_ipv6_link_local(interface_id);
901 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
902
903 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
904 }
905
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100906 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
907 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
908 T_default.start;
909 alt {
910 [] GTPU.receive { setverdict(fail); }
911 [] T_default.timeout { }
912 }
913 T_default.stop;
914 }
915
Harald Welte79737b42019-04-10 10:39:30 +0200916 /* list of protocols where we don't accept duplicates */
917 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
918 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
919 var integer i;
920 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
921 if (id == protocol_ids_nodupes[i]) {
922 return false;
923 }
924 }
925 return true;
926 }
927
928 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
929 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
930 var OCT2List protocol_ids := {};
931 var integer i, j;
932 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
933 var OCT2 id := pco.protocols[i].protocolID;
934 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
935 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
936 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
937 }
938 }
939 protocol_ids := protocol_ids & { id };
940 }
941 }
942
Harald Welte0ef285b2017-08-13 20:06:01 +0200943 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +0200944 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200945 f_init();
Harald Welte231b9412017-08-09 17:16:31 +0200946
Harald Welteed097432017-08-13 13:28:49 +0200947 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 +0200948 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +0200949 f_pdp_ctx_del(ctx, '1'B);
950 }
951
Harald Welte0ef285b2017-08-13 20:06:01 +0200952 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +0200953 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
954 f_init();
955
Harald Welteed097432017-08-13 13:28:49 +0200956 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 +0200957 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
958 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100959
Harald Welte79737b42019-04-10 10:39:30 +0200960 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100961 /* verify PCO contains both primary and secondary DNS */
962 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
963 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
964 setverdict(fail, "Primary DNS IPv6 PCO option not found");
965 }
966
967 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
968 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
969 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
970 }
971
Harald Welteed7a1772017-08-09 20:26:20 +0200972 f_pdp_ctx_del(ctx, '1'B);
973 }
974
Harald Welte0ef285b2017-08-13 20:06:01 +0200975 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +0200976 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
977 f_init();
978
Harald Welteed097432017-08-13 13:28:49 +0200979 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 +0200980 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
981 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200982
Harald Welte79737b42019-04-10 10:39:30 +0200983 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +0200984 //f_send_gtpu(ctx, c_router_solicit);
985 //f_send_gtpu(ctx, c_neigh_solicit);
986
987 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
988 f_wait_rtr_adv(ctx);
989 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
990
Harald Welte811651e2017-08-05 15:25:06 +0200991 f_pdp_ctx_del(ctx, '1'B);
Harald Welte94ade362017-08-04 00:36:55 +0200992 }
993
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100994 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
995 Test we can send ICMPv6 ping over GTPU to DNS server. */
996 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
997 f_init();
998 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
999 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1000 f_pdp_ctx_act(ctx);
1001
1002 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1003 f_wait_rtr_adv(ctx);
1004 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1005
1006 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1007
1008 /* Check if we can use valid link-local src addr. */
1009 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1010 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
Pau Espin Pedrolb63d85f2022-02-07 16:11:47 +01001011 if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) {
1012 f_wait_icmp6_echo_reply(ctx);
1013 } else {
1014 f_wait_gtpu_fail(ctx);
1015 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001016
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001017 /* Check if we can use valid global src addr, should work */
1018 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1019 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
1020 f_wait_icmp6_echo_reply(ctx);
1021
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001022 f_pdp_ctx_del(ctx, '1'B);
1023 }
1024
1025 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1026 testcase TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr() runs on GT_CT {
1027 f_init();
1028 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1029 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1030 f_pdp_ctx_act(ctx);
1031
1032 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1033 f_wait_rtr_adv(ctx);
1034 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1035
1036 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1037 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1038 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1039 f_wait_gtpu_fail(ctx);
1040
1041 f_pdp_ctx_del(ctx, '1'B);
1042 }
1043
1044 /* Assert that packets with wrong global src addr are dropped by GGSN */
1045 testcase TC_pdp6_act_deact_gtpu_access_wrong_global_saddr() runs on GT_CT {
1046 f_init();
1047 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1048 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1049 f_pdp_ctx_act(ctx);
1050
1051 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1052 f_wait_rtr_adv(ctx);
1053 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1054
1055 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1056 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001057 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1058 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
1059 f_wait_gtpu_fail(ctx);
1060
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001061 f_pdp_ctx_del(ctx, '1'B);
1062 }
1063
1064 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped */
1065 testcase TC_pdp6_act_deact_gtpu_access_ipv4_apn6() runs on GT_CT {
1066 f_init();
1067 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1068 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1069 f_pdp_ctx_act(ctx);
1070
1071 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1072 f_wait_rtr_adv(ctx);
1073 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1074
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001075 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
1076 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
1077 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
1078 f_wait_gtpu_fail(ctx);
1079
1080 f_pdp_ctx_del(ctx, '1'B);
1081 }
1082
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001083 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1084 testcase TC_pdp6_clients_interact() runs on GT_CT {
1085 f_init();
1086 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1087 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1088 f_pdp_ctx_act(ctxA);
1089 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
1090 f_wait_rtr_adv(ctxA);
1091 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
1092
1093 f_pdp_ctx_act(ctxB);
1094 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
1095 f_wait_rtr_adv(ctxB);
1096 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
1097
1098 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1099 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1100 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1101 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1102
1103 /* Validate if clients can interact using ll addr. */
1104 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1105 f_wait_gtpu_fail(ctxB);
1106
1107 /* Validate if clients can interact using global addr. */
1108 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1109 f_wait_gtpu_fail(ctxB);
1110
1111 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001112 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001113 }
1114
Harald Welte0ef285b2017-08-13 20:06:01 +02001115 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +02001116 testcase TC_pdp4_act_deact() runs on GT_CT {
1117 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001118 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 +02001119 f_pdp_ctx_act(ctx);
1120 f_pdp_ctx_del(ctx, '1'B);
1121 }
1122
Harald Welte0ef285b2017-08-13 20:06:01 +02001123 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +02001124 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
1125 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001126 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1127 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +02001128 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 +02001129 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +02001130 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001131 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +01001132 /* verify IPCP is at all contained */
1133 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1134 setverdict(fail, "IPCP not found in PCO");
1135 }
1136 /* verify IPCP contains both primary and secondary DNS */
1137 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001138 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1139 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1140 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1141 } else {
1142 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1143 }
Harald Welte71a36022017-12-04 18:55:58 +01001144 }
Harald Welteed7a1772017-08-09 20:26:20 +02001145 f_pdp_ctx_del(ctx, '1'B);
1146 }
1147
Harald Weltef8298542019-04-10 10:15:28 +02001148 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
1149 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
1150 f_init();
1151 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1152 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1153 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1154 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1155 f_pdp_ctx_act(ctx);
1156 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1157 /* verify IPCP is at all contained */
1158 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1159 setverdict(fail, "IPCP not found in PCO");
1160 }
1161 /* verify IPCP contains both primary and secondary DNS */
1162 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1163 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1164 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1165 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1166 } else {
1167 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1168 }
1169 }
1170 /* verify that PAP is contained */
1171 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1172 setverdict(fail, "PAP not found in PCO");
1173 }
1174 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1175 if (not match(pap, tr_PAP_AuthAck)) {
1176 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1177 }
1178 f_pdp_ctx_del(ctx, '1'B);
1179 }
1180
Harald Welte0ef285b2017-08-13 20:06:01 +02001181 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001182 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1183 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001184 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 +02001185 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001186 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001187
Harald Welte79737b42019-04-10 10:39:30 +02001188 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001189 /* verify PCO contains both primary and secondary DNS */
1190 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1191 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1192 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1193 }
1194
1195 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1196 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1197 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1198 }
1199
Harald Welteed7a1772017-08-09 20:26:20 +02001200 f_pdp_ctx_del(ctx, '1'B);
1201 }
1202
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001203 /* Test PDP context activation for dynamic IPv4 EUA.
1204 Test we can send ICMPv6 ping over GTPU to DNS server. */
1205 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1206 f_init();
1207 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1208 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1209 f_pdp_ctx_act(ctx);
1210
Harald Welte79737b42019-04-10 10:39:30 +02001211 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001212 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1213
1214 /* Check if we can use valid global src addr, should work */
1215 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1216 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1217 f_wait_icmp4_echo_reply(ctx);
1218
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001219 f_pdp_ctx_del(ctx, '1'B);
1220 }
1221
1222 /* Assert that packets with wrong global src addr are dropped by GGSN */
1223 testcase TC_pdp4_act_deact_gtpu_access_wrong_saddr() runs on GT_CT {
1224 f_init();
1225 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1226 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1227 f_pdp_ctx_act(ctx);
1228
1229 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1230 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1231 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001232 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1233 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1234 f_wait_gtpu_fail(ctx);
1235
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001236 f_pdp_ctx_del(ctx, '1'B);
1237 }
1238
1239 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1240 testcase TC_pdp4_act_deact_gtpu_access_ipv6_apn4() runs on GT_CT {
1241 f_init();
1242 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1243 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1244 f_pdp_ctx_act(ctx);
1245
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001246 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1247 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1248 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1249 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001250
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001251 f_pdp_ctx_del(ctx, '1'B);
1252 }
1253
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001254 /* Helper function for tests below. */
1255 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001256 f_init();
1257 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1258 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1259 f_pdp_ctx_act(ctxA);
1260 f_pdp_ctx_act(ctxB);
1261 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1262 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1263 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1264 f_wait_icmp4_echo_request(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 Pedrol6c7285d2018-01-30 17:20:22 +01001268 }
1269
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001270 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1271 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001272 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001273 f_pdp4_clients_interact();
1274 }
1275
1276 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1277 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001278 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001279 f_pdp4_clients_interact();
1280 }
1281
Harald Weltedca80052017-08-13 20:01:38 +02001282 testcase TC_echo_req_resp() runs on GT_CT {
1283 f_init();
1284 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1285 T_default.start;
1286 alt {
1287 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1288 [] GTPC.receive { repeat; };
1289 [] T_default.timeout { setverdict(fail); }
1290 }
1291 T_default.stop;
1292 }
1293
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001294 testcase TC_echo_req_resp_gtpu() runs on GT_CT {
1295 f_init();
1296 GTPU.send(ts_GTPU_PING(g_peer_u, g_d_seq_nr));
1297 T_default.start;
1298 alt {
1299 [] GTPU.receive(tr_GTPU_PONG(g_peer_u)) { setverdict(pass); };
1300 [] GTPU.receive { repeat; };
1301 [] T_default.timeout { setverdict(fail); }
1302 }
1303 T_default.stop;
1304 }
1305
Philipp Maier33e52612018-05-30 17:22:02 +02001306 /* Test if the parser can cope with PCO that only contain either a
1307 * single primary DNS or a secondary DNS. */
1308 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1309
1310 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1311 * the test is executed.
1312 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1313
1314 f_init();
1315 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1316 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1317 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1318 var octetstring pco_neg_dns;
1319 var octetstring pco_neg_dns_expected;
1320
1321 /* PCO with primary DNS only */
1322 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1323 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001324 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001325 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1326 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1327 /* Note: The prepended hex bytes encode the following information:
1328 * 0x02 = Configuration ACK
1329 * 0x00 = Identifier
1330 * 0x000a = Length
1331 * 0x81 = Type (Primary DNS Server Address)
1332 * 0x06 = Length
1333 * (4 byte IP-Address appended) */
1334 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1335 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1336 }
1337 f_pdp_ctx_del(ctx, '1'B);
1338
1339 /* PCO with secondary DNS only */
Harald Welte7ef6d102021-04-01 21:24:35 +02001340 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001341 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1342 f_pdp_ctx_act(ctx);
1343 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1344 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1345 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1346 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1347 }
1348 f_pdp_ctx_del(ctx, '1'B);
1349 }
1350
1351 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1352 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1353 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1354 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1355
1356 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1357 * the test is executed.
1358 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1359
1360 f_init();
1361 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1362 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1363 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1364 var octetstring pco_neg_dns;
1365 var octetstring pco_neg_dns_expected;
1366
1367 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1368 f_pdp_ctx_act(ctx);
1369
1370 /* Check if primary DNS is contained */
1371 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1372 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1373 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1374 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1375 }
Philipp Maier33e52612018-05-30 17:22:02 +02001376
1377 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001378 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1379 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001380 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1381 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1382 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1383 }
1384 f_pdp_ctx_del(ctx, '1'B);
1385 }
1386
Oliver Smithee6a0882019-03-08 11:05:46 +01001387 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1388 testcase TC_pdp46_act_deact() runs on GT_CT {
1389 f_init();
1390 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1391 f_pdp_ctx_act(ctx);
1392 f_pdp_ctx_del(ctx, '1'B);
1393 }
1394
1395 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1396 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1397 f_init();
1398 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1399 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1400 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1401 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1402 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001403 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001404 /* verify IPCP is at all contained */
1405 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1406 setverdict(fail, "IPCP not found in PCO");
1407 }
Harald Welte79737b42019-04-10 10:39:30 +02001408 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001409 /* verify IPCP contains both primary and secondary IPv4 DNS */
1410 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1411 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1412 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1413 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1414 } else {
1415 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1416 }
1417 }
1418 f_pdp_ctx_del(ctx, '1'B);
1419 }
1420
1421 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1422 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1423 f_init();
1424 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1425 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1426 f_pdp_ctx_act(ctx);
1427
1428 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1429 f_wait_rtr_adv(ctx);
1430 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1431
1432 f_pdp_ctx_del(ctx, '1'B);
1433 }
1434
1435 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1436 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1437 f_init();
1438
1439 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1440 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1441 f_pdp_ctx_act(ctx);
1442
Harald Welte79737b42019-04-10 10:39:30 +02001443 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001444 /* verify PCO contains both primary and secondary IPv4 DNS */
1445 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1446 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1447 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1448 }
1449
1450 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1451 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1452 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1453 }
1454
1455 f_pdp_ctx_del(ctx, '1'B);
1456 }
1457
1458 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1459 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1460 f_init();
1461
1462 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1463 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1464 f_pdp_ctx_act(ctx);
1465
Harald Welte79737b42019-04-10 10:39:30 +02001466 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001467 /* verify PCO contains both primary and secondary IPv6 DNS */
1468 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1469 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1470 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1471 }
1472
1473 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1474 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1475 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1476 }
1477
1478 f_pdp_ctx_del(ctx, '1'B);
1479 }
1480
1481 /* Test PDP context activation for dynamic IPv4v6 EUA.
1482 Test we can send ICMPv6 ping over GTPU to DNS server. */
1483 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1484 f_init();
1485 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1486 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1487 f_pdp_ctx_act(ctx);
1488
1489 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1490
1491 /* Check if we can use valid global src addr, should work */
1492 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1493 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1494 f_wait_icmp4_echo_reply(ctx);
1495
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001496 f_pdp_ctx_del(ctx, '1'B);
1497 }
1498
1499 /* Assert that packets with wrong ipv4 src addr are dropped by GGSN on APN IPv4v6 */
1500 testcase TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4() runs on GT_CT {
1501 f_init();
1502 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1503 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1504 f_pdp_ctx_act(ctx);
1505
1506 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1507 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
Oliver Smithee6a0882019-03-08 11:05:46 +01001508 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1509 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1510 f_wait_gtpu_fail(ctx);
1511
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001512 f_pdp_ctx_del(ctx, '1'B);
1513 }
1514
1515 /* Assert that packets with wrong ipv6 global src addr are dropped by GGSN on APN IPv4v6 */
1516 testcase TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6() runs on GT_CT {
1517 f_init();
1518 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1519 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1520 f_pdp_ctx_act(ctx);
1521
Oliver Smithee6a0882019-03-08 11:05:46 +01001522 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1523 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1524 f_wait_gtpu_fail(ctx);
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001525
Oliver Smithee6a0882019-03-08 11:05:46 +01001526 f_pdp_ctx_del(ctx, '1'B);
1527 }
1528
1529 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1530 testcase TC_pdp46_clients_interact() runs on GT_CT {
1531 f_init();
1532 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1533 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1534 f_pdp_ctx_act(ctxA);
1535 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1536 f_wait_rtr_adv(ctxA);
1537 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1538
1539 f_pdp_ctx_act(ctxB);
1540 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1541 f_wait_rtr_adv(ctxB);
1542 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1543
1544 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1545 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1546 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1547 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1548
1549 /* Validate if clients can interact using ll addr. */
1550 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1551 f_wait_gtpu_fail(ctxB);
1552
1553 /* Validate if clients can interact using global addr. */
1554 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1555 f_wait_gtpu_fail(ctxB);
1556
1557 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001558 f_pdp_ctx_del(ctxB, '1'B);
Oliver Smithee6a0882019-03-08 11:05:46 +01001559 }
1560
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001561 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
1562 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
1563 f_init();
1564 /* A typical MS first attempts v4v6, and if rejected, then tries v4 and v6 separetly */
1565 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
1566 f_pdp_ctx_act(ctx46, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1567
1568 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1569 f_pdp_ctx_act(ctx4, '80'O); /* Normal accept cause */
1570
1571 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv6Dyn)));
1572 f_pdp_ctx_act(ctx6, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1573
1574 f_pdp_ctx_del(ctx4, '1'B);
1575 }
1576
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001577 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
1578 testcase TC_pdp_act2_recovery() runs on GT_CT {
1579 var Gtp1cUnitdata ud;
1580 var default d;
1581 var boolean ctxA_deleted := false;
1582 var boolean ctxB_created := false;
1583
1584 f_init();
1585 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1586 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1587 f_pdp_ctx_act(ctxA);
1588
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06001589 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001590
1591 log("sending 2nd CreatePDP (recovery increased)");
1592 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
1593 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
1594 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
1595 T_default.start;
1596 d := activate(pingpong());
1597 alt {
1598 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
1599 f_handle_create_req(ctxB, ud);
1600 if (not ctxB_created) {
1601 ctxB_created := true;
1602 setverdict(pass);
1603 } else {
1604 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
1605 }
1606
1607 if (not ctxA_deleted) {
1608 repeat;
1609 }
1610 }
1611 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
1612 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
1613 setverdict(pass);
1614 } else {
1615 setverdict(fail);
1616 }
1617
1618 if (not ctxA_deleted) {
1619 ctxA_deleted := true;
1620 setverdict(pass);
1621 } else {
1622 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
1623 }
1624
1625 if (not ctxB_created) {
1626 repeat;
1627 }
1628 }
1629 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
1630 setverdict(fail, "GGSN dropping still valid pdp ctx");
1631 }
1632 }
1633 deactivate(d);
1634 T_default.stop;
1635
1636 f_pdp_ctx_del(ctxB, '1'B);
1637 }
1638
1639
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001640 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent
1641 responses (60 seconds): If same delete req is sent and duplicate is
1642 detected, saved duplicate response should be sent back. */
1643 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
1644 f_init();
1645 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1646 f_pdp_ctx_act(ctx);
1647 f_pdp_ctx_del(ctx, '1'B);
1648 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
1649 f_sleep(1.0);
1650 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
1651 duplicate. If it was not a duplicate, osmo-ggsn would answer
1652 with a failure since that PDP ctx was already deleted. */
1653 g_c_seq_nr := g_c_seq_nr - 1;
1654 f_pdp_ctx_del(ctx, '1'B);
1655
1656 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
1657 var OCT1 cause_nonexistent := 'C0'O;
1658 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent);
1659 }
1660
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001661 /* Activate PDP context + trigger Recovery procedure through EchoResp */
1662 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
1663 var Gtp1cUnitdata ud;
1664 g_use_echo := true;
1665 f_init();
1666 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1667 f_pdp_ctx_act(ctx);
1668
1669 /* Wait to receive echo request and send initial Restart counter */
1670 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1671 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1672 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1673 };
1674
1675 /* Wait to receive second echo request and send incremented Restart
1676 counter. This will fake a restarted SGSN, and pdp ctx allocated
1677 should be released by GGSN */
Vadim Yanitskiyd344b4a2022-02-09 18:28:18 +06001678 g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001679 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1680 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1681 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1682 };
1683 f_pdp_ctx_exp_del_req(ctx, omit, true);
1684 setverdict(pass);
1685 }
1686
Harald Welte94ade362017-08-04 00:36:55 +02001687 control {
Harald Welteed7a1772017-08-09 20:26:20 +02001688 execute(TC_pdp4_act_deact());
1689 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02001690 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02001691 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001692 execute(TC_pdp4_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001693 execute(TC_pdp4_act_deact_gtpu_access_wrong_saddr());
1694 execute(TC_pdp4_act_deact_gtpu_access_ipv6_apn4());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001695 execute(TC_pdp4_clients_interact_with_txseq());
1696 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02001697 execute(TC_pdp4_act_deact_with_single_dns());
1698 execute(TC_pdp4_act_deact_with_separate_dns());
Harald Welteed7a1772017-08-09 20:26:20 +02001699
1700 execute(TC_pdp6_act_deact());
1701 execute(TC_pdp6_act_deact_pcodns());
1702 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001703 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001704 execute(TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr());
1705 execute(TC_pdp6_act_deact_gtpu_access_wrong_global_saddr());
1706 execute(TC_pdp6_act_deact_gtpu_access_ipv4_apn6());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001707 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02001708
Oliver Smithee6a0882019-03-08 11:05:46 +01001709 execute(TC_pdp46_act_deact());
1710 execute(TC_pdp46_act_deact_ipcp());
1711 execute(TC_pdp46_act_deact_icmp6());
1712 execute(TC_pdp46_act_deact_pcodns4());
1713 execute(TC_pdp46_act_deact_pcodns6());
1714 execute(TC_pdp46_act_deact_gtpu_access());
Pau Espin Pedrolc8c03412022-02-11 13:39:26 +01001715 execute(TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4());
1716 execute(TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6());
Oliver Smithee6a0882019-03-08 11:05:46 +01001717 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001718 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01001719
Harald Weltedca80052017-08-13 20:01:38 +02001720 execute(TC_echo_req_resp());
Pau Espin Pedrol480e67f2022-02-09 16:37:47 +01001721 execute(TC_echo_req_resp_gtpu());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001722 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001723 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001724
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01001725 execute(TC_pdp_act_restart_ctr_echo());
Harald Welte94ade362017-08-04 00:36:55 +02001726 }
Harald Welte379d45a2017-08-03 09:55:15 +02001727}