blob: be0e565f224b31c5fe36178b1084320591f7818a [file] [log] [blame]
Harald Welte379d45a2017-08-03 09:55:15 +02001module GGSN_Tests {
2
Harald Welte34b5a952019-05-27 11:54:11 +02003/* GGSN test suite in TTCN-3
4 * (C) 2017-2019 Harald Welte <laforge@gnumonks.org>
5 * (C) 2018-2019 sysmocom - s.f.m.c. GmbH
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
14
Harald Welte94ade362017-08-04 00:36:55 +020015 import from General_Types all;
Harald Welte811651e2017-08-05 15:25:06 +020016 import from Osmocom_Types all;
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +010017 import from Misc_Helpers all;
Harald Welte94ade362017-08-04 00:36:55 +020018 import from IPL4asp_PortType all;
19 import from IPL4asp_Types all;
20 import from GTP_CodecPort all;
21 import from GTP_CodecPort_CtrlFunct all;
Harald Weltec69cf4e2018-02-17 20:57:02 +010022 import from GTP_Templates all;
Harald Welte94ade362017-08-04 00:36:55 +020023 import from GTPC_Types all;
24 import from GTPU_Types all;
Harald Welte71a36022017-12-04 18:55:58 +010025 import from IPCP_Types all;
Harald Weltef8298542019-04-10 10:15:28 +020026 import from PAP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020027 import from IP_Types all;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +010028 import from ICMP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020029 import from ICMPv6_Types all;
Harald Welteddeecbb2017-08-18 22:53:30 +020030 import from Native_Functions all;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +020031 import from Osmocom_VTY_Functions all;
32 import from TELNETasp_PortType all;
Harald Welte94ade362017-08-04 00:36:55 +020033
34 const integer GTP0_PORT := 3386;
35 const integer GTP1C_PORT := 2123;
36 const integer GTP1U_PORT := 2152;
Harald Welteddeecbb2017-08-18 22:53:30 +020037
38 modulepar {
Stefan Sperlingcb782b92018-04-03 16:03:15 +020039 /* Default IP addresses. May be overridden by GGSN_Tests configuration files. */
40
41 /* The SGSN simulated by TTCN3 will bind to these addresses for GTP control and GTP user planes. */
Harald Welteddeecbb2017-08-18 22:53:30 +020042 charstring m_bind_ip_gtpc := "127.23.42.1";
43 charstring m_bind_ip_gtpu := "127.23.42.1";
44
Stefan Sperlingcb782b92018-04-03 16:03:15 +020045 /* Addresses the GGSN which is being tested is listening on for SGSN connections. */
Harald Welteddeecbb2017-08-18 22:53:30 +020046 charstring m_ggsn_ip_gtpc := "127.0.0.6";
47 charstring m_ggsn_ip_gtpu := "127.0.0.6";
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010048
Stefan Sperlingcb782b92018-04-03 16:03:15 +020049 /*
50 * Our tests expect to see these DNS servers in 'Create PDP context responses' sent by the GGSN.
51 * These addresses must therefore match 'ip[v6] dns' options configured in osmo-ggsn.conf.
52 *
53 * These addresses are not expected to serve actual DNS requests. However, tests may expect to be
54 * able to ping these addresses (currently, IPv4 addresses must respond with an ICMP 'echo reply',
55 * and IPv6 addresses may respond with either ICMPv6 'echo reply' or 'destination unreachable').
56 */
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010057 charstring m_ggsn_ip4_dns1 := "192.168.100.1"
58 charstring m_ggsn_ip4_dns2 := "8.8.8.8"
Pau Espin Pedrol363ba482018-01-29 18:42:00 +010059 charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888"
60 charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844"
Stefan Sperlingcb782b92018-04-03 16:03:15 +020061
62 /*
63 * Additional address ranges are defined in osmo-ggsn.conf from which addresses are assigned
64 * to MS "behind" the simulated SGSN. These addresses appear on tun devices used by osmo-ggsn.
65 * The tests expect to be able to send ping packets between any two simulated MS within the same
66 * address range. This requires IP forwarding to be enabled on the corresponding tun interfaces.
67 */
Harald Welteddeecbb2017-08-18 22:53:30 +020068 }
Harald Welte94ade362017-08-04 00:36:55 +020069
Harald Welte811651e2017-08-05 15:25:06 +020070 type set PdpContext {
71 hexstring imsi,
72 octetstring msisdn optional,
73 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020074 ProtConfigOptions pco_req optional,
75 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020076 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020077 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020078 BIT4 nsapi,
79 /* TEI (Data) local side */
80 OCT4 teid,
81 /* TEI (Control) local side */
82 OCT4 teic,
83 /* TEI (Data) remote side */
84 OCT4 teid_remote,
85 /* TEI (Control) remote side */
Harald Welte5438b9d2017-08-13 13:27:48 +020086 OCT4 teic_remote
Harald Welte811651e2017-08-05 15:25:06 +020087 }
88
Harald Welte94ade362017-08-04 00:36:55 +020089 type component GT_CT {
90 port GTPC_PT GTPC;
91 port GTPU_PT GTPU;
92
Harald Welte0be142b2017-08-13 13:28:10 +020093 var boolean g_initialized := false;
94
Harald Welte94ade362017-08-04 00:36:55 +020095 var OCT1 g_restart_ctr := '01'O;
96 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +020097 var OCT4 g_sgsn_ip_c;
98 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +020099 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200100 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
101 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200102 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200103
104 /* next to-be-sent GTP-C sequence number */
105 var uint16_t g_c_seq_nr;
106 /* next to-be-sent GTP-U sequence number */
107 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200108
109 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200110 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200111 var boolean g_use_echo := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200112 }
113
114 private function f_init_vty() runs on GT_CT {
115 map(self:GGSNVTY, system:GGSNVTY);
116 f_vty_set_prompts(GGSNVTY);
117 f_vty_transceive(GGSNVTY, "enable");
118 }
119
120 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
121 f_vty_enter_config(GGSNVTY);
122 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200123
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200124 f_vty_transceive(GGSNVTY, "apn internet");
125 if (enable) {
126 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
127 } else {
128 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
129 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200130 f_vty_transceive(GGSNVTY, "exit");
131
132 f_vty_transceive(GGSNVTY, "apn inet6");
133 if (enable) {
134 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
135 } else {
136 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
137 }
138 f_vty_transceive(GGSNVTY, "exit");
139
140 f_vty_transceive(GGSNVTY, "apn inet46");
141 if (enable) {
142 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
143 } else {
144 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
145 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200146 f_vty_transceive(GGSNVTY, "end");
147 }
148
149 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
150 if (expect_gptu_txseq) {
151 if (gtpu.s_bit != '1'B) {
152 log("GTPU sequence number expected but not present")
153 return false;
154 }
155 } else {
156 if (gtpu.s_bit != '0'B) {
157 log("GTPU sequence number not expected but present")
158 return false;
159 }
160 }
161 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200162 }
163
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200164 private function f_vty_enable_echo_interval(boolean enable) runs on GT_CT {
165 f_vty_enter_config(GGSNVTY);
166 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
167 if (enable) {
168 f_vty_transceive(GGSNVTY, "echo-interval 5");
169 } else {
170 f_vty_transceive(GGSNVTY, "no echo-interval");
171 }
172 f_vty_transceive(GGSNVTY, "end");
173 }
174
Harald Welte94ade362017-08-04 00:36:55 +0200175 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200176 if (g_initialized == true) {
177 return;
178 }
179 g_initialized := true;
180
Harald Welteddeecbb2017-08-18 22:53:30 +0200181 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
182 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
183
Harald Welte94ade362017-08-04 00:36:55 +0200184 var Result res;
185 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +0200186 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200187 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200188 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200189
190 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +0200191 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200192 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200193
194 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200195 g_c_seq_nr := f_rnd_int(65535);
196 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200197
198 f_init_vty();
Harald Welte3e0b0392018-04-26 09:46:21 +0200199 f_vty_set_gpdu_txseq(use_gtpu_txseq);
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +0100200 f_vty_enable_echo_interval(g_use_echo);
Harald Welte94ade362017-08-04 00:36:55 +0200201 }
202
Harald Welte94ade362017-08-04 00:36:55 +0200203 /* Altstep implementing responses to any incoming echo requests */
204 altstep pingpong() runs on GT_CT {
205 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200206 var Gtp1uUnitdata udu;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200207 [g_use_echo] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200208 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200209 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200210 repeat;
211 };
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200212 [not g_use_echo] GTPC.receive(tr_GTPC_PING(?)) {
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100213 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
214 "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200215 };
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100216 [] T_default.timeout {
217 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
218 "pinpong T_default timeout");
219 };
Harald Welte94ade362017-08-04 00:36:55 +0200220 }
221
Harald Welte811651e2017-08-05 15:25:06 +0200222 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200223 const octetstring c_ApnInternet := '08696E7465726E6574'O;
224 const octetstring c_ApnInet6 := '05696E657436'O;
225 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200226
Harald Welte811651e2017-08-05 15:25:06 +0200227 /* return random NSAPI */
228 function f_rnd_nsapi() return BIT4 {
229 return int2bit(f_rnd_int(16), 4);
230 }
231
232 /* return random TEI[DC] */
233 function f_rnd_tei() return OCT4 {
234 return int2oct(f_rnd_int(4294967296), 4);
235 }
236
237 /* define an (internal) representation of a PDP context */
238 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
239 EndUserAddress eua) := {
240 imsi := imsi,
241 msisdn := msisdn,
242 nsapi := f_rnd_nsapi(),
243 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200244 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200245 eua := eua,
246 teid := f_rnd_tei(),
Harald Welte5438b9d2017-08-13 13:27:48 +0200247 teic := f_rnd_tei()
Harald Welte811651e2017-08-05 15:25:06 +0200248 }
249
250 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200251 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200252 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200253 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200254 }
255
256 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200257 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200258 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200259 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
260 g_d_seq_nr := g_d_seq_nr + 1;
261 } else {
262 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
263 }
Harald Welte811651e2017-08-05 15:25:06 +0200264 }
265
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200266 function f_handle_create_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
267 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
268 if (exp_cause == '80'O and exp_cause == cpr.cause.causevalue) {
269 /* Check if EUA type corresponds to requested type */
270 if (match(ctx.eua, t_EuaIPv4(?)) and
271 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
272 setverdict(fail);
273 }
274 if (match(ctx.eua, t_EuaIPv6(?)) and
275 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
276 setverdict(fail);
277 }
278 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
279 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
280 setverdict(fail);
281 }
282 /* Check if PCO response corresponds to request */
283 if (ispresent(ctx.pco_req)) {
284 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
285 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
286 log("IPv4 DNS Container requested, but missing");
287 setverdict(fail);
288 }
289 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
290 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
291 log("IPv6 DNS Container requested, but missing");
292 setverdict(fail);
293 }
294 }
295 ctx.teid_remote := cpr.teidDataI.teidDataI;
296 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
297 ctx.eua := cpr.endUserAddress;
298 ctx.pco_neg := cpr.protConfigOptions;
299 setverdict(pass);
300 } else if (exp_cause != '80'O and exp_cause == cpr.cause.causevalue) {
301 if (ispresent(cpr.endUserAddress)) {
302 log("EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
303 setverdict(fail);
304 }
305 setverdict(pass);
306 } else {
307 setverdict(fail);
308 }
309 }
310
Harald Welte811651e2017-08-05 15:25:06 +0200311 /* send a PDP context activation */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +0200312 function f_pdp_ctx_act(inout PdpContext ctx, OCT1 exp_cause := '80'O) runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200313 var Gtp1cUnitdata ud;
Harald Welte94ade362017-08-04 00:36:55 +0200314 var default d;
315
316 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200317 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 +0200318 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200319 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req));
Harald Welte94ade362017-08-04 00:36:55 +0200320 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200321 d := activate(pingpong());
322 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200323 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200324 f_handle_create_req(ctx, ud, exp_cause);
Harald Welte94ade362017-08-04 00:36:55 +0200325 }
326 }
327 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200328 T_default.stop;
Harald Welte94ade362017-08-04 00:36:55 +0200329 }
330
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200331 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
332 var Gtp1cUnitdata ud;
333 var default d;
334
335 T_default.start;
336 d := activate(pingpong());
337 alt {
338 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
339 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
340 setverdict(pass);
341 } else if (not istemplatekind(expect_cause, "omit") and
342 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
343 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
344 setverdict(pass);
345 } else {
346 setverdict(fail);
347 }
348
349 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
350 setverdict(pass);
351 } else {
352 setverdict(fail);
353 }
354 }
355 }
356 deactivate(d);
357 T_default.stop;
358 }
359
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200360 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 +0200361 var Gtp1cUnitdata ud;
362 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200363 var OCT4 expect_teid;
364
365 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
366 message with cause value "Non existent" shall be zero. */
367 if (expect_causevalue == 'C0'O) {
368 expect_teid := '00000000'O;
369 } else {
370 expect_teid := ctx.teic;
371 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200372
Harald Welte41575e92017-08-13 13:49:57 +0200373 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 +0200374 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200375 d := activate(pingpong());
376 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200377 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
378 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200379 setverdict(pass);
380 } else {
381 setverdict(fail);
382 }
383 }
384 }
385 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200386 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200387 }
Harald Welte811651e2017-08-05 15:25:06 +0200388 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
389 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
390 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
391 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200392
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200393 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100394 template PDU_ICMP ts_ICMPv4_ERQ := {
395 echo := {
396 type_field := 8,
397 code := 0,
398 checksum := '0000'O,
399 identifier := '0345'O,
400 sequence_number := '0001'O,
401 data := ''O
402 }
403 }
404
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200405 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100406 template PDU_ICMP tr_ICMPv4_ERQ := {
407 echo := {
408 type_field := 8,
409 code := 0,
410 checksum := ?,
411 identifier := ?,
412 sequence_number := ?,
413 data := ?
414 }
415 }
416
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200417 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100418 template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
419 echo_reply := {
420 type_field := 0,
421 code := 0,
422 checksum := ?,
423 identifier := ?,
424 sequence_number := ?,
425 data := data
426 }
427 }
428
429 /* template for receiving/matching an ICMPv6 Destination Unreachable */
430 template PDU_ICMP tr_ICMPv4_DU := {
431 destination_unreachable := {
432 type_field := 1,
433 code := ?,
434 checksum := ?,
435 unused := ?,
436 original_ip_msg := ?
437 }
438 }
439
440 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
441 template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
442 header := {
443 ver := 4,
444 hlen := 5,
445 tos := 0,
446 tlen := tlen,
447 id := 35902,
448 res := '0'B,
449 dfrag := '1'B,
450 mfrag := '0'B,
451 foffset := 0,
452 ttl := 64,
453 proto := proto,
454 cksum := 0,
455 srcaddr := srcaddr,
456 dstaddr := dstaddr
457 },
458 ext_headers := omit,
459 payload := payload
460 }
461
Harald Welte231b9412017-08-09 17:16:31 +0200462 /* template to generate a 'Prefix Information' ICMPv6 option */
463 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
464 prefixInformation := {
465 typeField := 3,
466 lengthIndicator := 8,
467 prefixLength := prefix_len,
468 reserved1 := '000000'B,
469 a_Bit := '0'B,
470 l_Bit := '0'B,
471 validLifetime := oct2int('FFFFFFFF'O),
472 preferredLifetime := oct2int('FFFFFFFF'O),
473 reserved2 := '00000000'O,
474 prefix := prefix
475 }
476 }
477
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200478 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100479 template PDU_ICMPv6 ts_ICMPv6_ERQ := {
480 echoRequest := {
481 typeField := 128,
482 code := 0,
483 checksum := '0000'O,
484 identifier := 0,
485 sequenceNr := 0,
486 data := ''O
487 }
488 }
489
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200490 /* template for sending an ICMPv6 router solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200491 template PDU_ICMPv6 ts_ICMPv6_RS := {
492 routerSolicitation := {
493 typeField := 133,
494 code := 0,
495 checksum := '0000'O,
496 reserved := '00000000'O,
497 /* TODO: do we need 'Source link-layer address' ? */
498 options := omit
499 }
500 }
501
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200502 /* template for sending an ICMPv6 router advertisement */
Harald Welte231b9412017-08-09 17:16:31 +0200503 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
504 routerAdvertisement := {
505 typeField := 134,
506 code := 0,
507 checksum := '0000'O,
508 curHopLimit := ?,
509 reserved := '000000'B,
510 o_Bit := '0'B,
511 m_Bit := '0'B,
512 routerLifetime := oct2int('FFFF'O),
513 reachableTime := oct2int('FFFFFFFF'O),
514 retransTimer := oct2int('FFFFFFFF'O),
515 options := {
516 ts_ICMP6_OptPrefix(prefix, prefix_len)
517 }
518 }
519 }
520
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200521 /* template for sending an ICMPv6 neighbor solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200522 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
523 neighborSolicitation := {
524 typeField := 135,
525 code := 0,
526 checksum := '0000'O,
527 reserved := '00000000'O,
528 targetAddress := target_addr,
529 /* TODO: do we need 'Source link-layer address' ? */
530 options := omit
531 }
532 }
533
534 /* derive ICMPv6 link-local address from lower 64bit of link_id */
535 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
536 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
537 prefixInformation := {
538 typeField := 3,
539 lengthIndicator := 4,
540 prefixLength := prefix_len,
541 reserved1 := ?,
542 a_Bit := ?,
543 l_Bit := ?,
544 validLifetime := ?,
545 preferredLifetime := ?,
546 reserved2 := ?,
547 prefix := prefix
548 }
549 }
550
551 /* template for receiving/matching an ICMPv6 router advertisement */
552 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
553 routerAdvertisement := {
554 typeField := 134,
555 code := 0,
556 checksum := ?,
557 curHopLimit := ?,
558 reserved := ?,
559 o_Bit := '0'B,
560 m_Bit := '0'B,
561 routerLifetime := ?,
562 reachableTime := ?,
563 retransTimer := ?,
564 options := {
565 tr_ICMP6_OptPrefix(prefix, prefix_len)
566 }
567 }
568 }
569
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100570 /* template for receiving/matching an ICMPv6 Destination Unreachable */
571 template PDU_ICMPv6 tr_ICMPv6_DU := {
572 destinationUnreachable := {
573 typeField := 1,
574 code := ?,
575 checksum := ?,
576 unused := ?,
577 originalIpMsg := ?
578 }
579 }
580
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200581 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100582 template PDU_ICMPv6 tr_ICMPv6_ERQ := {
583 echoRequest := {
584 typeField := 128,
585 code := 0,
586 checksum := ?,
587 identifier := ?,
588 sequenceNr := ?,
589 data := ?
590 }
591 }
592
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100593 /* template for receiving/matching an ICMPv6 echo reply */
594 template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
595 echoReply := {
596 typeField := 129,
597 code := 0,
598 checksum := ?,
599 identifier := ?,
600 sequenceNr := ?,
601 data := data
602 }
603 }
604
Harald Welte231b9412017-08-09 17:16:31 +0200605 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
606 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
607 header := {
608 ver := 6,
609 trclass := 0,
610 flabel := 0,
611 plen := 0,
612 nexthead := nexthead,
613 hlim := hlim,
614 srcaddr := srcaddr,
615 dstaddr := dstaddr
616 },
617 ext_headers := omit,
618 payload := payload
619 }
620
621 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
622 return 'FE80000000000000'O & substr(link_id, 8, 8);
623 }
624
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100625 function f_ipv6_global(in OCT16 link_id) return OCT16 {
626 return substr(link_id, 0, 8) & '1234123412341234'O;
627 }
628
629 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
630 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
631 var integer i;
632 var octetstring res := substr(addr, 0, prefix);
633 for (i := prefix; i < lengthof(addr); i := i + 1) {
634 var octetstring a := addr[i] xor4b '11'O;
635 res := res & a;
636 }
637 return res;
638 }
639
Harald Welte231b9412017-08-09 17:16:31 +0200640 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
641 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
642 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
643 }
644
645 /* generate and encode ICMPv6 router solicitation */
646 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
647 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
648 var OCT16 saddr := f_ipv6_link_local(link_id);
649
650 var octetstring tmp;
651 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
652 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
653
654 return f_IPv6_enc(ip6);
655 }
656
657 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
658 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
659 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
660 return f_gen_icmpv6_router_solicitation(interface_id);
661 }
662
663 /* generate and encode ICMPv6 neighbor solicitation */
664 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
665 var octetstring tmp;
666 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
667 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
668 return f_IPv6_enc(ip6);
669 }
670
671 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
672 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
673 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
674 var OCT16 link_local := f_ipv6_link_local(interface_id);
675 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
676
677 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
678 }
679
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100680 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
681 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring {
682 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ));
683 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
684 var octetstring data := f_IPv4_enc(ip4);
685 var OCT2 cksum := f_IPv4_checksum(data);
686 data[10] := cksum[0];
687 data[11] := cksum[1];
688 return data;
689 }
690
691 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
692 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
693 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
694 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
695 var octetstring data := f_IPv6_enc(ip6);
696 return data;
697 }
698
699 /* Wait for ICMPv4 from GTP */
700 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +0200701 var Gtp1uUnitdata ud;
702 T_default.start;
703 alt {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100704 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200705 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200706 setverdict(fail);
707 stop;
708 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100709 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
710 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
711 if (ip4.header.ver != 4) {
712 repeat;
713 }
714 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
715 if (not match(icmp4, expected)) {
716 repeat;
717 }
718 }
719 [] GTPU.receive { setverdict(fail); }
720 [] T_default.timeout { setverdict(fail); }
721 }
722 T_default.stop;
723 }
724
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100725 /* Wait for ICMPv4 echo request from GTP */
726 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
727 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
728 }
729
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100730 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
731 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
732 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
733 }
734
735 /* Wait for ICMPv6 from GTP */
736 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
737 var Gtp1uUnitdata ud;
738 T_default.start;
739 alt {
Harald Welte231b9412017-08-09 17:16:31 +0200740 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200741 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200742 setverdict(fail);
743 stop;
744 }
Harald Welte231b9412017-08-09 17:16:31 +0200745 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
746 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100747 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +0200748 repeat;
749 }
750 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100751 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +0200752 repeat;
753 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100754 /* We are waiting for RA, update ctx */
755 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
756 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
757 log("RA with /64 prefix ", ctx.ip6_prefix);
758 }
Harald Welte231b9412017-08-09 17:16:31 +0200759 }
760 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
761 [] GTPU.receive { setverdict(fail); }
762 [] T_default.timeout { setverdict(fail); }
763 }
764 T_default.stop;
765 }
766
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100767 /* wait for GGSN to send us an ICMPv6 router advertisement */
768 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
769 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
770 }
771
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100772 /* Wait for ICMPv6 echo request from GTP */
773 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
774 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
775 }
776
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100777 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
778 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
779 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
780 }
781
Oliver Smithee6a0882019-03-08 11:05:46 +0100782 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
783 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
784 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
785 return f_gen_icmpv6_router_solicitation(interface_id);
786 }
787
788 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
789 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
790 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
791 var OCT16 link_local := f_ipv6_link_local(interface_id);
792 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
793
794 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
795 }
796
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100797 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
798 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
799 T_default.start;
800 alt {
801 [] GTPU.receive { setverdict(fail); }
802 [] T_default.timeout { }
803 }
804 T_default.stop;
805 }
806
Harald Welte79737b42019-04-10 10:39:30 +0200807 /* list of protocols where we don't accept duplicates */
808 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
809 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
810 var integer i;
811 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
812 if (id == protocol_ids_nodupes[i]) {
813 return false;
814 }
815 }
816 return true;
817 }
818
819 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
820 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
821 var OCT2List protocol_ids := {};
822 var integer i, j;
823 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
824 var OCT2 id := pco.protocols[i].protocolID;
825 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
826 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
827 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
828 }
829 }
830 protocol_ids := protocol_ids & { id };
831 }
832 }
833
Harald Welte0ef285b2017-08-13 20:06:01 +0200834 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +0200835 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200836 f_init();
Harald Welte231b9412017-08-09 17:16:31 +0200837
Harald Welteed097432017-08-13 13:28:49 +0200838 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 +0200839 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +0200840 f_pdp_ctx_del(ctx, '1'B);
841 }
842
Harald Welte0ef285b2017-08-13 20:06:01 +0200843 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +0200844 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
845 f_init();
846
Harald Welteed097432017-08-13 13:28:49 +0200847 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 +0200848 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
849 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100850
Harald Welte79737b42019-04-10 10:39:30 +0200851 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100852 /* verify PCO contains both primary and secondary DNS */
853 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
854 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
855 setverdict(fail, "Primary DNS IPv6 PCO option not found");
856 }
857
858 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
859 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
860 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
861 }
862
Harald Welteed7a1772017-08-09 20:26:20 +0200863 f_pdp_ctx_del(ctx, '1'B);
864 }
865
Harald Welte0ef285b2017-08-13 20:06:01 +0200866 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +0200867 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
868 f_init();
869
Harald Welteed097432017-08-13 13:28:49 +0200870 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 +0200871 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
872 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200873
Harald Welte79737b42019-04-10 10:39:30 +0200874 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +0200875 //f_send_gtpu(ctx, c_router_solicit);
876 //f_send_gtpu(ctx, c_neigh_solicit);
877
878 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
879 f_wait_rtr_adv(ctx);
880 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
881
Harald Welte811651e2017-08-05 15:25:06 +0200882 f_pdp_ctx_del(ctx, '1'B);
Harald Welte94ade362017-08-04 00:36:55 +0200883 }
884
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100885 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
886 Test we can send ICMPv6 ping over GTPU to DNS server. */
887 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
888 f_init();
889 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
890 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
891 f_pdp_ctx_act(ctx);
892
893 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
894 f_wait_rtr_adv(ctx);
895 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
896
897 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
898
899 /* Check if we can use valid link-local src addr. */
900 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
901 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
902 f_wait_icmp6_echo_reply(ctx);
903
904 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
905 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
906 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
907 f_wait_gtpu_fail(ctx);
908
909 /* Check if we can use valid global src addr, should work */
910 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
911 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
912 f_wait_icmp6_echo_reply(ctx);
913
914 /* Assert that packets with wrong global src addr are dropped by GGSN */
915 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
916 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
917 f_wait_gtpu_fail(ctx);
918
919 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped) */
920 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
921 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
922 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
923 f_wait_gtpu_fail(ctx);
924
925 f_pdp_ctx_del(ctx, '1'B);
926 }
927
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100928 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
929 testcase TC_pdp6_clients_interact() runs on GT_CT {
930 f_init();
931 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
932 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
933 f_pdp_ctx_act(ctxA);
934 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
935 f_wait_rtr_adv(ctxA);
936 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
937
938 f_pdp_ctx_act(ctxB);
939 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
940 f_wait_rtr_adv(ctxB);
941 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
942
943 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
944 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
945 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
946 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
947
948 /* Validate if clients can interact using ll addr. */
949 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
950 f_wait_gtpu_fail(ctxB);
951
952 /* Validate if clients can interact using global addr. */
953 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
954 f_wait_gtpu_fail(ctxB);
955
956 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +0200957 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100958 }
959
Harald Welte0ef285b2017-08-13 20:06:01 +0200960 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +0200961 testcase TC_pdp4_act_deact() runs on GT_CT {
962 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200963 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 +0200964 f_pdp_ctx_act(ctx);
965 f_pdp_ctx_del(ctx, '1'B);
966 }
967
Harald Welte0ef285b2017-08-13 20:06:01 +0200968 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +0200969 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
970 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100971 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
972 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +0200973 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 +0200974 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +0200975 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +0200976 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +0100977 /* verify IPCP is at all contained */
978 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
979 setverdict(fail, "IPCP not found in PCO");
980 }
981 /* verify IPCP contains both primary and secondary DNS */
982 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100983 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
984 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
985 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
986 } else {
987 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
988 }
Harald Welte71a36022017-12-04 18:55:58 +0100989 }
Harald Welteed7a1772017-08-09 20:26:20 +0200990 f_pdp_ctx_del(ctx, '1'B);
991 }
992
Harald Weltef8298542019-04-10 10:15:28 +0200993 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
994 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
995 f_init();
996 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
997 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
998 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
999 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1000 f_pdp_ctx_act(ctx);
1001 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1002 /* verify IPCP is at all contained */
1003 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1004 setverdict(fail, "IPCP not found in PCO");
1005 }
1006 /* verify IPCP contains both primary and secondary DNS */
1007 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1008 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1009 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1010 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1011 } else {
1012 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1013 }
1014 }
1015 /* verify that PAP is contained */
1016 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1017 setverdict(fail, "PAP not found in PCO");
1018 }
1019 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1020 if (not match(pap, tr_PAP_AuthAck)) {
1021 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1022 }
1023 f_pdp_ctx_del(ctx, '1'B);
1024 }
1025
Harald Welte0ef285b2017-08-13 20:06:01 +02001026 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001027 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1028 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001029 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 +02001030 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001031 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001032
Harald Welte79737b42019-04-10 10:39:30 +02001033 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001034 /* verify PCO contains both primary and secondary DNS */
1035 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1036 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1037 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1038 }
1039
1040 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1041 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1042 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1043 }
1044
Harald Welteed7a1772017-08-09 20:26:20 +02001045 f_pdp_ctx_del(ctx, '1'B);
1046 }
1047
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001048 /* Test PDP context activation for dynamic IPv4 EUA.
1049 Test we can send ICMPv6 ping over GTPU to DNS server. */
1050 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1051 f_init();
1052 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1053 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1054 f_pdp_ctx_act(ctx);
1055
Harald Welte79737b42019-04-10 10:39:30 +02001056 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001057 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1058
1059 /* Check if we can use valid global src addr, should work */
1060 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1061 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1062 f_wait_icmp4_echo_reply(ctx);
1063
1064 /* Assert that packets with wrong global src addr are dropped by GGSN */
1065 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1066 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1067 f_wait_gtpu_fail(ctx);
1068
1069 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1070 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1071 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1072 f_wait_gtpu_fail(ctx);
1073 f_pdp_ctx_del(ctx, '1'B);
1074 }
1075
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001076 /* Helper function for tests below. */
1077 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001078 f_init();
1079 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1080 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1081 f_pdp_ctx_act(ctxA);
1082 f_pdp_ctx_act(ctxB);
1083 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1084 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1085 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1086 f_wait_icmp4_echo_request(ctxB);
1087
1088 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001089 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001090 }
1091
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001092 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1093 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001094 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001095 f_pdp4_clients_interact();
1096 }
1097
1098 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1099 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001100 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001101 f_pdp4_clients_interact();
1102 }
1103
Harald Weltedca80052017-08-13 20:01:38 +02001104 testcase TC_echo_req_resp() runs on GT_CT {
1105 f_init();
1106 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1107 T_default.start;
1108 alt {
1109 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1110 [] GTPC.receive { repeat; };
1111 [] T_default.timeout { setverdict(fail); }
1112 }
1113 T_default.stop;
1114 }
1115
Philipp Maier33e52612018-05-30 17:22:02 +02001116 /* Test if the parser can cope with PCO that only contain either a
1117 * single primary DNS or a secondary DNS. */
1118 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1119
1120 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1121 * the test is executed.
1122 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1123
1124 f_init();
1125 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1126 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1127 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1128 var octetstring pco_neg_dns;
1129 var octetstring pco_neg_dns_expected;
1130
1131 /* PCO with primary DNS only */
1132 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1133 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001134 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001135 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1136 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1137 /* Note: The prepended hex bytes encode the following information:
1138 * 0x02 = Configuration ACK
1139 * 0x00 = Identifier
1140 * 0x000a = Length
1141 * 0x81 = Type (Primary DNS Server Address)
1142 * 0x06 = Length
1143 * (4 byte IP-Address appended) */
1144 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1145 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1146 }
1147 f_pdp_ctx_del(ctx, '1'B);
1148
1149 /* PCO with secondary DNS only */
1150 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1151 f_pdp_ctx_act(ctx);
1152 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1153 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1154 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1155 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1156 }
1157 f_pdp_ctx_del(ctx, '1'B);
1158 }
1159
1160 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1161 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1162 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1163 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1164
1165 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1166 * the test is executed.
1167 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1168
1169 f_init();
1170 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1171 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1172 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1173 var octetstring pco_neg_dns;
1174 var octetstring pco_neg_dns_expected;
1175
1176 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1177 f_pdp_ctx_act(ctx);
1178
1179 /* Check if primary DNS is contained */
1180 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1181 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1182 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1183 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1184 }
Philipp Maier33e52612018-05-30 17:22:02 +02001185
1186 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001187 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1188 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001189 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1190 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1191 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1192 }
1193 f_pdp_ctx_del(ctx, '1'B);
1194 }
1195
Oliver Smithee6a0882019-03-08 11:05:46 +01001196 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1197 testcase TC_pdp46_act_deact() runs on GT_CT {
1198 f_init();
1199 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1200 f_pdp_ctx_act(ctx);
1201 f_pdp_ctx_del(ctx, '1'B);
1202 }
1203
1204 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1205 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1206 f_init();
1207 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1208 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1209 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1210 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1211 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001212 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001213 /* verify IPCP is at all contained */
1214 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1215 setverdict(fail, "IPCP not found in PCO");
1216 }
Harald Welte79737b42019-04-10 10:39:30 +02001217 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001218 /* verify IPCP contains both primary and secondary IPv4 DNS */
1219 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1220 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1221 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1222 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1223 } else {
1224 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1225 }
1226 }
1227 f_pdp_ctx_del(ctx, '1'B);
1228 }
1229
1230 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1231 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1232 f_init();
1233 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1234 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1235 f_pdp_ctx_act(ctx);
1236
1237 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1238 f_wait_rtr_adv(ctx);
1239 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1240
1241 f_pdp_ctx_del(ctx, '1'B);
1242 }
1243
1244 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1245 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1246 f_init();
1247
1248 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1249 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1250 f_pdp_ctx_act(ctx);
1251
Harald Welte79737b42019-04-10 10:39:30 +02001252 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001253 /* verify PCO contains both primary and secondary IPv4 DNS */
1254 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1255 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1256 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1257 }
1258
1259 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1260 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1261 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1262 }
1263
1264 f_pdp_ctx_del(ctx, '1'B);
1265 }
1266
1267 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1268 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1269 f_init();
1270
1271 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1272 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1273 f_pdp_ctx_act(ctx);
1274
Harald Welte79737b42019-04-10 10:39:30 +02001275 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001276 /* verify PCO contains both primary and secondary IPv6 DNS */
1277 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1278 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1279 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1280 }
1281
1282 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1283 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1284 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1285 }
1286
1287 f_pdp_ctx_del(ctx, '1'B);
1288 }
1289
1290 /* Test PDP context activation for dynamic IPv4v6 EUA.
1291 Test we can send ICMPv6 ping over GTPU to DNS server. */
1292 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1293 f_init();
1294 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1295 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1296 f_pdp_ctx_act(ctx);
1297
1298 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1299
1300 /* Check if we can use valid global src addr, should work */
1301 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1302 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1303 f_wait_icmp4_echo_reply(ctx);
1304
1305 /* Assert that packets with wrong global src addr are dropped by GGSN */
1306 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1307 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1308 f_wait_gtpu_fail(ctx);
1309
1310 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1311 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1312 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1313 f_wait_gtpu_fail(ctx);
1314 f_pdp_ctx_del(ctx, '1'B);
1315 }
1316
1317 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1318 testcase TC_pdp46_clients_interact() runs on GT_CT {
1319 f_init();
1320 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1321 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1322 f_pdp_ctx_act(ctxA);
1323 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1324 f_wait_rtr_adv(ctxA);
1325 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1326
1327 f_pdp_ctx_act(ctxB);
1328 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1329 f_wait_rtr_adv(ctxB);
1330 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1331
1332 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1333 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1334 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1335 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1336
1337 /* Validate if clients can interact using ll addr. */
1338 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1339 f_wait_gtpu_fail(ctxB);
1340
1341 /* Validate if clients can interact using global addr. */
1342 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1343 f_wait_gtpu_fail(ctxB);
1344
1345 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001346 f_pdp_ctx_del(ctxB, '1'B);
Oliver Smithee6a0882019-03-08 11:05:46 +01001347 }
1348
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001349 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
1350 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
1351 f_init();
1352 /* A typical MS first attempts v4v6, and if rejected, then tries v4 and v6 separetly */
1353 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
1354 f_pdp_ctx_act(ctx46, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1355
1356 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1357 f_pdp_ctx_act(ctx4, '80'O); /* Normal accept cause */
1358
1359 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv6Dyn)));
1360 f_pdp_ctx_act(ctx6, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1361
1362 f_pdp_ctx_del(ctx4, '1'B);
1363 }
1364
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001365 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
1366 testcase TC_pdp_act2_recovery() runs on GT_CT {
1367 var Gtp1cUnitdata ud;
1368 var default d;
1369 var boolean ctxA_deleted := false;
1370 var boolean ctxB_created := false;
1371
1372 f_init();
1373 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1374 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1375 f_pdp_ctx_act(ctxA);
1376
1377 g_restart_ctr := int2oct(oct2int(g_restart_ctr) + 1, 1);
1378
1379 log("sending 2nd CreatePDP (recovery increased)");
1380 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
1381 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
1382 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
1383 T_default.start;
1384 d := activate(pingpong());
1385 alt {
1386 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
1387 f_handle_create_req(ctxB, ud);
1388 if (not ctxB_created) {
1389 ctxB_created := true;
1390 setverdict(pass);
1391 } else {
1392 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
1393 }
1394
1395 if (not ctxA_deleted) {
1396 repeat;
1397 }
1398 }
1399 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
1400 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
1401 setverdict(pass);
1402 } else {
1403 setverdict(fail);
1404 }
1405
1406 if (not ctxA_deleted) {
1407 ctxA_deleted := true;
1408 setverdict(pass);
1409 } else {
1410 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
1411 }
1412
1413 if (not ctxB_created) {
1414 repeat;
1415 }
1416 }
1417 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
1418 setverdict(fail, "GGSN dropping still valid pdp ctx");
1419 }
1420 }
1421 deactivate(d);
1422 T_default.stop;
1423
1424 f_pdp_ctx_del(ctxB, '1'B);
1425 }
1426
1427
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001428 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent
1429 responses (60 seconds): If same delete req is sent and duplicate is
1430 detected, saved duplicate response should be sent back. */
1431 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
1432 f_init();
1433 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1434 f_pdp_ctx_act(ctx);
1435 f_pdp_ctx_del(ctx, '1'B);
1436 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
1437 f_sleep(1.0);
1438 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
1439 duplicate. If it was not a duplicate, osmo-ggsn would answer
1440 with a failure since that PDP ctx was already deleted. */
1441 g_c_seq_nr := g_c_seq_nr - 1;
1442 f_pdp_ctx_del(ctx, '1'B);
1443
1444 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
1445 var OCT1 cause_nonexistent := 'C0'O;
1446 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent);
1447 }
1448
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001449 /* Activate PDP context + trigger Recovery procedure through EchoResp */
1450 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
1451 var Gtp1cUnitdata ud;
1452 g_use_echo := true;
1453 f_init();
1454 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1455 f_pdp_ctx_act(ctx);
1456
1457 /* Wait to receive echo request and send initial Restart counter */
1458 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1459 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1460 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1461 };
1462
1463 /* Wait to receive second echo request and send incremented Restart
1464 counter. This will fake a restarted SGSN, and pdp ctx allocated
1465 should be released by GGSN */
1466 g_restart_ctr := int2oct(oct2int(g_restart_ctr) + 1, 1);
1467 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1468 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1469 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1470 };
1471 f_pdp_ctx_exp_del_req(ctx, omit, true);
1472 setverdict(pass);
1473 }
1474
Harald Welte94ade362017-08-04 00:36:55 +02001475 control {
Harald Welteed7a1772017-08-09 20:26:20 +02001476 execute(TC_pdp4_act_deact());
1477 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02001478 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02001479 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001480 execute(TC_pdp4_act_deact_gtpu_access());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001481 execute(TC_pdp4_clients_interact_with_txseq());
1482 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02001483 execute(TC_pdp4_act_deact_with_single_dns());
1484 execute(TC_pdp4_act_deact_with_separate_dns());
Harald Welteed7a1772017-08-09 20:26:20 +02001485
1486 execute(TC_pdp6_act_deact());
1487 execute(TC_pdp6_act_deact_pcodns());
1488 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001489 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001490 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02001491
Oliver Smithee6a0882019-03-08 11:05:46 +01001492 execute(TC_pdp46_act_deact());
1493 execute(TC_pdp46_act_deact_ipcp());
1494 execute(TC_pdp46_act_deact_icmp6());
1495 execute(TC_pdp46_act_deact_pcodns4());
1496 execute(TC_pdp46_act_deact_pcodns6());
1497 execute(TC_pdp46_act_deact_gtpu_access());
1498 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001499 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01001500
Harald Weltedca80052017-08-13 20:01:38 +02001501 execute(TC_echo_req_resp());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001502 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001503 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001504
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01001505 execute(TC_pdp_act_restart_ctr_echo());
Harald Welte94ade362017-08-04 00:36:55 +02001506 }
Harald Welte379d45a2017-08-03 09:55:15 +02001507}