blob: 28e34e9e73318fc7870f463ffd725252f8c4dd09 [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 */
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +010086 OCT4 teic_remote,
87 OCT1 ratType optional
Harald Welte811651e2017-08-05 15:25:06 +020088 }
89
Harald Welte94ade362017-08-04 00:36:55 +020090 type component GT_CT {
91 port GTPC_PT GTPC;
92 port GTPU_PT GTPU;
93
Harald Welte0be142b2017-08-13 13:28:10 +020094 var boolean g_initialized := false;
95
Harald Welte94ade362017-08-04 00:36:55 +020096 var OCT1 g_restart_ctr := '01'O;
97 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +020098 var OCT4 g_sgsn_ip_c;
99 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +0200100 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200101 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
102 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200103 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200104
105 /* next to-be-sent GTP-C sequence number */
106 var uint16_t g_c_seq_nr;
107 /* next to-be-sent GTP-U sequence number */
108 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200109
110 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200111 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200112 var boolean g_use_echo := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200113 }
114
115 private function f_init_vty() runs on GT_CT {
116 map(self:GGSNVTY, system:GGSNVTY);
117 f_vty_set_prompts(GGSNVTY);
118 f_vty_transceive(GGSNVTY, "enable");
119 }
120
121 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
122 f_vty_enter_config(GGSNVTY);
123 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200124
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200125 f_vty_transceive(GGSNVTY, "apn internet");
126 if (enable) {
127 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
128 } else {
129 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
130 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200131 f_vty_transceive(GGSNVTY, "exit");
132
133 f_vty_transceive(GGSNVTY, "apn inet6");
134 if (enable) {
135 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
136 } else {
137 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
138 }
139 f_vty_transceive(GGSNVTY, "exit");
140
141 f_vty_transceive(GGSNVTY, "apn inet46");
142 if (enable) {
143 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
144 } else {
145 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
146 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200147 f_vty_transceive(GGSNVTY, "end");
148 }
149
150 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
151 if (expect_gptu_txseq) {
152 if (gtpu.s_bit != '1'B) {
153 log("GTPU sequence number expected but not present")
154 return false;
155 }
156 } else {
157 if (gtpu.s_bit != '0'B) {
158 log("GTPU sequence number not expected but present")
159 return false;
160 }
161 }
162 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200163 }
164
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200165 private function f_vty_enable_echo_interval(boolean enable) runs on GT_CT {
166 f_vty_enter_config(GGSNVTY);
167 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
168 if (enable) {
169 f_vty_transceive(GGSNVTY, "echo-interval 5");
170 } else {
171 f_vty_transceive(GGSNVTY, "no echo-interval");
172 }
173 f_vty_transceive(GGSNVTY, "end");
174 }
175
Harald Welte94ade362017-08-04 00:36:55 +0200176 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200177 if (g_initialized == true) {
178 return;
179 }
180 g_initialized := true;
181
Harald Welteddeecbb2017-08-18 22:53:30 +0200182 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
183 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
184
Harald Welte94ade362017-08-04 00:36:55 +0200185 var Result res;
186 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +0200187 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200188 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200189 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200190
191 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +0200192 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200193 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200194
195 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200196 g_c_seq_nr := f_rnd_int(65535);
197 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200198
199 f_init_vty();
Harald Welte3e0b0392018-04-26 09:46:21 +0200200 f_vty_set_gpdu_txseq(use_gtpu_txseq);
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +0100201 f_vty_enable_echo_interval(g_use_echo);
Harald Welte94ade362017-08-04 00:36:55 +0200202 }
203
Harald Welte94ade362017-08-04 00:36:55 +0200204 /* Altstep implementing responses to any incoming echo requests */
205 altstep pingpong() runs on GT_CT {
206 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200207 var Gtp1uUnitdata udu;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200208 [g_use_echo] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200209 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200210 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200211 repeat;
212 };
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200213 [not g_use_echo] GTPC.receive(tr_GTPC_PING(?)) {
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100214 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
215 "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200216 };
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100217 [] T_default.timeout {
218 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
219 "pinpong T_default timeout");
220 };
Harald Welte94ade362017-08-04 00:36:55 +0200221 }
222
Harald Welte811651e2017-08-05 15:25:06 +0200223 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200224 const octetstring c_ApnInternet := '08696E7465726E6574'O;
225 const octetstring c_ApnInet6 := '05696E657436'O;
226 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200227
Harald Welte811651e2017-08-05 15:25:06 +0200228 /* return random NSAPI */
229 function f_rnd_nsapi() return BIT4 {
230 return int2bit(f_rnd_int(16), 4);
231 }
232
233 /* return random TEI[DC] */
234 function f_rnd_tei() return OCT4 {
235 return int2oct(f_rnd_int(4294967296), 4);
236 }
237
238 /* define an (internal) representation of a PDP context */
239 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100240 EndUserAddress eua, OCT1 ratType := '02'O /* GERAN */) := {
Harald Welte811651e2017-08-05 15:25:06 +0200241 imsi := imsi,
242 msisdn := msisdn,
243 nsapi := f_rnd_nsapi(),
244 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200245 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200246 eua := eua,
247 teid := f_rnd_tei(),
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100248 teic := f_rnd_tei(),
249 ratType := ratType
Harald Welte811651e2017-08-05 15:25:06 +0200250 }
251
252 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200253 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200254 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200255 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200256 }
257
258 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200259 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200260 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200261 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
262 g_d_seq_nr := g_d_seq_nr + 1;
263 } else {
264 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
265 }
Harald Welte811651e2017-08-05 15:25:06 +0200266 }
267
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200268 function f_handle_create_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
269 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
270 if (exp_cause == '80'O and exp_cause == cpr.cause.causevalue) {
271 /* Check if EUA type corresponds to requested type */
272 if (match(ctx.eua, t_EuaIPv4(?)) and
273 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
274 setverdict(fail);
275 }
276 if (match(ctx.eua, t_EuaIPv6(?)) and
277 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
278 setverdict(fail);
279 }
280 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
281 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
282 setverdict(fail);
283 }
284 /* Check if PCO response corresponds to request */
285 if (ispresent(ctx.pco_req)) {
286 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
287 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
288 log("IPv4 DNS Container requested, but missing");
289 setverdict(fail);
290 }
291 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
292 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
293 log("IPv6 DNS Container requested, but missing");
294 setverdict(fail);
295 }
296 }
297 ctx.teid_remote := cpr.teidDataI.teidDataI;
298 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
299 ctx.eua := cpr.endUserAddress;
300 ctx.pco_neg := cpr.protConfigOptions;
301 setverdict(pass);
302 } else if (exp_cause != '80'O and exp_cause == cpr.cause.causevalue) {
303 if (ispresent(cpr.endUserAddress)) {
304 log("EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
305 setverdict(fail);
306 }
307 setverdict(pass);
308 } else {
309 setverdict(fail);
310 }
311 }
312
Harald Welte811651e2017-08-05 15:25:06 +0200313 /* send a PDP context activation */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +0200314 function f_pdp_ctx_act(inout PdpContext ctx, OCT1 exp_cause := '80'O) runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200315 var Gtp1cUnitdata ud;
Harald Welte94ade362017-08-04 00:36:55 +0200316 var default d;
317
318 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200319 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 +0200320 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100321 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req, ctx.ratType));
Harald Welte94ade362017-08-04 00:36:55 +0200322 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200323 d := activate(pingpong());
324 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200325 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200326 f_handle_create_req(ctx, ud, exp_cause);
Harald Welte94ade362017-08-04 00:36:55 +0200327 }
328 }
329 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200330 T_default.stop;
Harald Welte94ade362017-08-04 00:36:55 +0200331 }
332
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200333 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
334 var Gtp1cUnitdata ud;
335 var default d;
336
337 T_default.start;
338 d := activate(pingpong());
339 alt {
340 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
341 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
342 setverdict(pass);
343 } else if (not istemplatekind(expect_cause, "omit") and
344 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
345 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
346 setverdict(pass);
347 } else {
348 setverdict(fail);
349 }
350
351 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
352 setverdict(pass);
353 } else {
354 setverdict(fail);
355 }
356 }
357 }
358 deactivate(d);
359 T_default.stop;
360 }
361
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200362 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 +0200363 var Gtp1cUnitdata ud;
364 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200365 var OCT4 expect_teid;
366
367 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
368 message with cause value "Non existent" shall be zero. */
369 if (expect_causevalue == 'C0'O) {
370 expect_teid := '00000000'O;
371 } else {
372 expect_teid := ctx.teic;
373 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200374
Harald Welte41575e92017-08-13 13:49:57 +0200375 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 +0200376 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200377 d := activate(pingpong());
378 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200379 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
380 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200381 setverdict(pass);
382 } else {
383 setverdict(fail);
384 }
385 }
386 }
387 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200388 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200389 }
Harald Welte811651e2017-08-05 15:25:06 +0200390 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
391 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
392 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
393 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200394
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200395 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100396 template PDU_ICMP ts_ICMPv4_ERQ := {
397 echo := {
398 type_field := 8,
399 code := 0,
400 checksum := '0000'O,
401 identifier := '0345'O,
402 sequence_number := '0001'O,
403 data := ''O
404 }
405 }
406
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200407 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100408 template PDU_ICMP tr_ICMPv4_ERQ := {
409 echo := {
410 type_field := 8,
411 code := 0,
412 checksum := ?,
413 identifier := ?,
414 sequence_number := ?,
415 data := ?
416 }
417 }
418
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200419 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100420 template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
421 echo_reply := {
422 type_field := 0,
423 code := 0,
424 checksum := ?,
425 identifier := ?,
426 sequence_number := ?,
427 data := data
428 }
429 }
430
431 /* template for receiving/matching an ICMPv6 Destination Unreachable */
432 template PDU_ICMP tr_ICMPv4_DU := {
433 destination_unreachable := {
434 type_field := 1,
435 code := ?,
436 checksum := ?,
437 unused := ?,
438 original_ip_msg := ?
439 }
440 }
441
442 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
443 template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
444 header := {
445 ver := 4,
446 hlen := 5,
447 tos := 0,
448 tlen := tlen,
449 id := 35902,
450 res := '0'B,
451 dfrag := '1'B,
452 mfrag := '0'B,
453 foffset := 0,
454 ttl := 64,
455 proto := proto,
456 cksum := 0,
457 srcaddr := srcaddr,
458 dstaddr := dstaddr
459 },
460 ext_headers := omit,
461 payload := payload
462 }
463
Harald Welte231b9412017-08-09 17:16:31 +0200464 /* template to generate a 'Prefix Information' ICMPv6 option */
465 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
466 prefixInformation := {
467 typeField := 3,
468 lengthIndicator := 8,
469 prefixLength := prefix_len,
470 reserved1 := '000000'B,
471 a_Bit := '0'B,
472 l_Bit := '0'B,
473 validLifetime := oct2int('FFFFFFFF'O),
474 preferredLifetime := oct2int('FFFFFFFF'O),
475 reserved2 := '00000000'O,
476 prefix := prefix
477 }
478 }
479
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200480 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100481 template PDU_ICMPv6 ts_ICMPv6_ERQ := {
482 echoRequest := {
483 typeField := 128,
484 code := 0,
485 checksum := '0000'O,
486 identifier := 0,
487 sequenceNr := 0,
488 data := ''O
489 }
490 }
491
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200492 /* template for sending an ICMPv6 router solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200493 template PDU_ICMPv6 ts_ICMPv6_RS := {
494 routerSolicitation := {
495 typeField := 133,
496 code := 0,
497 checksum := '0000'O,
498 reserved := '00000000'O,
499 /* TODO: do we need 'Source link-layer address' ? */
500 options := omit
501 }
502 }
503
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200504 /* template for sending an ICMPv6 router advertisement */
Harald Welte231b9412017-08-09 17:16:31 +0200505 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
506 routerAdvertisement := {
507 typeField := 134,
508 code := 0,
509 checksum := '0000'O,
510 curHopLimit := ?,
511 reserved := '000000'B,
512 o_Bit := '0'B,
513 m_Bit := '0'B,
514 routerLifetime := oct2int('FFFF'O),
515 reachableTime := oct2int('FFFFFFFF'O),
516 retransTimer := oct2int('FFFFFFFF'O),
517 options := {
518 ts_ICMP6_OptPrefix(prefix, prefix_len)
519 }
520 }
521 }
522
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200523 /* template for sending an ICMPv6 neighbor solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200524 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
525 neighborSolicitation := {
526 typeField := 135,
527 code := 0,
528 checksum := '0000'O,
529 reserved := '00000000'O,
530 targetAddress := target_addr,
531 /* TODO: do we need 'Source link-layer address' ? */
532 options := omit
533 }
534 }
535
536 /* derive ICMPv6 link-local address from lower 64bit of link_id */
537 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
538 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
539 prefixInformation := {
540 typeField := 3,
541 lengthIndicator := 4,
542 prefixLength := prefix_len,
543 reserved1 := ?,
544 a_Bit := ?,
545 l_Bit := ?,
546 validLifetime := ?,
547 preferredLifetime := ?,
548 reserved2 := ?,
549 prefix := prefix
550 }
551 }
552
553 /* template for receiving/matching an ICMPv6 router advertisement */
554 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
555 routerAdvertisement := {
556 typeField := 134,
557 code := 0,
558 checksum := ?,
559 curHopLimit := ?,
560 reserved := ?,
561 o_Bit := '0'B,
562 m_Bit := '0'B,
563 routerLifetime := ?,
564 reachableTime := ?,
565 retransTimer := ?,
566 options := {
567 tr_ICMP6_OptPrefix(prefix, prefix_len)
568 }
569 }
570 }
571
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100572 /* template for receiving/matching an ICMPv6 Destination Unreachable */
573 template PDU_ICMPv6 tr_ICMPv6_DU := {
574 destinationUnreachable := {
575 typeField := 1,
576 code := ?,
577 checksum := ?,
578 unused := ?,
579 originalIpMsg := ?
580 }
581 }
582
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200583 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100584 template PDU_ICMPv6 tr_ICMPv6_ERQ := {
585 echoRequest := {
586 typeField := 128,
587 code := 0,
588 checksum := ?,
589 identifier := ?,
590 sequenceNr := ?,
591 data := ?
592 }
593 }
594
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100595 /* template for receiving/matching an ICMPv6 echo reply */
596 template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
597 echoReply := {
598 typeField := 129,
599 code := 0,
600 checksum := ?,
601 identifier := ?,
602 sequenceNr := ?,
603 data := data
604 }
605 }
606
Harald Welte231b9412017-08-09 17:16:31 +0200607 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
608 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
609 header := {
610 ver := 6,
611 trclass := 0,
612 flabel := 0,
613 plen := 0,
614 nexthead := nexthead,
615 hlim := hlim,
616 srcaddr := srcaddr,
617 dstaddr := dstaddr
618 },
619 ext_headers := omit,
620 payload := payload
621 }
622
623 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
624 return 'FE80000000000000'O & substr(link_id, 8, 8);
625 }
626
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100627 function f_ipv6_global(in OCT16 link_id) return OCT16 {
628 return substr(link_id, 0, 8) & '1234123412341234'O;
629 }
630
631 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
632 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
633 var integer i;
634 var octetstring res := substr(addr, 0, prefix);
635 for (i := prefix; i < lengthof(addr); i := i + 1) {
636 var octetstring a := addr[i] xor4b '11'O;
637 res := res & a;
638 }
639 return res;
640 }
641
Harald Welte231b9412017-08-09 17:16:31 +0200642 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
643 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
644 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
645 }
646
647 /* generate and encode ICMPv6 router solicitation */
648 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
649 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
650 var OCT16 saddr := f_ipv6_link_local(link_id);
651
652 var octetstring tmp;
653 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
654 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
655
656 return f_IPv6_enc(ip6);
657 }
658
659 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
660 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
661 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
662 return f_gen_icmpv6_router_solicitation(interface_id);
663 }
664
665 /* generate and encode ICMPv6 neighbor solicitation */
666 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
667 var octetstring tmp;
668 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
669 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
670 return f_IPv6_enc(ip6);
671 }
672
673 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
674 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
675 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
676 var OCT16 link_local := f_ipv6_link_local(interface_id);
677 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
678
679 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
680 }
681
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100682 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
683 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring {
684 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ));
685 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
686 var octetstring data := f_IPv4_enc(ip4);
687 var OCT2 cksum := f_IPv4_checksum(data);
688 data[10] := cksum[0];
689 data[11] := cksum[1];
690 return data;
691 }
692
693 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
694 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
695 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
696 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
697 var octetstring data := f_IPv6_enc(ip6);
698 return data;
699 }
700
701 /* Wait for ICMPv4 from GTP */
702 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +0200703 var Gtp1uUnitdata ud;
704 T_default.start;
705 alt {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100706 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200707 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200708 setverdict(fail);
709 stop;
710 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100711 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
712 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
713 if (ip4.header.ver != 4) {
714 repeat;
715 }
716 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
717 if (not match(icmp4, expected)) {
718 repeat;
719 }
720 }
721 [] GTPU.receive { setverdict(fail); }
722 [] T_default.timeout { setverdict(fail); }
723 }
724 T_default.stop;
725 }
726
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100727 /* Wait for ICMPv4 echo request from GTP */
728 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
729 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
730 }
731
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100732 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
733 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
734 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
735 }
736
737 /* Wait for ICMPv6 from GTP */
738 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
739 var Gtp1uUnitdata ud;
740 T_default.start;
741 alt {
Harald Welte231b9412017-08-09 17:16:31 +0200742 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200743 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200744 setverdict(fail);
745 stop;
746 }
Harald Welte231b9412017-08-09 17:16:31 +0200747 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
748 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100749 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +0200750 repeat;
751 }
752 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100753 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +0200754 repeat;
755 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100756 /* We are waiting for RA, update ctx */
757 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
758 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
759 log("RA with /64 prefix ", ctx.ip6_prefix);
760 }
Harald Welte231b9412017-08-09 17:16:31 +0200761 }
762 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
763 [] GTPU.receive { setverdict(fail); }
764 [] T_default.timeout { setverdict(fail); }
765 }
766 T_default.stop;
767 }
768
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100769 /* wait for GGSN to send us an ICMPv6 router advertisement */
770 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
771 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
772 }
773
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100774 /* Wait for ICMPv6 echo request from GTP */
775 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
776 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
777 }
778
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100779 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
780 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
781 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
782 }
783
Oliver Smithee6a0882019-03-08 11:05:46 +0100784 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
785 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
786 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
787 return f_gen_icmpv6_router_solicitation(interface_id);
788 }
789
790 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
791 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
792 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
793 var OCT16 link_local := f_ipv6_link_local(interface_id);
794 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
795
796 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
797 }
798
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100799 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
800 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
801 T_default.start;
802 alt {
803 [] GTPU.receive { setverdict(fail); }
804 [] T_default.timeout { }
805 }
806 T_default.stop;
807 }
808
Harald Welte79737b42019-04-10 10:39:30 +0200809 /* list of protocols where we don't accept duplicates */
810 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
811 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
812 var integer i;
813 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
814 if (id == protocol_ids_nodupes[i]) {
815 return false;
816 }
817 }
818 return true;
819 }
820
821 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
822 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
823 var OCT2List protocol_ids := {};
824 var integer i, j;
825 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
826 var OCT2 id := pco.protocols[i].protocolID;
827 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
828 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
829 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
830 }
831 }
832 protocol_ids := protocol_ids & { id };
833 }
834 }
835
Harald Welte0ef285b2017-08-13 20:06:01 +0200836 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +0200837 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200838 f_init();
Harald Welte231b9412017-08-09 17:16:31 +0200839
Harald Welteed097432017-08-13 13:28:49 +0200840 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 +0200841 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +0200842 f_pdp_ctx_del(ctx, '1'B);
843 }
844
Harald Welte0ef285b2017-08-13 20:06:01 +0200845 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +0200846 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
847 f_init();
848
Harald Welteed097432017-08-13 13:28:49 +0200849 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 +0200850 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
851 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100852
Harald Welte79737b42019-04-10 10:39:30 +0200853 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100854 /* verify PCO contains both primary and secondary DNS */
855 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
856 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
857 setverdict(fail, "Primary DNS IPv6 PCO option not found");
858 }
859
860 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
861 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
862 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
863 }
864
Harald Welteed7a1772017-08-09 20:26:20 +0200865 f_pdp_ctx_del(ctx, '1'B);
866 }
867
Harald Welte0ef285b2017-08-13 20:06:01 +0200868 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +0200869 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
870 f_init();
871
Harald Welteed097432017-08-13 13:28:49 +0200872 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 +0200873 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
874 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200875
Harald Welte79737b42019-04-10 10:39:30 +0200876 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +0200877 //f_send_gtpu(ctx, c_router_solicit);
878 //f_send_gtpu(ctx, c_neigh_solicit);
879
880 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
881 f_wait_rtr_adv(ctx);
882 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
883
Harald Welte811651e2017-08-05 15:25:06 +0200884 f_pdp_ctx_del(ctx, '1'B);
Harald Welte94ade362017-08-04 00:36:55 +0200885 }
886
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100887 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
888 Test we can send ICMPv6 ping over GTPU to DNS server. */
889 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
890 f_init();
891 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
892 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
893 f_pdp_ctx_act(ctx);
894
895 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
896 f_wait_rtr_adv(ctx);
897 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
898
899 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
900
901 /* Check if we can use valid link-local src addr. */
902 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
903 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
904 f_wait_icmp6_echo_reply(ctx);
905
906 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
907 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
908 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
909 f_wait_gtpu_fail(ctx);
910
911 /* Check if we can use valid global src addr, should work */
912 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
913 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
914 f_wait_icmp6_echo_reply(ctx);
915
916 /* Assert that packets with wrong global src addr are dropped by GGSN */
917 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
918 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
919 f_wait_gtpu_fail(ctx);
920
921 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped) */
922 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
923 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
924 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
925 f_wait_gtpu_fail(ctx);
926
927 f_pdp_ctx_del(ctx, '1'B);
928 }
929
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100930 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
931 testcase TC_pdp6_clients_interact() runs on GT_CT {
932 f_init();
933 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
934 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
935 f_pdp_ctx_act(ctxA);
936 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
937 f_wait_rtr_adv(ctxA);
938 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
939
940 f_pdp_ctx_act(ctxB);
941 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
942 f_wait_rtr_adv(ctxB);
943 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
944
945 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
946 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
947 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
948 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
949
950 /* Validate if clients can interact using ll addr. */
951 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
952 f_wait_gtpu_fail(ctxB);
953
954 /* Validate if clients can interact using global addr. */
955 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
956 f_wait_gtpu_fail(ctxB);
957
958 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +0200959 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100960 }
961
Harald Welte0ef285b2017-08-13 20:06:01 +0200962 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +0200963 testcase TC_pdp4_act_deact() runs on GT_CT {
964 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200965 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 +0200966 f_pdp_ctx_act(ctx);
967 f_pdp_ctx_del(ctx, '1'B);
968 }
969
Harald Welte0ef285b2017-08-13 20:06:01 +0200970 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +0200971 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
972 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100973 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
974 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +0200975 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 +0200976 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +0200977 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +0200978 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +0100979 /* verify IPCP is at all contained */
980 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
981 setverdict(fail, "IPCP not found in PCO");
982 }
983 /* verify IPCP contains both primary and secondary DNS */
984 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100985 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
986 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
987 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
988 } else {
989 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
990 }
Harald Welte71a36022017-12-04 18:55:58 +0100991 }
Harald Welteed7a1772017-08-09 20:26:20 +0200992 f_pdp_ctx_del(ctx, '1'B);
993 }
994
Harald Weltef8298542019-04-10 10:15:28 +0200995 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
996 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
997 f_init();
998 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
999 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1000 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1001 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1002 f_pdp_ctx_act(ctx);
1003 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1004 /* verify IPCP is at all contained */
1005 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1006 setverdict(fail, "IPCP not found in PCO");
1007 }
1008 /* verify IPCP contains both primary and secondary DNS */
1009 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1010 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1011 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1012 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1013 } else {
1014 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1015 }
1016 }
1017 /* verify that PAP is contained */
1018 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1019 setverdict(fail, "PAP not found in PCO");
1020 }
1021 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1022 if (not match(pap, tr_PAP_AuthAck)) {
1023 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1024 }
1025 f_pdp_ctx_del(ctx, '1'B);
1026 }
1027
Harald Welte0ef285b2017-08-13 20:06:01 +02001028 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001029 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1030 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001031 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 +02001032 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001033 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001034
Harald Welte79737b42019-04-10 10:39:30 +02001035 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001036 /* verify PCO contains both primary and secondary DNS */
1037 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1038 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1039 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1040 }
1041
1042 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1043 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1044 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1045 }
1046
Harald Welteed7a1772017-08-09 20:26:20 +02001047 f_pdp_ctx_del(ctx, '1'B);
1048 }
1049
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001050 /* Test PDP context activation for dynamic IPv4 EUA.
1051 Test we can send ICMPv6 ping over GTPU to DNS server. */
1052 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1053 f_init();
1054 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1055 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1056 f_pdp_ctx_act(ctx);
1057
Harald Welte79737b42019-04-10 10:39:30 +02001058 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001059 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1060
1061 /* Check if we can use valid global src addr, should work */
1062 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1063 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1064 f_wait_icmp4_echo_reply(ctx);
1065
1066 /* Assert that packets with wrong global src addr are dropped by GGSN */
1067 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1068 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1069 f_wait_gtpu_fail(ctx);
1070
1071 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1072 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1073 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1074 f_wait_gtpu_fail(ctx);
1075 f_pdp_ctx_del(ctx, '1'B);
1076 }
1077
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001078 /* Helper function for tests below. */
1079 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001080 f_init();
1081 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1082 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1083 f_pdp_ctx_act(ctxA);
1084 f_pdp_ctx_act(ctxB);
1085 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1086 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1087 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1088 f_wait_icmp4_echo_request(ctxB);
1089
1090 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001091 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001092 }
1093
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001094 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1095 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001096 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001097 f_pdp4_clients_interact();
1098 }
1099
1100 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1101 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001102 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001103 f_pdp4_clients_interact();
1104 }
1105
Harald Weltedca80052017-08-13 20:01:38 +02001106 testcase TC_echo_req_resp() runs on GT_CT {
1107 f_init();
1108 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1109 T_default.start;
1110 alt {
1111 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1112 [] GTPC.receive { repeat; };
1113 [] T_default.timeout { setverdict(fail); }
1114 }
1115 T_default.stop;
1116 }
1117
Philipp Maier33e52612018-05-30 17:22:02 +02001118 /* Test if the parser can cope with PCO that only contain either a
1119 * single primary DNS or a secondary DNS. */
1120 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1121
1122 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1123 * the test is executed.
1124 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1125
1126 f_init();
1127 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1128 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1129 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1130 var octetstring pco_neg_dns;
1131 var octetstring pco_neg_dns_expected;
1132
1133 /* PCO with primary DNS only */
1134 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1135 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001136 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001137 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1138 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1139 /* Note: The prepended hex bytes encode the following information:
1140 * 0x02 = Configuration ACK
1141 * 0x00 = Identifier
1142 * 0x000a = Length
1143 * 0x81 = Type (Primary DNS Server Address)
1144 * 0x06 = Length
1145 * (4 byte IP-Address appended) */
1146 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1147 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1148 }
1149 f_pdp_ctx_del(ctx, '1'B);
1150
1151 /* PCO with secondary DNS only */
Harald Welte7ef6d102021-04-01 21:24:35 +02001152 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001153 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1154 f_pdp_ctx_act(ctx);
1155 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1156 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1157 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1158 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1159 }
1160 f_pdp_ctx_del(ctx, '1'B);
1161 }
1162
1163 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1164 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1165 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1166 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1167
1168 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1169 * the test is executed.
1170 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1171
1172 f_init();
1173 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1174 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1175 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1176 var octetstring pco_neg_dns;
1177 var octetstring pco_neg_dns_expected;
1178
1179 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1180 f_pdp_ctx_act(ctx);
1181
1182 /* Check if primary DNS is contained */
1183 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1184 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1185 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1186 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1187 }
Philipp Maier33e52612018-05-30 17:22:02 +02001188
1189 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001190 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1191 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001192 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1193 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1194 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1195 }
1196 f_pdp_ctx_del(ctx, '1'B);
1197 }
1198
Oliver Smithee6a0882019-03-08 11:05:46 +01001199 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1200 testcase TC_pdp46_act_deact() runs on GT_CT {
1201 f_init();
1202 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1203 f_pdp_ctx_act(ctx);
1204 f_pdp_ctx_del(ctx, '1'B);
1205 }
1206
1207 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1208 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1209 f_init();
1210 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1211 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1212 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1213 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1214 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001215 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001216 /* verify IPCP is at all contained */
1217 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1218 setverdict(fail, "IPCP not found in PCO");
1219 }
Harald Welte79737b42019-04-10 10:39:30 +02001220 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001221 /* verify IPCP contains both primary and secondary IPv4 DNS */
1222 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1223 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1224 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1225 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1226 } else {
1227 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1228 }
1229 }
1230 f_pdp_ctx_del(ctx, '1'B);
1231 }
1232
1233 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1234 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1235 f_init();
1236 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1237 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1238 f_pdp_ctx_act(ctx);
1239
1240 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1241 f_wait_rtr_adv(ctx);
1242 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1243
1244 f_pdp_ctx_del(ctx, '1'B);
1245 }
1246
1247 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1248 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1249 f_init();
1250
1251 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1252 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1253 f_pdp_ctx_act(ctx);
1254
Harald Welte79737b42019-04-10 10:39:30 +02001255 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001256 /* verify PCO contains both primary and secondary IPv4 DNS */
1257 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1258 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1259 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1260 }
1261
1262 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1263 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1264 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1265 }
1266
1267 f_pdp_ctx_del(ctx, '1'B);
1268 }
1269
1270 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1271 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1272 f_init();
1273
1274 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1275 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1276 f_pdp_ctx_act(ctx);
1277
Harald Welte79737b42019-04-10 10:39:30 +02001278 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001279 /* verify PCO contains both primary and secondary IPv6 DNS */
1280 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1281 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1282 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1283 }
1284
1285 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1286 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1287 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1288 }
1289
1290 f_pdp_ctx_del(ctx, '1'B);
1291 }
1292
1293 /* Test PDP context activation for dynamic IPv4v6 EUA.
1294 Test we can send ICMPv6 ping over GTPU to DNS server. */
1295 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1296 f_init();
1297 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1298 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1299 f_pdp_ctx_act(ctx);
1300
1301 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1302
1303 /* Check if we can use valid global src addr, should work */
1304 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1305 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1306 f_wait_icmp4_echo_reply(ctx);
1307
1308 /* Assert that packets with wrong global src addr are dropped by GGSN */
1309 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1310 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1311 f_wait_gtpu_fail(ctx);
1312
1313 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1314 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1315 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1316 f_wait_gtpu_fail(ctx);
1317 f_pdp_ctx_del(ctx, '1'B);
1318 }
1319
1320 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1321 testcase TC_pdp46_clients_interact() runs on GT_CT {
1322 f_init();
1323 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1324 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1325 f_pdp_ctx_act(ctxA);
1326 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1327 f_wait_rtr_adv(ctxA);
1328 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1329
1330 f_pdp_ctx_act(ctxB);
1331 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1332 f_wait_rtr_adv(ctxB);
1333 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1334
1335 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1336 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1337 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1338 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1339
1340 /* Validate if clients can interact using ll addr. */
1341 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1342 f_wait_gtpu_fail(ctxB);
1343
1344 /* Validate if clients can interact using global addr. */
1345 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1346 f_wait_gtpu_fail(ctxB);
1347
1348 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001349 f_pdp_ctx_del(ctxB, '1'B);
Oliver Smithee6a0882019-03-08 11:05:46 +01001350 }
1351
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001352 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
1353 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
1354 f_init();
1355 /* A typical MS first attempts v4v6, and if rejected, then tries v4 and v6 separetly */
1356 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
1357 f_pdp_ctx_act(ctx46, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1358
1359 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1360 f_pdp_ctx_act(ctx4, '80'O); /* Normal accept cause */
1361
1362 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv6Dyn)));
1363 f_pdp_ctx_act(ctx6, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1364
1365 f_pdp_ctx_del(ctx4, '1'B);
1366 }
1367
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001368 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
1369 testcase TC_pdp_act2_recovery() runs on GT_CT {
1370 var Gtp1cUnitdata ud;
1371 var default d;
1372 var boolean ctxA_deleted := false;
1373 var boolean ctxB_created := false;
1374
1375 f_init();
1376 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1377 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1378 f_pdp_ctx_act(ctxA);
1379
1380 g_restart_ctr := int2oct(oct2int(g_restart_ctr) + 1, 1);
1381
1382 log("sending 2nd CreatePDP (recovery increased)");
1383 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
1384 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
1385 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
1386 T_default.start;
1387 d := activate(pingpong());
1388 alt {
1389 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
1390 f_handle_create_req(ctxB, ud);
1391 if (not ctxB_created) {
1392 ctxB_created := true;
1393 setverdict(pass);
1394 } else {
1395 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
1396 }
1397
1398 if (not ctxA_deleted) {
1399 repeat;
1400 }
1401 }
1402 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
1403 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
1404 setverdict(pass);
1405 } else {
1406 setverdict(fail);
1407 }
1408
1409 if (not ctxA_deleted) {
1410 ctxA_deleted := true;
1411 setverdict(pass);
1412 } else {
1413 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
1414 }
1415
1416 if (not ctxB_created) {
1417 repeat;
1418 }
1419 }
1420 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
1421 setverdict(fail, "GGSN dropping still valid pdp ctx");
1422 }
1423 }
1424 deactivate(d);
1425 T_default.stop;
1426
1427 f_pdp_ctx_del(ctxB, '1'B);
1428 }
1429
1430
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001431 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent
1432 responses (60 seconds): If same delete req is sent and duplicate is
1433 detected, saved duplicate response should be sent back. */
1434 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
1435 f_init();
1436 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1437 f_pdp_ctx_act(ctx);
1438 f_pdp_ctx_del(ctx, '1'B);
1439 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
1440 f_sleep(1.0);
1441 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
1442 duplicate. If it was not a duplicate, osmo-ggsn would answer
1443 with a failure since that PDP ctx was already deleted. */
1444 g_c_seq_nr := g_c_seq_nr - 1;
1445 f_pdp_ctx_del(ctx, '1'B);
1446
1447 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
1448 var OCT1 cause_nonexistent := 'C0'O;
1449 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent);
1450 }
1451
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001452 /* Activate PDP context + trigger Recovery procedure through EchoResp */
1453 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
1454 var Gtp1cUnitdata ud;
1455 g_use_echo := true;
1456 f_init();
1457 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1458 f_pdp_ctx_act(ctx);
1459
1460 /* Wait to receive echo request and send initial Restart counter */
1461 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1462 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1463 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1464 };
1465
1466 /* Wait to receive second echo request and send incremented Restart
1467 counter. This will fake a restarted SGSN, and pdp ctx allocated
1468 should be released by GGSN */
1469 g_restart_ctr := int2oct(oct2int(g_restart_ctr) + 1, 1);
1470 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1471 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1472 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1473 };
1474 f_pdp_ctx_exp_del_req(ctx, omit, true);
1475 setverdict(pass);
1476 }
1477
Harald Welte94ade362017-08-04 00:36:55 +02001478 control {
Harald Welteed7a1772017-08-09 20:26:20 +02001479 execute(TC_pdp4_act_deact());
1480 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02001481 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02001482 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001483 execute(TC_pdp4_act_deact_gtpu_access());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001484 execute(TC_pdp4_clients_interact_with_txseq());
1485 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02001486 execute(TC_pdp4_act_deact_with_single_dns());
1487 execute(TC_pdp4_act_deact_with_separate_dns());
Harald Welteed7a1772017-08-09 20:26:20 +02001488
1489 execute(TC_pdp6_act_deact());
1490 execute(TC_pdp6_act_deact_pcodns());
1491 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001492 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001493 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02001494
Oliver Smithee6a0882019-03-08 11:05:46 +01001495 execute(TC_pdp46_act_deact());
1496 execute(TC_pdp46_act_deact_ipcp());
1497 execute(TC_pdp46_act_deact_icmp6());
1498 execute(TC_pdp46_act_deact_pcodns4());
1499 execute(TC_pdp46_act_deact_pcodns6());
1500 execute(TC_pdp46_act_deact_gtpu_access());
1501 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001502 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01001503
Harald Weltedca80052017-08-13 20:01:38 +02001504 execute(TC_echo_req_resp());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001505 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001506 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001507
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01001508 execute(TC_pdp_act_restart_ctr_echo());
Harald Welte94ade362017-08-04 00:36:55 +02001509 }
Harald Welte379d45a2017-08-03 09:55:15 +02001510}