blob: 44dba4afd12b524e47800ceb9a55c7681ab681b5 [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);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +0200961 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100962 }
963
Harald Welte0ef285b2017-08-13 20:06:01 +0200964 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +0200965 testcase TC_pdp4_act_deact() runs on GT_CT {
966 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200967 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 +0200968 f_pdp_ctx_act(ctx);
969 f_pdp_ctx_del(ctx, '1'B);
970 }
971
Harald Welte0ef285b2017-08-13 20:06:01 +0200972 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +0200973 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
974 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100975 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
976 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +0200977 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 +0200978 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +0200979 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +0200980 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +0100981 /* verify IPCP is at all contained */
982 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
983 setverdict(fail, "IPCP not found in PCO");
984 }
985 /* verify IPCP contains both primary and secondary DNS */
986 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100987 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
988 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
989 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
990 } else {
991 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
992 }
Harald Welte71a36022017-12-04 18:55:58 +0100993 }
Harald Welteed7a1772017-08-09 20:26:20 +0200994 f_pdp_ctx_del(ctx, '1'B);
995 }
996
Harald Weltef8298542019-04-10 10:15:28 +0200997 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
998 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
999 f_init();
1000 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1001 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1002 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1003 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1004 f_pdp_ctx_act(ctx);
1005 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1006 /* verify IPCP is at all contained */
1007 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1008 setverdict(fail, "IPCP not found in PCO");
1009 }
1010 /* verify IPCP contains both primary and secondary DNS */
1011 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1012 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1013 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1014 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1015 } else {
1016 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1017 }
1018 }
1019 /* verify that PAP is contained */
1020 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1021 setverdict(fail, "PAP not found in PCO");
1022 }
1023 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1024 if (not match(pap, tr_PAP_AuthAck)) {
1025 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1026 }
1027 f_pdp_ctx_del(ctx, '1'B);
1028 }
1029
Harald Welte0ef285b2017-08-13 20:06:01 +02001030 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001031 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1032 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001033 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 +02001034 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001035 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001036
Harald Welte79737b42019-04-10 10:39:30 +02001037 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001038 /* verify PCO contains both primary and secondary DNS */
1039 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1040 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1041 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1042 }
1043
1044 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1045 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1046 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1047 }
1048
Harald Welteed7a1772017-08-09 20:26:20 +02001049 f_pdp_ctx_del(ctx, '1'B);
1050 }
1051
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001052 /* Test PDP context activation for dynamic IPv4 EUA.
1053 Test we can send ICMPv6 ping over GTPU to DNS server. */
1054 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1055 f_init();
1056 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1057 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1058 f_pdp_ctx_act(ctx);
1059
Harald Welte79737b42019-04-10 10:39:30 +02001060 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001061 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1062
1063 /* Check if we can use valid global src addr, should work */
1064 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1065 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1066 f_wait_icmp4_echo_reply(ctx);
1067
1068 /* Assert that packets with wrong global src addr are dropped by GGSN */
1069 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1070 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1071 f_wait_gtpu_fail(ctx);
1072
1073 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1074 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1075 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1076 f_wait_gtpu_fail(ctx);
1077 f_pdp_ctx_del(ctx, '1'B);
1078 }
1079
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001080 /* Helper function for tests below. */
1081 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001082 f_init();
1083 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1084 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1085 f_pdp_ctx_act(ctxA);
1086 f_pdp_ctx_act(ctxB);
1087 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1088 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1089 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1090 f_wait_icmp4_echo_request(ctxB);
1091
1092 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001093 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001094 }
1095
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001096 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1097 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001098 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001099 f_pdp4_clients_interact();
1100 }
1101
1102 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1103 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001104 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001105 f_pdp4_clients_interact();
1106 }
1107
Harald Weltedca80052017-08-13 20:01:38 +02001108 testcase TC_echo_req_resp() runs on GT_CT {
1109 f_init();
1110 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1111 T_default.start;
1112 alt {
1113 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1114 [] GTPC.receive { repeat; };
1115 [] T_default.timeout { setverdict(fail); }
1116 }
1117 T_default.stop;
1118 }
1119
Philipp Maier33e52612018-05-30 17:22:02 +02001120 /* Test if the parser can cope with PCO that only contain either a
1121 * single primary DNS or a secondary DNS. */
1122 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1123
1124 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1125 * the test is executed.
1126 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1127
1128 f_init();
1129 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1130 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1131 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1132 var octetstring pco_neg_dns;
1133 var octetstring pco_neg_dns_expected;
1134
1135 /* PCO with primary DNS only */
1136 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1137 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001138 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001139 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1140 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1141 /* Note: The prepended hex bytes encode the following information:
1142 * 0x02 = Configuration ACK
1143 * 0x00 = Identifier
1144 * 0x000a = Length
1145 * 0x81 = Type (Primary DNS Server Address)
1146 * 0x06 = Length
1147 * (4 byte IP-Address appended) */
1148 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1149 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1150 }
1151 f_pdp_ctx_del(ctx, '1'B);
1152
1153 /* PCO with secondary DNS only */
1154 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1155 f_pdp_ctx_act(ctx);
1156 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1157 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1158 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1159 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1160 }
1161 f_pdp_ctx_del(ctx, '1'B);
1162 }
1163
1164 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1165 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1166 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1167 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1168
1169 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1170 * the test is executed.
1171 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1172
1173 f_init();
1174 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1175 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1176 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1177 var octetstring pco_neg_dns;
1178 var octetstring pco_neg_dns_expected;
1179
1180 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1181 f_pdp_ctx_act(ctx);
1182
1183 /* Check if primary DNS is contained */
1184 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1185 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1186 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1187 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1188 }
Philipp Maier33e52612018-05-30 17:22:02 +02001189
1190 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001191 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1192 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001193 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1194 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1195 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1196 }
1197 f_pdp_ctx_del(ctx, '1'B);
1198 }
1199
Oliver Smithee6a0882019-03-08 11:05:46 +01001200 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1201 testcase TC_pdp46_act_deact() runs on GT_CT {
1202 f_init();
1203 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1204 f_pdp_ctx_act(ctx);
1205 f_pdp_ctx_del(ctx, '1'B);
1206 }
1207
1208 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1209 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1210 f_init();
1211 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1212 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1213 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1214 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1215 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001216 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001217 /* verify IPCP is at all contained */
1218 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1219 setverdict(fail, "IPCP not found in PCO");
1220 }
Harald Welte79737b42019-04-10 10:39:30 +02001221 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001222 /* verify IPCP contains both primary and secondary IPv4 DNS */
1223 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1224 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1225 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1226 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1227 } else {
1228 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1229 }
1230 }
1231 f_pdp_ctx_del(ctx, '1'B);
1232 }
1233
1234 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1235 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1236 f_init();
1237 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1238 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1239 f_pdp_ctx_act(ctx);
1240
1241 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1242 f_wait_rtr_adv(ctx);
1243 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1244
1245 f_pdp_ctx_del(ctx, '1'B);
1246 }
1247
1248 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1249 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1250 f_init();
1251
1252 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1253 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1254 f_pdp_ctx_act(ctx);
1255
Harald Welte79737b42019-04-10 10:39:30 +02001256 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001257 /* verify PCO contains both primary and secondary IPv4 DNS */
1258 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1259 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1260 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1261 }
1262
1263 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1264 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1265 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1266 }
1267
1268 f_pdp_ctx_del(ctx, '1'B);
1269 }
1270
1271 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1272 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1273 f_init();
1274
1275 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1276 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1277 f_pdp_ctx_act(ctx);
1278
Harald Welte79737b42019-04-10 10:39:30 +02001279 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001280 /* verify PCO contains both primary and secondary IPv6 DNS */
1281 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1282 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1283 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1284 }
1285
1286 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1287 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1288 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1289 }
1290
1291 f_pdp_ctx_del(ctx, '1'B);
1292 }
1293
1294 /* Test PDP context activation for dynamic IPv4v6 EUA.
1295 Test we can send ICMPv6 ping over GTPU to DNS server. */
1296 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1297 f_init();
1298 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1299 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1300 f_pdp_ctx_act(ctx);
1301
1302 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1303
1304 /* Check if we can use valid global src addr, should work */
1305 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1306 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1307 f_wait_icmp4_echo_reply(ctx);
1308
1309 /* Assert that packets with wrong global src addr are dropped by GGSN */
1310 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1311 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1312 f_wait_gtpu_fail(ctx);
1313
1314 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1315 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1316 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1317 f_wait_gtpu_fail(ctx);
1318 f_pdp_ctx_del(ctx, '1'B);
1319 }
1320
1321 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1322 testcase TC_pdp46_clients_interact() runs on GT_CT {
1323 f_init();
1324 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1325 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1326 f_pdp_ctx_act(ctxA);
1327 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1328 f_wait_rtr_adv(ctxA);
1329 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1330
1331 f_pdp_ctx_act(ctxB);
1332 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1333 f_wait_rtr_adv(ctxB);
1334 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1335
1336 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1337 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1338 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1339 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1340
1341 /* Validate if clients can interact using ll addr. */
1342 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1343 f_wait_gtpu_fail(ctxB);
1344
1345 /* Validate if clients can interact using global addr. */
1346 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1347 f_wait_gtpu_fail(ctxB);
1348
1349 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001350 f_pdp_ctx_del(ctxB, '1'B);
Oliver Smithee6a0882019-03-08 11:05:46 +01001351 }
1352
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001353 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
1354 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
1355 f_init();
1356 /* A typical MS first attempts v4v6, and if rejected, then tries v4 and v6 separetly */
1357 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
1358 f_pdp_ctx_act(ctx46, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1359
1360 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1361 f_pdp_ctx_act(ctx4, '80'O); /* Normal accept cause */
1362
1363 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv6Dyn)));
1364 f_pdp_ctx_act(ctx6, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1365
1366 f_pdp_ctx_del(ctx4, '1'B);
1367 }
1368
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001369 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
1370 testcase TC_pdp_act2_recovery() runs on GT_CT {
1371 var Gtp1cUnitdata ud;
1372 var default d;
1373 var boolean ctxA_deleted := false;
1374 var boolean ctxB_created := false;
1375
1376 f_init();
1377 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1378 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1379 f_pdp_ctx_act(ctxA);
1380
1381 g_restart_ctr := int2oct(oct2int(g_restart_ctr) + 1, 1);
1382
1383 log("sending 2nd CreatePDP (recovery increased)");
1384 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
1385 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
1386 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
1387 T_default.start;
1388 d := activate(pingpong());
1389 alt {
1390 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
1391 f_handle_create_req(ctxB, ud);
1392 if (not ctxB_created) {
1393 ctxB_created := true;
1394 setverdict(pass);
1395 } else {
1396 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
1397 }
1398
1399 if (not ctxA_deleted) {
1400 repeat;
1401 }
1402 }
1403 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
1404 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
1405 setverdict(pass);
1406 } else {
1407 setverdict(fail);
1408 }
1409
1410 if (not ctxA_deleted) {
1411 ctxA_deleted := true;
1412 setverdict(pass);
1413 } else {
1414 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
1415 }
1416
1417 if (not ctxB_created) {
1418 repeat;
1419 }
1420 }
1421 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
1422 setverdict(fail, "GGSN dropping still valid pdp ctx");
1423 }
1424 }
1425 deactivate(d);
1426 T_default.stop;
1427
1428 f_pdp_ctx_del(ctxB, '1'B);
1429 }
1430
1431
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001432 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent
1433 responses (60 seconds): If same delete req is sent and duplicate is
1434 detected, saved duplicate response should be sent back. */
1435 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
1436 f_init();
1437 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1438 f_pdp_ctx_act(ctx);
1439 f_pdp_ctx_del(ctx, '1'B);
1440 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
1441 f_sleep(1.0);
1442 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
1443 duplicate. If it was not a duplicate, osmo-ggsn would answer
1444 with a failure since that PDP ctx was already deleted. */
1445 g_c_seq_nr := g_c_seq_nr - 1;
1446 f_pdp_ctx_del(ctx, '1'B);
1447
1448 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
1449 var OCT1 cause_nonexistent := 'C0'O;
1450 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent);
1451 }
1452
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001453 /* Activate PDP context + trigger Recovery procedure through EchoResp */
1454 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
1455 var Gtp1cUnitdata ud;
1456 g_use_echo := true;
1457 f_init();
1458 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1459 f_pdp_ctx_act(ctx);
1460
1461 /* Wait to receive echo request and send initial Restart counter */
1462 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1463 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1464 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1465 };
1466
1467 /* Wait to receive second echo request and send incremented Restart
1468 counter. This will fake a restarted SGSN, and pdp ctx allocated
1469 should be released by GGSN */
1470 g_restart_ctr := int2oct(oct2int(g_restart_ctr) + 1, 1);
1471 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1472 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1473 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1474 };
1475 f_pdp_ctx_exp_del_req(ctx, omit, true);
1476 setverdict(pass);
1477 }
1478
Harald Welte94ade362017-08-04 00:36:55 +02001479 control {
Harald Welteed7a1772017-08-09 20:26:20 +02001480 execute(TC_pdp4_act_deact());
1481 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02001482 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02001483 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001484 execute(TC_pdp4_act_deact_gtpu_access());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001485 execute(TC_pdp4_clients_interact_with_txseq());
1486 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02001487 execute(TC_pdp4_act_deact_with_single_dns());
1488 execute(TC_pdp4_act_deact_with_separate_dns());
Harald Welteed7a1772017-08-09 20:26:20 +02001489
1490 execute(TC_pdp6_act_deact());
1491 execute(TC_pdp6_act_deact_pcodns());
1492 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001493 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001494 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02001495
Oliver Smithee6a0882019-03-08 11:05:46 +01001496 execute(TC_pdp46_act_deact());
1497 execute(TC_pdp46_act_deact_ipcp());
1498 execute(TC_pdp46_act_deact_icmp6());
1499 execute(TC_pdp46_act_deact_pcodns4());
1500 execute(TC_pdp46_act_deact_pcodns6());
1501 execute(TC_pdp46_act_deact_gtpu_access());
1502 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001503 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01001504
Harald Weltedca80052017-08-13 20:01:38 +02001505 execute(TC_echo_req_resp());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001506 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001507 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001508
1509 if (m_ggsn_supports_echo_interval) {
1510 execute(TC_pdp_act_restart_ctr_echo());
1511 }
Harald Welte94ade362017-08-04 00:36:55 +02001512 }
Harald Welte379d45a2017-08-03 09:55:15 +02001513}