blob: 40506dfa0cea658737d9b0f2c97cf649a1c27b52 [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 */
Harald Welteddeecbb2017-08-18 22:53:30 +020067 }
Harald Welte94ade362017-08-04 00:36:55 +020068
Harald Welte811651e2017-08-05 15:25:06 +020069 type set PdpContext {
70 hexstring imsi,
71 octetstring msisdn optional,
72 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020073 ProtConfigOptions pco_req optional,
74 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020075 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020076 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020077 BIT4 nsapi,
78 /* TEI (Data) local side */
79 OCT4 teid,
80 /* TEI (Control) local side */
81 OCT4 teic,
82 /* TEI (Data) remote side */
83 OCT4 teid_remote,
84 /* TEI (Control) remote side */
Harald Welte5438b9d2017-08-13 13:27:48 +020085 OCT4 teic_remote
Harald Welte811651e2017-08-05 15:25:06 +020086 }
87
Harald Welte94ade362017-08-04 00:36:55 +020088 type component GT_CT {
89 port GTPC_PT GTPC;
90 port GTPU_PT GTPU;
91
Harald Welte0be142b2017-08-13 13:28:10 +020092 var boolean g_initialized := false;
93
Harald Welte94ade362017-08-04 00:36:55 +020094 var OCT1 g_restart_ctr := '01'O;
95 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +020096 var OCT4 g_sgsn_ip_c;
97 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +020098 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +020099 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
100 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200101 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200102
103 /* next to-be-sent GTP-C sequence number */
104 var uint16_t g_c_seq_nr;
105 /* next to-be-sent GTP-U sequence number */
106 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200107
108 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200109 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200110 var boolean g_use_echo := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200111 }
112
113 private function f_init_vty() runs on GT_CT {
114 map(self:GGSNVTY, system:GGSNVTY);
115 f_vty_set_prompts(GGSNVTY);
116 f_vty_transceive(GGSNVTY, "enable");
117 }
118
119 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
120 f_vty_enter_config(GGSNVTY);
121 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200122
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200123 f_vty_transceive(GGSNVTY, "apn internet");
124 if (enable) {
125 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
126 } else {
127 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
128 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200129 f_vty_transceive(GGSNVTY, "exit");
130
131 f_vty_transceive(GGSNVTY, "apn inet6");
132 if (enable) {
133 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
134 } else {
135 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
136 }
137 f_vty_transceive(GGSNVTY, "exit");
138
139 f_vty_transceive(GGSNVTY, "apn inet46");
140 if (enable) {
141 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
142 } else {
143 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
144 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200145 f_vty_transceive(GGSNVTY, "end");
146 }
147
148 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
149 if (expect_gptu_txseq) {
150 if (gtpu.s_bit != '1'B) {
151 log("GTPU sequence number expected but not present")
152 return false;
153 }
154 } else {
155 if (gtpu.s_bit != '0'B) {
156 log("GTPU sequence number not expected but present")
157 return false;
158 }
159 }
160 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200161 }
162
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200163 private function f_vty_enable_echo_interval(boolean enable) runs on GT_CT {
164 f_vty_enter_config(GGSNVTY);
165 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
166 if (enable) {
167 f_vty_transceive(GGSNVTY, "echo-interval 5");
168 } else {
169 f_vty_transceive(GGSNVTY, "no echo-interval");
170 }
171 f_vty_transceive(GGSNVTY, "end");
172 }
173
Harald Welte94ade362017-08-04 00:36:55 +0200174 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200175 if (g_initialized == true) {
176 return;
177 }
178 g_initialized := true;
179
Harald Welteddeecbb2017-08-18 22:53:30 +0200180 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
181 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
182
Harald Welte94ade362017-08-04 00:36:55 +0200183 var Result res;
184 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +0200185 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200186 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200187 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200188
189 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +0200190 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200191 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200192
193 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200194 g_c_seq_nr := f_rnd_int(65535);
195 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200196
197 f_init_vty();
Harald Welte3e0b0392018-04-26 09:46:21 +0200198 f_vty_set_gpdu_txseq(use_gtpu_txseq);
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +0100199 f_vty_enable_echo_interval(g_use_echo);
Harald Welte94ade362017-08-04 00:36:55 +0200200 }
201
Harald Welte94ade362017-08-04 00:36:55 +0200202 /* Altstep implementing responses to any incoming echo requests */
203 altstep pingpong() runs on GT_CT {
204 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200205 var Gtp1uUnitdata udu;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200206 [g_use_echo] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200207 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200208 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200209 repeat;
210 };
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200211 [not g_use_echo] GTPC.receive(tr_GTPC_PING(?)) {
212 setverdict(fail, "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200213 };
Harald Welte94ade362017-08-04 00:36:55 +0200214 [] T_default.timeout { setverdict(fail); };
215 }
216
Harald Welte811651e2017-08-05 15:25:06 +0200217 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200218 const octetstring c_ApnInternet := '08696E7465726E6574'O;
219 const octetstring c_ApnInet6 := '05696E657436'O;
220 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200221
Harald Welte811651e2017-08-05 15:25:06 +0200222 /* return random NSAPI */
223 function f_rnd_nsapi() return BIT4 {
224 return int2bit(f_rnd_int(16), 4);
225 }
226
227 /* return random TEI[DC] */
228 function f_rnd_tei() return OCT4 {
229 return int2oct(f_rnd_int(4294967296), 4);
230 }
231
232 /* define an (internal) representation of a PDP context */
233 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
234 EndUserAddress eua) := {
235 imsi := imsi,
236 msisdn := msisdn,
237 nsapi := f_rnd_nsapi(),
238 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200239 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200240 eua := eua,
241 teid := f_rnd_tei(),
Harald Welte5438b9d2017-08-13 13:27:48 +0200242 teic := f_rnd_tei()
Harald Welte811651e2017-08-05 15:25:06 +0200243 }
244
245 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200246 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200247 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200248 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200249 }
250
251 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200252 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200253 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200254 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
255 g_d_seq_nr := g_d_seq_nr + 1;
256 } else {
257 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
258 }
Harald Welte811651e2017-08-05 15:25:06 +0200259 }
260
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200261 function f_handle_create_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
262 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
263 if (exp_cause == '80'O and exp_cause == cpr.cause.causevalue) {
264 /* Check if EUA type corresponds to requested type */
265 if (match(ctx.eua, t_EuaIPv4(?)) and
266 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
267 setverdict(fail);
268 }
269 if (match(ctx.eua, t_EuaIPv6(?)) and
270 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
271 setverdict(fail);
272 }
273 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
274 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
275 setverdict(fail);
276 }
277 /* Check if PCO response corresponds to request */
278 if (ispresent(ctx.pco_req)) {
279 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
280 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
281 log("IPv4 DNS Container requested, but missing");
282 setverdict(fail);
283 }
284 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
285 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
286 log("IPv6 DNS Container requested, but missing");
287 setverdict(fail);
288 }
289 }
290 ctx.teid_remote := cpr.teidDataI.teidDataI;
291 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
292 ctx.eua := cpr.endUserAddress;
293 ctx.pco_neg := cpr.protConfigOptions;
294 setverdict(pass);
295 } else if (exp_cause != '80'O and exp_cause == cpr.cause.causevalue) {
296 if (ispresent(cpr.endUserAddress)) {
297 log("EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
298 setverdict(fail);
299 }
300 setverdict(pass);
301 } else {
302 setverdict(fail);
303 }
304 }
305
Harald Welte811651e2017-08-05 15:25:06 +0200306 /* send a PDP context activation */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +0200307 function f_pdp_ctx_act(inout PdpContext ctx, OCT1 exp_cause := '80'O) runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200308 var Gtp1cUnitdata ud;
Harald Welte94ade362017-08-04 00:36:55 +0200309 var default d;
310
311 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200312 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 +0200313 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200314 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req));
Harald Welte94ade362017-08-04 00:36:55 +0200315 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200316 d := activate(pingpong());
317 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200318 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200319 f_handle_create_req(ctx, ud, exp_cause);
Harald Welte94ade362017-08-04 00:36:55 +0200320 }
321 }
322 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200323 T_default.stop;
Harald Welte94ade362017-08-04 00:36:55 +0200324 }
325
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200326 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
327 var Gtp1cUnitdata ud;
328 var default d;
329
330 T_default.start;
331 d := activate(pingpong());
332 alt {
333 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
334 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
335 setverdict(pass);
336 } else if (not istemplatekind(expect_cause, "omit") and
337 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
338 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
339 setverdict(pass);
340 } else {
341 setverdict(fail);
342 }
343
344 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
345 setverdict(pass);
346 } else {
347 setverdict(fail);
348 }
349 }
350 }
351 deactivate(d);
352 T_default.stop;
353 }
354
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200355 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 +0200356 var Gtp1cUnitdata ud;
357 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200358 var OCT4 expect_teid;
359
360 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
361 message with cause value "Non existent" shall be zero. */
362 if (expect_causevalue == 'C0'O) {
363 expect_teid := '00000000'O;
364 } else {
365 expect_teid := ctx.teic;
366 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200367
Harald Welte41575e92017-08-13 13:49:57 +0200368 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 +0200369 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200370 d := activate(pingpong());
371 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200372 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
373 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200374 setverdict(pass);
375 } else {
376 setverdict(fail);
377 }
378 }
379 }
380 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200381 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200382 }
Harald Welte811651e2017-08-05 15:25:06 +0200383 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
384 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
385 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
386 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200387
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200388 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100389 template PDU_ICMP ts_ICMPv4_ERQ := {
390 echo := {
391 type_field := 8,
392 code := 0,
393 checksum := '0000'O,
394 identifier := '0345'O,
395 sequence_number := '0001'O,
396 data := ''O
397 }
398 }
399
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200400 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100401 template PDU_ICMP tr_ICMPv4_ERQ := {
402 echo := {
403 type_field := 8,
404 code := 0,
405 checksum := ?,
406 identifier := ?,
407 sequence_number := ?,
408 data := ?
409 }
410 }
411
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200412 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100413 template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
414 echo_reply := {
415 type_field := 0,
416 code := 0,
417 checksum := ?,
418 identifier := ?,
419 sequence_number := ?,
420 data := data
421 }
422 }
423
424 /* template for receiving/matching an ICMPv6 Destination Unreachable */
425 template PDU_ICMP tr_ICMPv4_DU := {
426 destination_unreachable := {
427 type_field := 1,
428 code := ?,
429 checksum := ?,
430 unused := ?,
431 original_ip_msg := ?
432 }
433 }
434
435 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
436 template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
437 header := {
438 ver := 4,
439 hlen := 5,
440 tos := 0,
441 tlen := tlen,
442 id := 35902,
443 res := '0'B,
444 dfrag := '1'B,
445 mfrag := '0'B,
446 foffset := 0,
447 ttl := 64,
448 proto := proto,
449 cksum := 0,
450 srcaddr := srcaddr,
451 dstaddr := dstaddr
452 },
453 ext_headers := omit,
454 payload := payload
455 }
456
Harald Welte231b9412017-08-09 17:16:31 +0200457 /* template to generate a 'Prefix Information' ICMPv6 option */
458 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
459 prefixInformation := {
460 typeField := 3,
461 lengthIndicator := 8,
462 prefixLength := prefix_len,
463 reserved1 := '000000'B,
464 a_Bit := '0'B,
465 l_Bit := '0'B,
466 validLifetime := oct2int('FFFFFFFF'O),
467 preferredLifetime := oct2int('FFFFFFFF'O),
468 reserved2 := '00000000'O,
469 prefix := prefix
470 }
471 }
472
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200473 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100474 template PDU_ICMPv6 ts_ICMPv6_ERQ := {
475 echoRequest := {
476 typeField := 128,
477 code := 0,
478 checksum := '0000'O,
479 identifier := 0,
480 sequenceNr := 0,
481 data := ''O
482 }
483 }
484
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200485 /* template for sending an ICMPv6 router solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200486 template PDU_ICMPv6 ts_ICMPv6_RS := {
487 routerSolicitation := {
488 typeField := 133,
489 code := 0,
490 checksum := '0000'O,
491 reserved := '00000000'O,
492 /* TODO: do we need 'Source link-layer address' ? */
493 options := omit
494 }
495 }
496
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200497 /* template for sending an ICMPv6 router advertisement */
Harald Welte231b9412017-08-09 17:16:31 +0200498 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
499 routerAdvertisement := {
500 typeField := 134,
501 code := 0,
502 checksum := '0000'O,
503 curHopLimit := ?,
504 reserved := '000000'B,
505 o_Bit := '0'B,
506 m_Bit := '0'B,
507 routerLifetime := oct2int('FFFF'O),
508 reachableTime := oct2int('FFFFFFFF'O),
509 retransTimer := oct2int('FFFFFFFF'O),
510 options := {
511 ts_ICMP6_OptPrefix(prefix, prefix_len)
512 }
513 }
514 }
515
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200516 /* template for sending an ICMPv6 neighbor solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200517 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
518 neighborSolicitation := {
519 typeField := 135,
520 code := 0,
521 checksum := '0000'O,
522 reserved := '00000000'O,
523 targetAddress := target_addr,
524 /* TODO: do we need 'Source link-layer address' ? */
525 options := omit
526 }
527 }
528
529 /* derive ICMPv6 link-local address from lower 64bit of link_id */
530 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
531 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
532 prefixInformation := {
533 typeField := 3,
534 lengthIndicator := 4,
535 prefixLength := prefix_len,
536 reserved1 := ?,
537 a_Bit := ?,
538 l_Bit := ?,
539 validLifetime := ?,
540 preferredLifetime := ?,
541 reserved2 := ?,
542 prefix := prefix
543 }
544 }
545
546 /* template for receiving/matching an ICMPv6 router advertisement */
547 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
548 routerAdvertisement := {
549 typeField := 134,
550 code := 0,
551 checksum := ?,
552 curHopLimit := ?,
553 reserved := ?,
554 o_Bit := '0'B,
555 m_Bit := '0'B,
556 routerLifetime := ?,
557 reachableTime := ?,
558 retransTimer := ?,
559 options := {
560 tr_ICMP6_OptPrefix(prefix, prefix_len)
561 }
562 }
563 }
564
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100565 /* template for receiving/matching an ICMPv6 Destination Unreachable */
566 template PDU_ICMPv6 tr_ICMPv6_DU := {
567 destinationUnreachable := {
568 typeField := 1,
569 code := ?,
570 checksum := ?,
571 unused := ?,
572 originalIpMsg := ?
573 }
574 }
575
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200576 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100577 template PDU_ICMPv6 tr_ICMPv6_ERQ := {
578 echoRequest := {
579 typeField := 128,
580 code := 0,
581 checksum := ?,
582 identifier := ?,
583 sequenceNr := ?,
584 data := ?
585 }
586 }
587
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100588 /* template for receiving/matching an ICMPv6 echo reply */
589 template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
590 echoReply := {
591 typeField := 129,
592 code := 0,
593 checksum := ?,
594 identifier := ?,
595 sequenceNr := ?,
596 data := data
597 }
598 }
599
Harald Welte231b9412017-08-09 17:16:31 +0200600 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
601 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
602 header := {
603 ver := 6,
604 trclass := 0,
605 flabel := 0,
606 plen := 0,
607 nexthead := nexthead,
608 hlim := hlim,
609 srcaddr := srcaddr,
610 dstaddr := dstaddr
611 },
612 ext_headers := omit,
613 payload := payload
614 }
615
616 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
617 return 'FE80000000000000'O & substr(link_id, 8, 8);
618 }
619
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100620 function f_ipv6_global(in OCT16 link_id) return OCT16 {
621 return substr(link_id, 0, 8) & '1234123412341234'O;
622 }
623
624 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
625 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
626 var integer i;
627 var octetstring res := substr(addr, 0, prefix);
628 for (i := prefix; i < lengthof(addr); i := i + 1) {
629 var octetstring a := addr[i] xor4b '11'O;
630 res := res & a;
631 }
632 return res;
633 }
634
Harald Welte231b9412017-08-09 17:16:31 +0200635 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
636 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
637 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
638 }
639
640 /* generate and encode ICMPv6 router solicitation */
641 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
642 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
643 var OCT16 saddr := f_ipv6_link_local(link_id);
644
645 var octetstring tmp;
646 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
647 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
648
649 return f_IPv6_enc(ip6);
650 }
651
652 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
653 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
654 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
655 return f_gen_icmpv6_router_solicitation(interface_id);
656 }
657
658 /* generate and encode ICMPv6 neighbor solicitation */
659 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
660 var octetstring tmp;
661 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
662 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
663 return f_IPv6_enc(ip6);
664 }
665
666 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
667 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
668 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
669 var OCT16 link_local := f_ipv6_link_local(interface_id);
670 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
671
672 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
673 }
674
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100675 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
676 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring {
677 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ));
678 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
679 var octetstring data := f_IPv4_enc(ip4);
680 var OCT2 cksum := f_IPv4_checksum(data);
681 data[10] := cksum[0];
682 data[11] := cksum[1];
683 return data;
684 }
685
686 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
687 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
688 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
689 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
690 var octetstring data := f_IPv6_enc(ip6);
691 return data;
692 }
693
694 /* Wait for ICMPv4 from GTP */
695 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +0200696 var Gtp1uUnitdata ud;
697 T_default.start;
698 alt {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100699 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200700 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200701 setverdict(fail);
702 stop;
703 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100704 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
705 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
706 if (ip4.header.ver != 4) {
707 repeat;
708 }
709 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
710 if (not match(icmp4, expected)) {
711 repeat;
712 }
713 }
714 [] GTPU.receive { setverdict(fail); }
715 [] T_default.timeout { setverdict(fail); }
716 }
717 T_default.stop;
718 }
719
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100720 /* Wait for ICMPv4 echo request from GTP */
721 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
722 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
723 }
724
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100725 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
726 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
727 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
728 }
729
730 /* Wait for ICMPv6 from GTP */
731 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
732 var Gtp1uUnitdata ud;
733 T_default.start;
734 alt {
Harald Welte231b9412017-08-09 17:16:31 +0200735 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200736 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200737 setverdict(fail);
738 stop;
739 }
Harald Welte231b9412017-08-09 17:16:31 +0200740 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
741 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100742 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +0200743 repeat;
744 }
745 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100746 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +0200747 repeat;
748 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100749 /* We are waiting for RA, update ctx */
750 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
751 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
752 log("RA with /64 prefix ", ctx.ip6_prefix);
753 }
Harald Welte231b9412017-08-09 17:16:31 +0200754 }
755 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
756 [] GTPU.receive { setverdict(fail); }
757 [] T_default.timeout { setverdict(fail); }
758 }
759 T_default.stop;
760 }
761
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100762 /* wait for GGSN to send us an ICMPv6 router advertisement */
763 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
764 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
765 }
766
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100767 /* Wait for ICMPv6 echo request from GTP */
768 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
769 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
770 }
771
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100772 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
773 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
774 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
775 }
776
Oliver Smithee6a0882019-03-08 11:05:46 +0100777 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
778 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
779 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
780 return f_gen_icmpv6_router_solicitation(interface_id);
781 }
782
783 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
784 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
785 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
786 var OCT16 link_local := f_ipv6_link_local(interface_id);
787 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
788
789 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
790 }
791
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100792 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
793 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
794 T_default.start;
795 alt {
796 [] GTPU.receive { setverdict(fail); }
797 [] T_default.timeout { }
798 }
799 T_default.stop;
800 }
801
Harald Welte79737b42019-04-10 10:39:30 +0200802 /* list of protocols where we don't accept duplicates */
803 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
804 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
805 var integer i;
806 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
807 if (id == protocol_ids_nodupes[i]) {
808 return false;
809 }
810 }
811 return true;
812 }
813
814 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
815 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
816 var OCT2List protocol_ids := {};
817 var integer i, j;
818 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
819 var OCT2 id := pco.protocols[i].protocolID;
820 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
821 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
822 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
823 }
824 }
825 protocol_ids := protocol_ids & { id };
826 }
827 }
828
Harald Welte0ef285b2017-08-13 20:06:01 +0200829 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +0200830 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200831 f_init();
Harald Welte231b9412017-08-09 17:16:31 +0200832
Harald Welteed097432017-08-13 13:28:49 +0200833 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 +0200834 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +0200835 f_pdp_ctx_del(ctx, '1'B);
836 }
837
Harald Welte0ef285b2017-08-13 20:06:01 +0200838 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +0200839 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
840 f_init();
841
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 Welteed7a1772017-08-09 20:26:20 +0200843 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
844 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100845
Harald Welte79737b42019-04-10 10:39:30 +0200846 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100847 /* verify PCO contains both primary and secondary DNS */
848 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
849 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
850 setverdict(fail, "Primary DNS IPv6 PCO option not found");
851 }
852
853 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
854 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
855 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
856 }
857
Harald Welteed7a1772017-08-09 20:26:20 +0200858 f_pdp_ctx_del(ctx, '1'B);
859 }
860
Harald Welte0ef285b2017-08-13 20:06:01 +0200861 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +0200862 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
863 f_init();
864
Harald Welteed097432017-08-13 13:28:49 +0200865 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 +0200866 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
867 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200868
Harald Welte79737b42019-04-10 10:39:30 +0200869 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +0200870 //f_send_gtpu(ctx, c_router_solicit);
871 //f_send_gtpu(ctx, c_neigh_solicit);
872
873 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
874 f_wait_rtr_adv(ctx);
875 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
876
Harald Welte811651e2017-08-05 15:25:06 +0200877 f_pdp_ctx_del(ctx, '1'B);
Harald Welte94ade362017-08-04 00:36:55 +0200878 }
879
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100880 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
881 Test we can send ICMPv6 ping over GTPU to DNS server. */
882 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
883 f_init();
884 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
885 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
886 f_pdp_ctx_act(ctx);
887
888 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
889 f_wait_rtr_adv(ctx);
890 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
891
892 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
893
894 /* Check if we can use valid link-local src addr. */
895 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
896 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
897 f_wait_icmp6_echo_reply(ctx);
898
899 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
900 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
901 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
902 f_wait_gtpu_fail(ctx);
903
904 /* Check if we can use valid global src addr, should work */
905 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
906 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
907 f_wait_icmp6_echo_reply(ctx);
908
909 /* Assert that packets with wrong global src addr are dropped by GGSN */
910 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
911 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
912 f_wait_gtpu_fail(ctx);
913
914 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped) */
915 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
916 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
917 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
918 f_wait_gtpu_fail(ctx);
919
920 f_pdp_ctx_del(ctx, '1'B);
921 }
922
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100923 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
924 testcase TC_pdp6_clients_interact() runs on GT_CT {
925 f_init();
926 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
927 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
928 f_pdp_ctx_act(ctxA);
929 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
930 f_wait_rtr_adv(ctxA);
931 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
932
933 f_pdp_ctx_act(ctxB);
934 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
935 f_wait_rtr_adv(ctxB);
936 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
937
938 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
939 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
940 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
941 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
942
943 /* Validate if clients can interact using ll addr. */
944 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
945 f_wait_gtpu_fail(ctxB);
946
947 /* Validate if clients can interact using global addr. */
948 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
949 f_wait_gtpu_fail(ctxB);
950
951 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +0200952 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100953 }
954
Harald Welte0ef285b2017-08-13 20:06:01 +0200955 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +0200956 testcase TC_pdp4_act_deact() runs on GT_CT {
957 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200958 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 +0200959 f_pdp_ctx_act(ctx);
960 f_pdp_ctx_del(ctx, '1'B);
961 }
962
Harald Welte0ef285b2017-08-13 20:06:01 +0200963 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +0200964 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
965 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100966 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
967 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +0200968 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 +0200969 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +0200970 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +0200971 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +0100972 /* verify IPCP is at all contained */
973 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
974 setverdict(fail, "IPCP not found in PCO");
975 }
976 /* verify IPCP contains both primary and secondary DNS */
977 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100978 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
979 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
980 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
981 } else {
982 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
983 }
Harald Welte71a36022017-12-04 18:55:58 +0100984 }
Harald Welteed7a1772017-08-09 20:26:20 +0200985 f_pdp_ctx_del(ctx, '1'B);
986 }
987
Harald Weltef8298542019-04-10 10:15:28 +0200988 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
989 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
990 f_init();
991 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
992 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
993 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
994 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
995 f_pdp_ctx_act(ctx);
996 f_PCO_ensure_no_duplicates(ctx.pco_neg);
997 /* verify IPCP is at all contained */
998 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
999 setverdict(fail, "IPCP not found in PCO");
1000 }
1001 /* verify IPCP contains both primary and secondary DNS */
1002 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1003 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1004 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1005 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1006 } else {
1007 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1008 }
1009 }
1010 /* verify that PAP is contained */
1011 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1012 setverdict(fail, "PAP not found in PCO");
1013 }
1014 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1015 if (not match(pap, tr_PAP_AuthAck)) {
1016 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1017 }
1018 f_pdp_ctx_del(ctx, '1'B);
1019 }
1020
Harald Welte0ef285b2017-08-13 20:06:01 +02001021 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001022 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1023 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001024 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 +02001025 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001026 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001027
Harald Welte79737b42019-04-10 10:39:30 +02001028 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001029 /* verify PCO contains both primary and secondary DNS */
1030 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1031 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1032 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1033 }
1034
1035 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1036 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1037 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1038 }
1039
Harald Welteed7a1772017-08-09 20:26:20 +02001040 f_pdp_ctx_del(ctx, '1'B);
1041 }
1042
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001043 /* Test PDP context activation for dynamic IPv4 EUA.
1044 Test we can send ICMPv6 ping over GTPU to DNS server. */
1045 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1046 f_init();
1047 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1048 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1049 f_pdp_ctx_act(ctx);
1050
Harald Welte79737b42019-04-10 10:39:30 +02001051 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001052 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1053
1054 /* Check if we can use valid global src addr, should work */
1055 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1056 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1057 f_wait_icmp4_echo_reply(ctx);
1058
1059 /* Assert that packets with wrong global src addr are dropped by GGSN */
1060 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1061 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1062 f_wait_gtpu_fail(ctx);
1063
1064 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1065 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1066 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1067 f_wait_gtpu_fail(ctx);
1068 f_pdp_ctx_del(ctx, '1'B);
1069 }
1070
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001071 /* Helper function for tests below. */
1072 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001073 f_init();
1074 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1075 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1076 f_pdp_ctx_act(ctxA);
1077 f_pdp_ctx_act(ctxB);
1078 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1079 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1080 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1081 f_wait_icmp4_echo_request(ctxB);
1082
1083 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001084 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001085 }
1086
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001087 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1088 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001089 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001090 f_pdp4_clients_interact();
1091 }
1092
1093 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1094 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001095 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001096 f_pdp4_clients_interact();
1097 }
1098
Harald Weltedca80052017-08-13 20:01:38 +02001099 testcase TC_echo_req_resp() runs on GT_CT {
1100 f_init();
1101 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1102 T_default.start;
1103 alt {
1104 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1105 [] GTPC.receive { repeat; };
1106 [] T_default.timeout { setverdict(fail); }
1107 }
1108 T_default.stop;
1109 }
1110
Philipp Maier33e52612018-05-30 17:22:02 +02001111 /* Test if the parser can cope with PCO that only contain either a
1112 * single primary DNS or a secondary DNS. */
1113 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1114
1115 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1116 * the test is executed.
1117 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1118
1119 f_init();
1120 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1121 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1122 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1123 var octetstring pco_neg_dns;
1124 var octetstring pco_neg_dns_expected;
1125
1126 /* PCO with primary DNS only */
1127 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1128 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001129 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001130 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1131 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1132 /* Note: The prepended hex bytes encode the following information:
1133 * 0x02 = Configuration ACK
1134 * 0x00 = Identifier
1135 * 0x000a = Length
1136 * 0x81 = Type (Primary DNS Server Address)
1137 * 0x06 = Length
1138 * (4 byte IP-Address appended) */
1139 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1140 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1141 }
1142 f_pdp_ctx_del(ctx, '1'B);
1143
1144 /* PCO with secondary DNS only */
1145 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1146 f_pdp_ctx_act(ctx);
1147 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1148 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1149 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1150 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1151 }
1152 f_pdp_ctx_del(ctx, '1'B);
1153 }
1154
1155 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1156 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1157 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1158 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1159
1160 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1161 * the test is executed.
1162 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1163
1164 f_init();
1165 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1166 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1167 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1168 var octetstring pco_neg_dns;
1169 var octetstring pco_neg_dns_expected;
1170
1171 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1172 f_pdp_ctx_act(ctx);
1173
1174 /* Check if primary DNS is contained */
1175 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1176 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1177 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1178 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1179 }
Philipp Maier33e52612018-05-30 17:22:02 +02001180
1181 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001182 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1183 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001184 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1185 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1186 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1187 }
1188 f_pdp_ctx_del(ctx, '1'B);
1189 }
1190
Oliver Smithee6a0882019-03-08 11:05:46 +01001191 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1192 testcase TC_pdp46_act_deact() runs on GT_CT {
1193 f_init();
1194 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1195 f_pdp_ctx_act(ctx);
1196 f_pdp_ctx_del(ctx, '1'B);
1197 }
1198
1199 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1200 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1201 f_init();
1202 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1203 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1204 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1205 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1206 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001207 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001208 /* verify IPCP is at all contained */
1209 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1210 setverdict(fail, "IPCP not found in PCO");
1211 }
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 contains both primary and secondary IPv4 DNS */
1214 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1215 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1216 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1217 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1218 } else {
1219 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1220 }
1221 }
1222 f_pdp_ctx_del(ctx, '1'B);
1223 }
1224
1225 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1226 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1227 f_init();
1228 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1229 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1230 f_pdp_ctx_act(ctx);
1231
1232 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1233 f_wait_rtr_adv(ctx);
1234 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1235
1236 f_pdp_ctx_del(ctx, '1'B);
1237 }
1238
1239 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1240 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1241 f_init();
1242
1243 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1244 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1245 f_pdp_ctx_act(ctx);
1246
Harald Welte79737b42019-04-10 10:39:30 +02001247 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001248 /* verify PCO contains both primary and secondary IPv4 DNS */
1249 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1250 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1251 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1252 }
1253
1254 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1255 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1256 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1257 }
1258
1259 f_pdp_ctx_del(ctx, '1'B);
1260 }
1261
1262 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1263 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1264 f_init();
1265
1266 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1267 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1268 f_pdp_ctx_act(ctx);
1269
Harald Welte79737b42019-04-10 10:39:30 +02001270 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001271 /* verify PCO contains both primary and secondary IPv6 DNS */
1272 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1273 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1274 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1275 }
1276
1277 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1278 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1279 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1280 }
1281
1282 f_pdp_ctx_del(ctx, '1'B);
1283 }
1284
1285 /* Test PDP context activation for dynamic IPv4v6 EUA.
1286 Test we can send ICMPv6 ping over GTPU to DNS server. */
1287 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1288 f_init();
1289 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1290 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1291 f_pdp_ctx_act(ctx);
1292
1293 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1294
1295 /* Check if we can use valid global src addr, should work */
1296 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1297 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1298 f_wait_icmp4_echo_reply(ctx);
1299
1300 /* Assert that packets with wrong global src addr are dropped by GGSN */
1301 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1302 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1303 f_wait_gtpu_fail(ctx);
1304
1305 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1306 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1307 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1308 f_wait_gtpu_fail(ctx);
1309 f_pdp_ctx_del(ctx, '1'B);
1310 }
1311
1312 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1313 testcase TC_pdp46_clients_interact() runs on GT_CT {
1314 f_init();
1315 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1316 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1317 f_pdp_ctx_act(ctxA);
1318 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1319 f_wait_rtr_adv(ctxA);
1320 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1321
1322 f_pdp_ctx_act(ctxB);
1323 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1324 f_wait_rtr_adv(ctxB);
1325 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1326
1327 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1328 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1329 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1330 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1331
1332 /* Validate if clients can interact using ll addr. */
1333 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1334 f_wait_gtpu_fail(ctxB);
1335
1336 /* Validate if clients can interact using global addr. */
1337 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1338 f_wait_gtpu_fail(ctxB);
1339
1340 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001341 f_pdp_ctx_del(ctxB, '1'B);
Oliver Smithee6a0882019-03-08 11:05:46 +01001342 }
1343
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001344 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
1345 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
1346 f_init();
1347 /* A typical MS first attempts v4v6, and if rejected, then tries v4 and v6 separetly */
1348 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
1349 f_pdp_ctx_act(ctx46, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1350
1351 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1352 f_pdp_ctx_act(ctx4, '80'O); /* Normal accept cause */
1353
1354 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv6Dyn)));
1355 f_pdp_ctx_act(ctx6, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1356
1357 f_pdp_ctx_del(ctx4, '1'B);
1358 }
1359
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001360 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
1361 testcase TC_pdp_act2_recovery() runs on GT_CT {
1362 var Gtp1cUnitdata ud;
1363 var default d;
1364 var boolean ctxA_deleted := false;
1365 var boolean ctxB_created := false;
1366
1367 f_init();
1368 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1369 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1370 f_pdp_ctx_act(ctxA);
1371
1372 g_restart_ctr := int2oct(oct2int(g_restart_ctr) + 1, 1);
1373
1374 log("sending 2nd CreatePDP (recovery increased)");
1375 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
1376 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
1377 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
1378 T_default.start;
1379 d := activate(pingpong());
1380 alt {
1381 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
1382 f_handle_create_req(ctxB, ud);
1383 if (not ctxB_created) {
1384 ctxB_created := true;
1385 setverdict(pass);
1386 } else {
1387 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
1388 }
1389
1390 if (not ctxA_deleted) {
1391 repeat;
1392 }
1393 }
1394 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
1395 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
1396 setverdict(pass);
1397 } else {
1398 setverdict(fail);
1399 }
1400
1401 if (not ctxA_deleted) {
1402 ctxA_deleted := true;
1403 setverdict(pass);
1404 } else {
1405 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
1406 }
1407
1408 if (not ctxB_created) {
1409 repeat;
1410 }
1411 }
1412 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
1413 setverdict(fail, "GGSN dropping still valid pdp ctx");
1414 }
1415 }
1416 deactivate(d);
1417 T_default.stop;
1418
1419 f_pdp_ctx_del(ctxB, '1'B);
1420 }
1421
1422
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001423 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent
1424 responses (60 seconds): If same delete req is sent and duplicate is
1425 detected, saved duplicate response should be sent back. */
1426 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
1427 f_init();
1428 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1429 f_pdp_ctx_act(ctx);
1430 f_pdp_ctx_del(ctx, '1'B);
1431 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
1432 f_sleep(1.0);
1433 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
1434 duplicate. If it was not a duplicate, osmo-ggsn would answer
1435 with a failure since that PDP ctx was already deleted. */
1436 g_c_seq_nr := g_c_seq_nr - 1;
1437 f_pdp_ctx_del(ctx, '1'B);
1438
1439 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
1440 var OCT1 cause_nonexistent := 'C0'O;
1441 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent);
1442 }
1443
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001444 /* Activate PDP context + trigger Recovery procedure through EchoResp */
1445 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
1446 var Gtp1cUnitdata ud;
1447 g_use_echo := true;
1448 f_init();
1449 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1450 f_pdp_ctx_act(ctx);
1451
1452 /* Wait to receive echo request and send initial Restart counter */
1453 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1454 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1455 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1456 };
1457
1458 /* Wait to receive second echo request and send incremented Restart
1459 counter. This will fake a restarted SGSN, and pdp ctx allocated
1460 should be released by GGSN */
1461 g_restart_ctr := int2oct(oct2int(g_restart_ctr) + 1, 1);
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 f_pdp_ctx_exp_del_req(ctx, omit, true);
1467 setverdict(pass);
1468 }
1469
Harald Welte94ade362017-08-04 00:36:55 +02001470 control {
Harald Welteed7a1772017-08-09 20:26:20 +02001471 execute(TC_pdp4_act_deact());
1472 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02001473 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02001474 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001475 execute(TC_pdp4_act_deact_gtpu_access());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001476 execute(TC_pdp4_clients_interact_with_txseq());
1477 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02001478 execute(TC_pdp4_act_deact_with_single_dns());
1479 execute(TC_pdp4_act_deact_with_separate_dns());
Harald Welteed7a1772017-08-09 20:26:20 +02001480
1481 execute(TC_pdp6_act_deact());
1482 execute(TC_pdp6_act_deact_pcodns());
1483 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001484 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001485 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02001486
Oliver Smithee6a0882019-03-08 11:05:46 +01001487 execute(TC_pdp46_act_deact());
1488 execute(TC_pdp46_act_deact_ipcp());
1489 execute(TC_pdp46_act_deact_icmp6());
1490 execute(TC_pdp46_act_deact_pcodns4());
1491 execute(TC_pdp46_act_deact_pcodns6());
1492 execute(TC_pdp46_act_deact_gtpu_access());
1493 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001494 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01001495
Harald Weltedca80052017-08-13 20:01:38 +02001496 execute(TC_echo_req_resp());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001497 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001498 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001499
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01001500 execute(TC_pdp_act_restart_ctr_echo());
Harald Welte94ade362017-08-04 00:36:55 +02001501 }
Harald Welte379d45a2017-08-03 09:55:15 +02001502}