blob: 4a53fa14ac6a2fe8465e25ed90ad38ce970b27dc [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;
Harald Welte94ade362017-08-04 00:36:55 +020017 import from IPL4asp_PortType all;
18 import from IPL4asp_Types all;
19 import from GTP_CodecPort all;
20 import from GTP_CodecPort_CtrlFunct all;
Harald Weltec69cf4e2018-02-17 20:57:02 +010021 import from GTP_Templates all;
Harald Welte94ade362017-08-04 00:36:55 +020022 import from GTPC_Types all;
23 import from GTPU_Types all;
Harald Welte71a36022017-12-04 18:55:58 +010024 import from IPCP_Types all;
Harald Weltef8298542019-04-10 10:15:28 +020025 import from PAP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020026 import from IP_Types all;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +010027 import from ICMP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020028 import from ICMPv6_Types all;
Harald Welteddeecbb2017-08-18 22:53:30 +020029 import from Native_Functions all;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +020030 import from Osmocom_VTY_Functions all;
31 import from TELNETasp_PortType all;
Harald Welte94ade362017-08-04 00:36:55 +020032
33 const integer GTP0_PORT := 3386;
34 const integer GTP1C_PORT := 2123;
35 const integer GTP1U_PORT := 2152;
Harald Welteddeecbb2017-08-18 22:53:30 +020036
37 modulepar {
Stefan Sperlingcb782b92018-04-03 16:03:15 +020038 /* Default IP addresses. May be overridden by GGSN_Tests configuration files. */
39
40 /* The SGSN simulated by TTCN3 will bind to these addresses for GTP control and GTP user planes. */
Harald Welteddeecbb2017-08-18 22:53:30 +020041 charstring m_bind_ip_gtpc := "127.23.42.1";
42 charstring m_bind_ip_gtpu := "127.23.42.1";
43
Stefan Sperlingcb782b92018-04-03 16:03:15 +020044 /* Addresses the GGSN which is being tested is listening on for SGSN connections. */
Harald Welteddeecbb2017-08-18 22:53:30 +020045 charstring m_ggsn_ip_gtpc := "127.0.0.6";
46 charstring m_ggsn_ip_gtpu := "127.0.0.6";
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010047
Stefan Sperlingcb782b92018-04-03 16:03:15 +020048 /*
49 * Our tests expect to see these DNS servers in 'Create PDP context responses' sent by the GGSN.
50 * These addresses must therefore match 'ip[v6] dns' options configured in osmo-ggsn.conf.
51 *
52 * These addresses are not expected to serve actual DNS requests. However, tests may expect to be
53 * able to ping these addresses (currently, IPv4 addresses must respond with an ICMP 'echo reply',
54 * and IPv6 addresses may respond with either ICMPv6 'echo reply' or 'destination unreachable').
55 */
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010056 charstring m_ggsn_ip4_dns1 := "192.168.100.1"
57 charstring m_ggsn_ip4_dns2 := "8.8.8.8"
Pau Espin Pedrol363ba482018-01-29 18:42:00 +010058 charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888"
59 charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844"
Stefan Sperlingcb782b92018-04-03 16:03:15 +020060
61 /*
62 * Additional address ranges are defined in osmo-ggsn.conf from which addresses are assigned
63 * to MS "behind" the simulated SGSN. These addresses appear on tun devices used by osmo-ggsn.
64 * The tests expect to be able to send ping packets between any two simulated MS within the same
65 * address range. This requires IP forwarding to be enabled on the corresponding tun interfaces.
66 */
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +020067
68 /*
69 * Whether ggsn supports "(no) echo-interval" VTY command
70 * (osmo-ggsn.git Id2c84165dc59dff495106758146a701ca488834f).
71 * This option can be dropped after osmo-ggsn release > 1.4.0 exists.
72 */
73 boolean m_ggsn_supports_echo_interval := true;
Harald Welteddeecbb2017-08-18 22:53:30 +020074 }
Harald Welte94ade362017-08-04 00:36:55 +020075
Harald Welte811651e2017-08-05 15:25:06 +020076 type set PdpContext {
77 hexstring imsi,
78 octetstring msisdn optional,
79 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020080 ProtConfigOptions pco_req optional,
81 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020082 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020083 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020084 BIT4 nsapi,
85 /* TEI (Data) local side */
86 OCT4 teid,
87 /* TEI (Control) local side */
88 OCT4 teic,
89 /* TEI (Data) remote side */
90 OCT4 teid_remote,
91 /* TEI (Control) remote side */
Harald Welte5438b9d2017-08-13 13:27:48 +020092 OCT4 teic_remote
Harald Welte811651e2017-08-05 15:25:06 +020093 }
94
Harald Welte94ade362017-08-04 00:36:55 +020095 type component GT_CT {
96 port GTPC_PT GTPC;
97 port GTPU_PT GTPU;
98
Harald Welte0be142b2017-08-13 13:28:10 +020099 var boolean g_initialized := false;
100
Harald Welte94ade362017-08-04 00:36:55 +0200101 var OCT1 g_restart_ctr := '01'O;
102 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200103 var OCT4 g_sgsn_ip_c;
104 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +0200105 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200106 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
107 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200108 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200109
110 /* next to-be-sent GTP-C sequence number */
111 var uint16_t g_c_seq_nr;
112 /* next to-be-sent GTP-U sequence number */
113 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200114
115 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200116 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200117 var boolean g_use_echo := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200118 }
119
120 private function f_init_vty() runs on GT_CT {
121 map(self:GGSNVTY, system:GGSNVTY);
122 f_vty_set_prompts(GGSNVTY);
123 f_vty_transceive(GGSNVTY, "enable");
124 }
125
126 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
127 f_vty_enter_config(GGSNVTY);
128 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200129
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200130 f_vty_transceive(GGSNVTY, "apn internet");
131 if (enable) {
132 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
133 } else {
134 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
135 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200136 f_vty_transceive(GGSNVTY, "exit");
137
138 f_vty_transceive(GGSNVTY, "apn inet6");
139 if (enable) {
140 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
141 } else {
142 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
143 }
144 f_vty_transceive(GGSNVTY, "exit");
145
146 f_vty_transceive(GGSNVTY, "apn inet46");
147 if (enable) {
148 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
149 } else {
150 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
151 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200152 f_vty_transceive(GGSNVTY, "end");
153 }
154
155 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
156 if (expect_gptu_txseq) {
157 if (gtpu.s_bit != '1'B) {
158 log("GTPU sequence number expected but not present")
159 return false;
160 }
161 } else {
162 if (gtpu.s_bit != '0'B) {
163 log("GTPU sequence number not expected but present")
164 return false;
165 }
166 }
167 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200168 }
169
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200170 private function f_vty_enable_echo_interval(boolean enable) runs on GT_CT {
171 f_vty_enter_config(GGSNVTY);
172 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
173 if (enable) {
174 f_vty_transceive(GGSNVTY, "echo-interval 5");
175 } else {
176 f_vty_transceive(GGSNVTY, "no echo-interval");
177 }
178 f_vty_transceive(GGSNVTY, "end");
179 }
180
Harald Welte94ade362017-08-04 00:36:55 +0200181 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200182 if (g_initialized == true) {
183 return;
184 }
185 g_initialized := true;
186
Harald Welteddeecbb2017-08-18 22:53:30 +0200187 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
188 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
189
Harald Welte94ade362017-08-04 00:36:55 +0200190 var Result res;
191 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +0200192 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200193 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200194 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200195
196 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +0200197 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200198 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200199
200 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200201 g_c_seq_nr := f_rnd_int(65535);
202 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200203
204 f_init_vty();
Harald Welte3e0b0392018-04-26 09:46:21 +0200205 f_vty_set_gpdu_txseq(use_gtpu_txseq);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200206 if (m_ggsn_supports_echo_interval) {
207 f_vty_enable_echo_interval(g_use_echo);
208 }
Harald Welte94ade362017-08-04 00:36:55 +0200209 }
210
Harald Welte94ade362017-08-04 00:36:55 +0200211 /* Altstep implementing responses to any incoming echo requests */
212 altstep pingpong() runs on GT_CT {
213 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200214 var Gtp1uUnitdata udu;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200215 [g_use_echo] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200216 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200217 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200218 repeat;
219 };
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200220 [not g_use_echo] GTPC.receive(tr_GTPC_PING(?)) {
221 setverdict(fail, "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200222 };
Harald Welte94ade362017-08-04 00:36:55 +0200223 [] T_default.timeout { setverdict(fail); };
224 }
225
Harald Welte811651e2017-08-05 15:25:06 +0200226 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200227 const octetstring c_ApnInternet := '08696E7465726E6574'O;
228 const octetstring c_ApnInet6 := '05696E657436'O;
229 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200230
Harald Welte811651e2017-08-05 15:25:06 +0200231 /* return random NSAPI */
232 function f_rnd_nsapi() return BIT4 {
233 return int2bit(f_rnd_int(16), 4);
234 }
235
236 /* return random TEI[DC] */
237 function f_rnd_tei() return OCT4 {
238 return int2oct(f_rnd_int(4294967296), 4);
239 }
240
241 /* define an (internal) representation of a PDP context */
242 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
243 EndUserAddress eua) := {
244 imsi := imsi,
245 msisdn := msisdn,
246 nsapi := f_rnd_nsapi(),
247 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200248 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200249 eua := eua,
250 teid := f_rnd_tei(),
Harald Welte5438b9d2017-08-13 13:27:48 +0200251 teic := f_rnd_tei()
Harald Welte811651e2017-08-05 15:25:06 +0200252 }
253
254 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200255 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200256 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200257 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200258 }
259
260 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200261 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200262 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200263 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
264 g_d_seq_nr := g_d_seq_nr + 1;
265 } else {
266 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
267 }
Harald Welte811651e2017-08-05 15:25:06 +0200268 }
269
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200270 function f_handle_create_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
271 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
272 if (exp_cause == '80'O and exp_cause == cpr.cause.causevalue) {
273 /* Check if EUA type corresponds to requested type */
274 if (match(ctx.eua, t_EuaIPv4(?)) and
275 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
276 setverdict(fail);
277 }
278 if (match(ctx.eua, t_EuaIPv6(?)) and
279 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
280 setverdict(fail);
281 }
282 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
283 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
284 setverdict(fail);
285 }
286 /* Check if PCO response corresponds to request */
287 if (ispresent(ctx.pco_req)) {
288 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
289 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
290 log("IPv4 DNS Container requested, but missing");
291 setverdict(fail);
292 }
293 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
294 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
295 log("IPv6 DNS Container requested, but missing");
296 setverdict(fail);
297 }
298 }
299 ctx.teid_remote := cpr.teidDataI.teidDataI;
300 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
301 ctx.eua := cpr.endUserAddress;
302 ctx.pco_neg := cpr.protConfigOptions;
303 setverdict(pass);
304 } else if (exp_cause != '80'O and exp_cause == cpr.cause.causevalue) {
305 if (ispresent(cpr.endUserAddress)) {
306 log("EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
307 setverdict(fail);
308 }
309 setverdict(pass);
310 } else {
311 setverdict(fail);
312 }
313 }
314
Harald Welte811651e2017-08-05 15:25:06 +0200315 /* send a PDP context activation */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +0200316 function f_pdp_ctx_act(inout PdpContext ctx, OCT1 exp_cause := '80'O) runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200317 var Gtp1cUnitdata ud;
Harald Welte94ade362017-08-04 00:36:55 +0200318 var default d;
319
320 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200321 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 +0200322 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200323 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req));
Harald Welte94ade362017-08-04 00:36:55 +0200324 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200325 d := activate(pingpong());
326 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200327 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200328 f_handle_create_req(ctx, ud, exp_cause);
Harald Welte94ade362017-08-04 00:36:55 +0200329 }
330 }
331 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200332 T_default.stop;
Harald Welte94ade362017-08-04 00:36:55 +0200333 }
334
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200335 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
336 var Gtp1cUnitdata ud;
337 var default d;
338
339 T_default.start;
340 d := activate(pingpong());
341 alt {
342 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
343 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
344 setverdict(pass);
345 } else if (not istemplatekind(expect_cause, "omit") and
346 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
347 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
348 setverdict(pass);
349 } else {
350 setverdict(fail);
351 }
352
353 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
354 setverdict(pass);
355 } else {
356 setverdict(fail);
357 }
358 }
359 }
360 deactivate(d);
361 T_default.stop;
362 }
363
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200364 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 +0200365 var Gtp1cUnitdata ud;
366 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200367 var OCT4 expect_teid;
368
369 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
370 message with cause value "Non existent" shall be zero. */
371 if (expect_causevalue == 'C0'O) {
372 expect_teid := '00000000'O;
373 } else {
374 expect_teid := ctx.teic;
375 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200376
Harald Welte41575e92017-08-13 13:49:57 +0200377 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 +0200378 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200379 d := activate(pingpong());
380 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200381 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
382 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200383 setverdict(pass);
384 } else {
385 setverdict(fail);
386 }
387 }
388 }
389 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200390 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200391 }
Harald Welte811651e2017-08-05 15:25:06 +0200392 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
393 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
394 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
395 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200396
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200397 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100398 template PDU_ICMP ts_ICMPv4_ERQ := {
399 echo := {
400 type_field := 8,
401 code := 0,
402 checksum := '0000'O,
403 identifier := '0345'O,
404 sequence_number := '0001'O,
405 data := ''O
406 }
407 }
408
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200409 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100410 template PDU_ICMP tr_ICMPv4_ERQ := {
411 echo := {
412 type_field := 8,
413 code := 0,
414 checksum := ?,
415 identifier := ?,
416 sequence_number := ?,
417 data := ?
418 }
419 }
420
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200421 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100422 template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
423 echo_reply := {
424 type_field := 0,
425 code := 0,
426 checksum := ?,
427 identifier := ?,
428 sequence_number := ?,
429 data := data
430 }
431 }
432
433 /* template for receiving/matching an ICMPv6 Destination Unreachable */
434 template PDU_ICMP tr_ICMPv4_DU := {
435 destination_unreachable := {
436 type_field := 1,
437 code := ?,
438 checksum := ?,
439 unused := ?,
440 original_ip_msg := ?
441 }
442 }
443
444 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
445 template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
446 header := {
447 ver := 4,
448 hlen := 5,
449 tos := 0,
450 tlen := tlen,
451 id := 35902,
452 res := '0'B,
453 dfrag := '1'B,
454 mfrag := '0'B,
455 foffset := 0,
456 ttl := 64,
457 proto := proto,
458 cksum := 0,
459 srcaddr := srcaddr,
460 dstaddr := dstaddr
461 },
462 ext_headers := omit,
463 payload := payload
464 }
465
Harald Welte231b9412017-08-09 17:16:31 +0200466 /* template to generate a 'Prefix Information' ICMPv6 option */
467 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
468 prefixInformation := {
469 typeField := 3,
470 lengthIndicator := 8,
471 prefixLength := prefix_len,
472 reserved1 := '000000'B,
473 a_Bit := '0'B,
474 l_Bit := '0'B,
475 validLifetime := oct2int('FFFFFFFF'O),
476 preferredLifetime := oct2int('FFFFFFFF'O),
477 reserved2 := '00000000'O,
478 prefix := prefix
479 }
480 }
481
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200482 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100483 template PDU_ICMPv6 ts_ICMPv6_ERQ := {
484 echoRequest := {
485 typeField := 128,
486 code := 0,
487 checksum := '0000'O,
488 identifier := 0,
489 sequenceNr := 0,
490 data := ''O
491 }
492 }
493
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200494 /* template for sending an ICMPv6 router solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200495 template PDU_ICMPv6 ts_ICMPv6_RS := {
496 routerSolicitation := {
497 typeField := 133,
498 code := 0,
499 checksum := '0000'O,
500 reserved := '00000000'O,
501 /* TODO: do we need 'Source link-layer address' ? */
502 options := omit
503 }
504 }
505
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200506 /* template for sending an ICMPv6 router advertisement */
Harald Welte231b9412017-08-09 17:16:31 +0200507 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
508 routerAdvertisement := {
509 typeField := 134,
510 code := 0,
511 checksum := '0000'O,
512 curHopLimit := ?,
513 reserved := '000000'B,
514 o_Bit := '0'B,
515 m_Bit := '0'B,
516 routerLifetime := oct2int('FFFF'O),
517 reachableTime := oct2int('FFFFFFFF'O),
518 retransTimer := oct2int('FFFFFFFF'O),
519 options := {
520 ts_ICMP6_OptPrefix(prefix, prefix_len)
521 }
522 }
523 }
524
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200525 /* template for sending an ICMPv6 neighbor solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200526 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
527 neighborSolicitation := {
528 typeField := 135,
529 code := 0,
530 checksum := '0000'O,
531 reserved := '00000000'O,
532 targetAddress := target_addr,
533 /* TODO: do we need 'Source link-layer address' ? */
534 options := omit
535 }
536 }
537
538 /* derive ICMPv6 link-local address from lower 64bit of link_id */
539 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
540 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
541 prefixInformation := {
542 typeField := 3,
543 lengthIndicator := 4,
544 prefixLength := prefix_len,
545 reserved1 := ?,
546 a_Bit := ?,
547 l_Bit := ?,
548 validLifetime := ?,
549 preferredLifetime := ?,
550 reserved2 := ?,
551 prefix := prefix
552 }
553 }
554
555 /* template for receiving/matching an ICMPv6 router advertisement */
556 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
557 routerAdvertisement := {
558 typeField := 134,
559 code := 0,
560 checksum := ?,
561 curHopLimit := ?,
562 reserved := ?,
563 o_Bit := '0'B,
564 m_Bit := '0'B,
565 routerLifetime := ?,
566 reachableTime := ?,
567 retransTimer := ?,
568 options := {
569 tr_ICMP6_OptPrefix(prefix, prefix_len)
570 }
571 }
572 }
573
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100574 /* template for receiving/matching an ICMPv6 Destination Unreachable */
575 template PDU_ICMPv6 tr_ICMPv6_DU := {
576 destinationUnreachable := {
577 typeField := 1,
578 code := ?,
579 checksum := ?,
580 unused := ?,
581 originalIpMsg := ?
582 }
583 }
584
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200585 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100586 template PDU_ICMPv6 tr_ICMPv6_ERQ := {
587 echoRequest := {
588 typeField := 128,
589 code := 0,
590 checksum := ?,
591 identifier := ?,
592 sequenceNr := ?,
593 data := ?
594 }
595 }
596
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100597 /* template for receiving/matching an ICMPv6 echo reply */
598 template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
599 echoReply := {
600 typeField := 129,
601 code := 0,
602 checksum := ?,
603 identifier := ?,
604 sequenceNr := ?,
605 data := data
606 }
607 }
608
Harald Welte231b9412017-08-09 17:16:31 +0200609 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
610 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
611 header := {
612 ver := 6,
613 trclass := 0,
614 flabel := 0,
615 plen := 0,
616 nexthead := nexthead,
617 hlim := hlim,
618 srcaddr := srcaddr,
619 dstaddr := dstaddr
620 },
621 ext_headers := omit,
622 payload := payload
623 }
624
625 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
626 return 'FE80000000000000'O & substr(link_id, 8, 8);
627 }
628
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100629 function f_ipv6_global(in OCT16 link_id) return OCT16 {
630 return substr(link_id, 0, 8) & '1234123412341234'O;
631 }
632
633 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
634 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
635 var integer i;
636 var octetstring res := substr(addr, 0, prefix);
637 for (i := prefix; i < lengthof(addr); i := i + 1) {
638 var octetstring a := addr[i] xor4b '11'O;
639 res := res & a;
640 }
641 return res;
642 }
643
Harald Welte231b9412017-08-09 17:16:31 +0200644 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
645 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
646 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
647 }
648
649 /* generate and encode ICMPv6 router solicitation */
650 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
651 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
652 var OCT16 saddr := f_ipv6_link_local(link_id);
653
654 var octetstring tmp;
655 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
656 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
657
658 return f_IPv6_enc(ip6);
659 }
660
661 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
662 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
663 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
664 return f_gen_icmpv6_router_solicitation(interface_id);
665 }
666
667 /* generate and encode ICMPv6 neighbor solicitation */
668 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
669 var octetstring tmp;
670 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
671 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
672 return f_IPv6_enc(ip6);
673 }
674
675 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
676 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
677 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
678 var OCT16 link_local := f_ipv6_link_local(interface_id);
679 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
680
681 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
682 }
683
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100684 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
685 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring {
686 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ));
687 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
688 var octetstring data := f_IPv4_enc(ip4);
689 var OCT2 cksum := f_IPv4_checksum(data);
690 data[10] := cksum[0];
691 data[11] := cksum[1];
692 return data;
693 }
694
695 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
696 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
697 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
698 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
699 var octetstring data := f_IPv6_enc(ip6);
700 return data;
701 }
702
703 /* Wait for ICMPv4 from GTP */
704 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +0200705 var Gtp1uUnitdata ud;
706 T_default.start;
707 alt {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100708 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200709 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200710 setverdict(fail);
711 stop;
712 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100713 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
714 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
715 if (ip4.header.ver != 4) {
716 repeat;
717 }
718 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
719 if (not match(icmp4, expected)) {
720 repeat;
721 }
722 }
723 [] GTPU.receive { setverdict(fail); }
724 [] T_default.timeout { setverdict(fail); }
725 }
726 T_default.stop;
727 }
728
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100729 /* Wait for ICMPv4 echo request from GTP */
730 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
731 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
732 }
733
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100734 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
735 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
736 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
737 }
738
739 /* Wait for ICMPv6 from GTP */
740 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
741 var Gtp1uUnitdata ud;
742 T_default.start;
743 alt {
Harald Welte231b9412017-08-09 17:16:31 +0200744 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200745 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200746 setverdict(fail);
747 stop;
748 }
Harald Welte231b9412017-08-09 17:16:31 +0200749 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
750 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100751 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +0200752 repeat;
753 }
754 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100755 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +0200756 repeat;
757 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100758 /* We are waiting for RA, update ctx */
759 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
760 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
761 log("RA with /64 prefix ", ctx.ip6_prefix);
762 }
Harald Welte231b9412017-08-09 17:16:31 +0200763 }
764 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
765 [] GTPU.receive { setverdict(fail); }
766 [] T_default.timeout { setverdict(fail); }
767 }
768 T_default.stop;
769 }
770
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100771 /* wait for GGSN to send us an ICMPv6 router advertisement */
772 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
773 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
774 }
775
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100776 /* Wait for ICMPv6 echo request from GTP */
777 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
778 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
779 }
780
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100781 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
782 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
783 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
784 }
785
Oliver Smithee6a0882019-03-08 11:05:46 +0100786 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
787 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
788 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
789 return f_gen_icmpv6_router_solicitation(interface_id);
790 }
791
792 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
793 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
794 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
795 var OCT16 link_local := f_ipv6_link_local(interface_id);
796 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
797
798 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
799 }
800
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100801 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
802 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
803 T_default.start;
804 alt {
805 [] GTPU.receive { setverdict(fail); }
806 [] T_default.timeout { }
807 }
808 T_default.stop;
809 }
810
Harald Welte79737b42019-04-10 10:39:30 +0200811 /* list of protocols where we don't accept duplicates */
812 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
813 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
814 var integer i;
815 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
816 if (id == protocol_ids_nodupes[i]) {
817 return false;
818 }
819 }
820 return true;
821 }
822
823 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
824 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
825 var OCT2List protocol_ids := {};
826 var integer i, j;
827 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
828 var OCT2 id := pco.protocols[i].protocolID;
829 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
830 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
831 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
832 }
833 }
834 protocol_ids := protocol_ids & { id };
835 }
836 }
837
Harald Welte0ef285b2017-08-13 20:06:01 +0200838 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +0200839 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200840 f_init();
Harald Welte231b9412017-08-09 17:16:31 +0200841
Harald Welteed097432017-08-13 13:28:49 +0200842 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 +0200843 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +0200844 f_pdp_ctx_del(ctx, '1'B);
845 }
846
Harald Welte0ef285b2017-08-13 20:06:01 +0200847 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +0200848 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
849 f_init();
850
Harald Welteed097432017-08-13 13:28:49 +0200851 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 +0200852 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
853 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100854
Harald Welte79737b42019-04-10 10:39:30 +0200855 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100856 /* verify PCO contains both primary and secondary DNS */
857 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
858 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
859 setverdict(fail, "Primary DNS IPv6 PCO option not found");
860 }
861
862 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
863 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
864 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
865 }
866
Harald Welteed7a1772017-08-09 20:26:20 +0200867 f_pdp_ctx_del(ctx, '1'B);
868 }
869
Harald Welte0ef285b2017-08-13 20:06:01 +0200870 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +0200871 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
872 f_init();
873
Harald Welteed097432017-08-13 13:28:49 +0200874 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 +0200875 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
876 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200877
Harald Welte79737b42019-04-10 10:39:30 +0200878 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +0200879 //f_send_gtpu(ctx, c_router_solicit);
880 //f_send_gtpu(ctx, c_neigh_solicit);
881
882 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
883 f_wait_rtr_adv(ctx);
884 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
885
Harald Welte811651e2017-08-05 15:25:06 +0200886 f_pdp_ctx_del(ctx, '1'B);
Harald Welte94ade362017-08-04 00:36:55 +0200887 }
888
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100889 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
890 Test we can send ICMPv6 ping over GTPU to DNS server. */
891 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
892 f_init();
893 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
894 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
895 f_pdp_ctx_act(ctx);
896
897 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
898 f_wait_rtr_adv(ctx);
899 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
900
901 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
902
903 /* Check if we can use valid link-local src addr. */
904 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
905 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
906 f_wait_icmp6_echo_reply(ctx);
907
908 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
909 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
910 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
911 f_wait_gtpu_fail(ctx);
912
913 /* Check if we can use valid global src addr, should work */
914 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
915 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
916 f_wait_icmp6_echo_reply(ctx);
917
918 /* Assert that packets with wrong global src addr are dropped by GGSN */
919 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
920 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
921 f_wait_gtpu_fail(ctx);
922
923 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped) */
924 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
925 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
926 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
927 f_wait_gtpu_fail(ctx);
928
929 f_pdp_ctx_del(ctx, '1'B);
930 }
931
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100932 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
933 testcase TC_pdp6_clients_interact() runs on GT_CT {
934 f_init();
935 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
936 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
937 f_pdp_ctx_act(ctxA);
938 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
939 f_wait_rtr_adv(ctxA);
940 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
941
942 f_pdp_ctx_act(ctxB);
943 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
944 f_wait_rtr_adv(ctxB);
945 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
946
947 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
948 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
949 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
950 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
951
952 /* Validate if clients can interact using ll addr. */
953 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
954 f_wait_gtpu_fail(ctxB);
955
956 /* Validate if clients can interact using global addr. */
957 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
958 f_wait_gtpu_fail(ctxB);
959
960 f_pdp_ctx_del(ctxA, '1'B);
961 }
962
Harald Welte0ef285b2017-08-13 20:06:01 +0200963 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +0200964 testcase TC_pdp4_act_deact() runs on GT_CT {
965 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200966 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 +0200967 f_pdp_ctx_act(ctx);
968 f_pdp_ctx_del(ctx, '1'B);
969 }
970
Harald Welte0ef285b2017-08-13 20:06:01 +0200971 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +0200972 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
973 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100974 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
975 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +0200976 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 +0200977 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +0200978 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +0200979 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +0100980 /* verify IPCP is at all contained */
981 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
982 setverdict(fail, "IPCP not found in PCO");
983 }
984 /* verify IPCP contains both primary and secondary DNS */
985 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100986 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
987 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
988 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
989 } else {
990 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
991 }
Harald Welte71a36022017-12-04 18:55:58 +0100992 }
Harald Welteed7a1772017-08-09 20:26:20 +0200993 f_pdp_ctx_del(ctx, '1'B);
994 }
995
Harald Weltef8298542019-04-10 10:15:28 +0200996 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
997 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
998 f_init();
999 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1000 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1001 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1002 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1003 f_pdp_ctx_act(ctx);
1004 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1005 /* verify IPCP is at all contained */
1006 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1007 setverdict(fail, "IPCP not found in PCO");
1008 }
1009 /* verify IPCP contains both primary and secondary DNS */
1010 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1011 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1012 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1013 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1014 } else {
1015 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1016 }
1017 }
1018 /* verify that PAP is contained */
1019 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1020 setverdict(fail, "PAP not found in PCO");
1021 }
1022 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1023 if (not match(pap, tr_PAP_AuthAck)) {
1024 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1025 }
1026 f_pdp_ctx_del(ctx, '1'B);
1027 }
1028
Harald Welte0ef285b2017-08-13 20:06:01 +02001029 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001030 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1031 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001032 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 +02001033 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001034 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001035
Harald Welte79737b42019-04-10 10:39:30 +02001036 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001037 /* verify PCO contains both primary and secondary DNS */
1038 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1039 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1040 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1041 }
1042
1043 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1044 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1045 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1046 }
1047
Harald Welteed7a1772017-08-09 20:26:20 +02001048 f_pdp_ctx_del(ctx, '1'B);
1049 }
1050
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001051 /* Test PDP context activation for dynamic IPv4 EUA.
1052 Test we can send ICMPv6 ping over GTPU to DNS server. */
1053 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1054 f_init();
1055 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1056 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1057 f_pdp_ctx_act(ctx);
1058
Harald Welte79737b42019-04-10 10:39:30 +02001059 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001060 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1061
1062 /* Check if we can use valid global src addr, should work */
1063 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1064 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1065 f_wait_icmp4_echo_reply(ctx);
1066
1067 /* Assert that packets with wrong global src addr are dropped by GGSN */
1068 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1069 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1070 f_wait_gtpu_fail(ctx);
1071
1072 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1073 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1074 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1075 f_wait_gtpu_fail(ctx);
1076 f_pdp_ctx_del(ctx, '1'B);
1077 }
1078
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001079 /* Helper function for tests below. */
1080 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001081 f_init();
1082 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1083 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1084 f_pdp_ctx_act(ctxA);
1085 f_pdp_ctx_act(ctxB);
1086 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1087 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1088 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1089 f_wait_icmp4_echo_request(ctxB);
1090
1091 f_pdp_ctx_del(ctxA, '1'B);
1092 }
1093
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001094 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1095 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001096 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001097 f_pdp4_clients_interact();
1098 }
1099
1100 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1101 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001102 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001103 f_pdp4_clients_interact();
1104 }
1105
Harald Weltedca80052017-08-13 20:01:38 +02001106 testcase TC_echo_req_resp() runs on GT_CT {
1107 f_init();
1108 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1109 T_default.start;
1110 alt {
1111 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1112 [] GTPC.receive { repeat; };
1113 [] T_default.timeout { setverdict(fail); }
1114 }
1115 T_default.stop;
1116 }
1117
Philipp Maier33e52612018-05-30 17:22:02 +02001118 /* Test if the parser can cope with PCO that only contain either a
1119 * single primary DNS or a secondary DNS. */
1120 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1121
1122 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1123 * the test is executed.
1124 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1125
1126 f_init();
1127 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1128 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1129 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1130 var octetstring pco_neg_dns;
1131 var octetstring pco_neg_dns_expected;
1132
1133 /* PCO with primary DNS only */
1134 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1135 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001136 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001137 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1138 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1139 /* Note: The prepended hex bytes encode the following information:
1140 * 0x02 = Configuration ACK
1141 * 0x00 = Identifier
1142 * 0x000a = Length
1143 * 0x81 = Type (Primary DNS Server Address)
1144 * 0x06 = Length
1145 * (4 byte IP-Address appended) */
1146 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1147 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1148 }
1149 f_pdp_ctx_del(ctx, '1'B);
1150
1151 /* PCO with secondary DNS only */
1152 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1153 f_pdp_ctx_act(ctx);
1154 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1155 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1156 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1157 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1158 }
1159 f_pdp_ctx_del(ctx, '1'B);
1160 }
1161
1162 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1163 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1164 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1165 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1166
1167 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1168 * the test is executed.
1169 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1170
1171 f_init();
1172 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1173 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1174 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1175 var octetstring pco_neg_dns;
1176 var octetstring pco_neg_dns_expected;
1177
1178 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1179 f_pdp_ctx_act(ctx);
1180
1181 /* Check if primary DNS is contained */
1182 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1183 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1184 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1185 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1186 }
Philipp Maier33e52612018-05-30 17:22:02 +02001187
1188 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001189 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1190 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001191 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1192 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1193 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1194 }
1195 f_pdp_ctx_del(ctx, '1'B);
1196 }
1197
Oliver Smithee6a0882019-03-08 11:05:46 +01001198 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1199 testcase TC_pdp46_act_deact() runs on GT_CT {
1200 f_init();
1201 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1202 f_pdp_ctx_act(ctx);
1203 f_pdp_ctx_del(ctx, '1'B);
1204 }
1205
1206 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1207 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1208 f_init();
1209 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1210 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1211 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1212 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1213 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001214 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001215 /* verify IPCP is at all contained */
1216 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1217 setverdict(fail, "IPCP not found in PCO");
1218 }
Harald Welte79737b42019-04-10 10:39:30 +02001219 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001220 /* verify IPCP contains both primary and secondary IPv4 DNS */
1221 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1222 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1223 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1224 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1225 } else {
1226 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1227 }
1228 }
1229 f_pdp_ctx_del(ctx, '1'B);
1230 }
1231
1232 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1233 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1234 f_init();
1235 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1236 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1237 f_pdp_ctx_act(ctx);
1238
1239 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1240 f_wait_rtr_adv(ctx);
1241 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1242
1243 f_pdp_ctx_del(ctx, '1'B);
1244 }
1245
1246 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1247 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1248 f_init();
1249
1250 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1251 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1252 f_pdp_ctx_act(ctx);
1253
Harald Welte79737b42019-04-10 10:39:30 +02001254 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001255 /* verify PCO contains both primary and secondary IPv4 DNS */
1256 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1257 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1258 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1259 }
1260
1261 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1262 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1263 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1264 }
1265
1266 f_pdp_ctx_del(ctx, '1'B);
1267 }
1268
1269 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1270 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1271 f_init();
1272
1273 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1274 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1275 f_pdp_ctx_act(ctx);
1276
Harald Welte79737b42019-04-10 10:39:30 +02001277 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001278 /* verify PCO contains both primary and secondary IPv6 DNS */
1279 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1280 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1281 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1282 }
1283
1284 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1285 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1286 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1287 }
1288
1289 f_pdp_ctx_del(ctx, '1'B);
1290 }
1291
1292 /* Test PDP context activation for dynamic IPv4v6 EUA.
1293 Test we can send ICMPv6 ping over GTPU to DNS server. */
1294 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1295 f_init();
1296 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1297 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1298 f_pdp_ctx_act(ctx);
1299
1300 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1301
1302 /* Check if we can use valid global src addr, should work */
1303 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1304 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1305 f_wait_icmp4_echo_reply(ctx);
1306
1307 /* Assert that packets with wrong global src addr are dropped by GGSN */
1308 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1309 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1310 f_wait_gtpu_fail(ctx);
1311
1312 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1313 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1314 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1315 f_wait_gtpu_fail(ctx);
1316 f_pdp_ctx_del(ctx, '1'B);
1317 }
1318
1319 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1320 testcase TC_pdp46_clients_interact() runs on GT_CT {
1321 f_init();
1322 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1323 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1324 f_pdp_ctx_act(ctxA);
1325 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1326 f_wait_rtr_adv(ctxA);
1327 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1328
1329 f_pdp_ctx_act(ctxB);
1330 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1331 f_wait_rtr_adv(ctxB);
1332 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1333
1334 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1335 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1336 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1337 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1338
1339 /* Validate if clients can interact using ll addr. */
1340 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1341 f_wait_gtpu_fail(ctxB);
1342
1343 /* Validate if clients can interact using global addr. */
1344 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1345 f_wait_gtpu_fail(ctxB);
1346
1347 f_pdp_ctx_del(ctxA, '1'B);
1348 }
1349
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001350 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
1351 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
1352 f_init();
1353 /* A typical MS first attempts v4v6, and if rejected, then tries v4 and v6 separetly */
1354 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
1355 f_pdp_ctx_act(ctx46, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1356
1357 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1358 f_pdp_ctx_act(ctx4, '80'O); /* Normal accept cause */
1359
1360 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv6Dyn)));
1361 f_pdp_ctx_act(ctx6, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1362
1363 f_pdp_ctx_del(ctx4, '1'B);
1364 }
1365
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001366 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
1367 testcase TC_pdp_act2_recovery() runs on GT_CT {
1368 var Gtp1cUnitdata ud;
1369 var default d;
1370 var boolean ctxA_deleted := false;
1371 var boolean ctxB_created := false;
1372
1373 f_init();
1374 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1375 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1376 f_pdp_ctx_act(ctxA);
1377
1378 g_restart_ctr := int2oct(oct2int(g_restart_ctr) + 1, 1);
1379
1380 log("sending 2nd CreatePDP (recovery increased)");
1381 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
1382 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
1383 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
1384 T_default.start;
1385 d := activate(pingpong());
1386 alt {
1387 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
1388 f_handle_create_req(ctxB, ud);
1389 if (not ctxB_created) {
1390 ctxB_created := true;
1391 setverdict(pass);
1392 } else {
1393 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
1394 }
1395
1396 if (not ctxA_deleted) {
1397 repeat;
1398 }
1399 }
1400 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
1401 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
1402 setverdict(pass);
1403 } else {
1404 setverdict(fail);
1405 }
1406
1407 if (not ctxA_deleted) {
1408 ctxA_deleted := true;
1409 setverdict(pass);
1410 } else {
1411 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
1412 }
1413
1414 if (not ctxB_created) {
1415 repeat;
1416 }
1417 }
1418 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
1419 setverdict(fail, "GGSN dropping still valid pdp ctx");
1420 }
1421 }
1422 deactivate(d);
1423 T_default.stop;
1424
1425 f_pdp_ctx_del(ctxB, '1'B);
1426 }
1427
1428
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001429 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent
1430 responses (60 seconds): If same delete req is sent and duplicate is
1431 detected, saved duplicate response should be sent back. */
1432 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
1433 f_init();
1434 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1435 f_pdp_ctx_act(ctx);
1436 f_pdp_ctx_del(ctx, '1'B);
1437 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
1438 f_sleep(1.0);
1439 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
1440 duplicate. If it was not a duplicate, osmo-ggsn would answer
1441 with a failure since that PDP ctx was already deleted. */
1442 g_c_seq_nr := g_c_seq_nr - 1;
1443 f_pdp_ctx_del(ctx, '1'B);
1444
1445 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
1446 var OCT1 cause_nonexistent := 'C0'O;
1447 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent);
1448 }
1449
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001450 /* Activate PDP context + trigger Recovery procedure through EchoResp */
1451 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
1452 var Gtp1cUnitdata ud;
1453 g_use_echo := true;
1454 f_init();
1455 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1456 f_pdp_ctx_act(ctx);
1457
1458 /* Wait to receive echo request and send initial Restart counter */
1459 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1460 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1461 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1462 };
1463
1464 /* Wait to receive second echo request and send incremented Restart
1465 counter. This will fake a restarted SGSN, and pdp ctx allocated
1466 should be released by GGSN */
1467 g_restart_ctr := int2oct(oct2int(g_restart_ctr) + 1, 1);
1468 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1469 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1470 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1471 };
1472 f_pdp_ctx_exp_del_req(ctx, omit, true);
1473 setverdict(pass);
1474 }
1475
Harald Welte94ade362017-08-04 00:36:55 +02001476 control {
Harald Welteed7a1772017-08-09 20:26:20 +02001477 execute(TC_pdp4_act_deact());
1478 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02001479 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02001480 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001481 execute(TC_pdp4_act_deact_gtpu_access());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001482 execute(TC_pdp4_clients_interact_with_txseq());
1483 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02001484 execute(TC_pdp4_act_deact_with_single_dns());
1485 execute(TC_pdp4_act_deact_with_separate_dns());
Harald Welteed7a1772017-08-09 20:26:20 +02001486
1487 execute(TC_pdp6_act_deact());
1488 execute(TC_pdp6_act_deact_pcodns());
1489 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001490 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001491 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02001492
Oliver Smithee6a0882019-03-08 11:05:46 +01001493 execute(TC_pdp46_act_deact());
1494 execute(TC_pdp46_act_deact_ipcp());
1495 execute(TC_pdp46_act_deact_icmp6());
1496 execute(TC_pdp46_act_deact_pcodns4());
1497 execute(TC_pdp46_act_deact_pcodns6());
1498 execute(TC_pdp46_act_deact_gtpu_access());
1499 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001500 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01001501
Harald Weltedca80052017-08-13 20:01:38 +02001502 execute(TC_echo_req_resp());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001503 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001504 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001505
1506 if (m_ggsn_supports_echo_interval) {
1507 execute(TC_pdp_act_restart_ctr_echo());
1508 }
Harald Welte94ade362017-08-04 00:36:55 +02001509 }
Harald Welte379d45a2017-08-03 09:55:15 +02001510}