blob: 634534f2febf3b1cff373617bed1aa46dff8496f [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,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +010087 OCT1 ratType optional,
88 UserLocationInformation uli optional
Harald Welte811651e2017-08-05 15:25:06 +020089 }
90
Harald Welte94ade362017-08-04 00:36:55 +020091 type component GT_CT {
92 port GTPC_PT GTPC;
93 port GTPU_PT GTPU;
94
Harald Welte0be142b2017-08-13 13:28:10 +020095 var boolean g_initialized := false;
96
Harald Welte94ade362017-08-04 00:36:55 +020097 var OCT1 g_restart_ctr := '01'O;
98 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +020099 var OCT4 g_sgsn_ip_c;
100 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +0200101 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +0200102 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
103 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +0200104 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +0200105
106 /* next to-be-sent GTP-C sequence number */
107 var uint16_t g_c_seq_nr;
108 /* next to-be-sent GTP-U sequence number */
109 var uint16_t g_d_seq_nr;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200110
111 port TELNETasp_PT GGSNVTY;
Harald Welted2394e92018-04-26 10:21:49 +0200112 var boolean use_gtpu_txseq := false;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200113 var boolean g_use_echo := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200114 }
115
116 private function f_init_vty() runs on GT_CT {
117 map(self:GGSNVTY, system:GGSNVTY);
118 f_vty_set_prompts(GGSNVTY);
119 f_vty_transceive(GGSNVTY, "enable");
120 }
121
122 private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT {
123 f_vty_enter_config(GGSNVTY);
124 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200125
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200126 f_vty_transceive(GGSNVTY, "apn internet");
127 if (enable) {
128 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
129 } else {
130 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
131 }
Pau Espin Pedrol205a3842018-07-06 13:24:14 +0200132 f_vty_transceive(GGSNVTY, "exit");
133
134 f_vty_transceive(GGSNVTY, "apn inet6");
135 if (enable) {
136 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
137 } else {
138 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
139 }
140 f_vty_transceive(GGSNVTY, "exit");
141
142 f_vty_transceive(GGSNVTY, "apn inet46");
143 if (enable) {
144 f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers");
145 } else {
146 f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers");
147 }
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200148 f_vty_transceive(GGSNVTY, "end");
149 }
150
151 private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean {
152 if (expect_gptu_txseq) {
153 if (gtpu.s_bit != '1'B) {
154 log("GTPU sequence number expected but not present")
155 return false;
156 }
157 } else {
158 if (gtpu.s_bit != '0'B) {
159 log("GTPU sequence number not expected but present")
160 return false;
161 }
162 }
163 return true;
Harald Welte94ade362017-08-04 00:36:55 +0200164 }
165
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200166 private function f_vty_enable_echo_interval(boolean enable) runs on GT_CT {
167 f_vty_enter_config(GGSNVTY);
168 f_vty_transceive(GGSNVTY, "ggsn ggsn0");
169 if (enable) {
170 f_vty_transceive(GGSNVTY, "echo-interval 5");
171 } else {
172 f_vty_transceive(GGSNVTY, "no echo-interval");
173 }
174 f_vty_transceive(GGSNVTY, "end");
175 }
176
Harald Welte94ade362017-08-04 00:36:55 +0200177 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +0200178 if (g_initialized == true) {
179 return;
180 }
181 g_initialized := true;
182
Harald Welteddeecbb2017-08-18 22:53:30 +0200183 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
184 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
185
Harald Welte94ade362017-08-04 00:36:55 +0200186 var Result res;
187 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +0200188 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +0200189 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +0200190 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +0200191
192 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +0200193 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +0200194 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +0200195
196 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +0200197 g_c_seq_nr := f_rnd_int(65535);
198 g_d_seq_nr := f_rnd_int(65535);
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200199
200 f_init_vty();
Harald Welte3e0b0392018-04-26 09:46:21 +0200201 f_vty_set_gpdu_txseq(use_gtpu_txseq);
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +0100202 f_vty_enable_echo_interval(g_use_echo);
Harald Welte94ade362017-08-04 00:36:55 +0200203 }
204
Harald Welte94ade362017-08-04 00:36:55 +0200205 /* Altstep implementing responses to any incoming echo requests */
206 altstep pingpong() runs on GT_CT {
207 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200208 var Gtp1uUnitdata udu;
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200209 [g_use_echo] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200210 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200211 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
Harald Welte94ade362017-08-04 00:36:55 +0200212 repeat;
213 };
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200214 [not g_use_echo] GTPC.receive(tr_GTPC_PING(?)) {
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100215 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
216 "GTP Echo Req rceived but not enabled in VTY");
Harald Welte3af89482017-08-04 16:20:23 +0200217 };
Pau Espin Pedrolc04c69e2020-03-03 16:46:29 +0100218 [] T_default.timeout {
219 Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
220 "pinpong T_default timeout");
221 };
Harald Welte94ade362017-08-04 00:36:55 +0200222 }
223
Harald Welte811651e2017-08-05 15:25:06 +0200224 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200225 const octetstring c_ApnInternet := '08696E7465726E6574'O;
226 const octetstring c_ApnInet6 := '05696E657436'O;
227 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200228
Harald Welte811651e2017-08-05 15:25:06 +0200229 /* return random NSAPI */
230 function f_rnd_nsapi() return BIT4 {
231 return int2bit(f_rnd_int(16), 4);
232 }
233
234 /* return random TEI[DC] */
235 function f_rnd_tei() return OCT4 {
236 return int2oct(f_rnd_int(4294967296), 4);
237 }
238
239 /* define an (internal) representation of a PDP context */
240 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100241 EndUserAddress eua, OCT1 ratType := '02'O /* GERAN */) := {
Harald Welte811651e2017-08-05 15:25:06 +0200242 imsi := imsi,
243 msisdn := msisdn,
244 nsapi := f_rnd_nsapi(),
245 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200246 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200247 eua := eua,
248 teid := f_rnd_tei(),
Pau Espin Pedrol38aeffb2022-02-01 20:46:29 +0100249 teic := f_rnd_tei(),
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100250 ratType := ratType,
251 uli := {
252 type_gtpc := '98'O,
253 lengthf := 0 /* filled in by encoder */,
254 geographicLocationType := '00'O /* CGI */,
255 geographicLocation := {
256 geographicLocationCGI := ts_GeographicLocationCGI('262'H, '42F'H, '0001'O, '0002'O)
257 }
258 }
Harald Welte811651e2017-08-05 15:25:06 +0200259 }
260
261 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200262 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200263 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200264 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200265 }
266
267 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200268 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +0200269 if (use_gtpu_txseq) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200270 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
271 g_d_seq_nr := g_d_seq_nr + 1;
272 } else {
273 GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data));
274 }
Harald Welte811651e2017-08-05 15:25:06 +0200275 }
276
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200277 function f_handle_create_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT {
278 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
279 if (exp_cause == '80'O and exp_cause == cpr.cause.causevalue) {
280 /* Check if EUA type corresponds to requested type */
281 if (match(ctx.eua, t_EuaIPv4(?)) and
282 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
283 setverdict(fail);
284 }
285 if (match(ctx.eua, t_EuaIPv6(?)) and
286 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
287 setverdict(fail);
288 }
289 if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and
290 not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) {
291 setverdict(fail);
292 }
293 /* Check if PCO response corresponds to request */
294 if (ispresent(ctx.pco_req)) {
295 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
296 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
297 log("IPv4 DNS Container requested, but missing");
298 setverdict(fail);
299 }
300 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
301 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
302 log("IPv6 DNS Container requested, but missing");
303 setverdict(fail);
304 }
305 }
306 ctx.teid_remote := cpr.teidDataI.teidDataI;
307 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
308 ctx.eua := cpr.endUserAddress;
309 ctx.pco_neg := cpr.protConfigOptions;
310 setverdict(pass);
311 } else if (exp_cause != '80'O and exp_cause == cpr.cause.causevalue) {
312 if (ispresent(cpr.endUserAddress)) {
313 log("EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue));
314 setverdict(fail);
315 }
316 setverdict(pass);
317 } else {
318 setverdict(fail);
319 }
320 }
321
Harald Welte811651e2017-08-05 15:25:06 +0200322 /* send a PDP context activation */
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +0200323 function f_pdp_ctx_act(inout PdpContext ctx, OCT1 exp_cause := '80'O) runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200324 var Gtp1cUnitdata ud;
Harald Welte94ade362017-08-04 00:36:55 +0200325 var default d;
326
327 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200328 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 +0200329 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Pau Espin Pedrolca587f12022-02-02 10:42:01 +0100330 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req, ctx.ratType, ctx.uli));
Harald Welte94ade362017-08-04 00:36:55 +0200331 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200332 d := activate(pingpong());
333 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200334 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +0200335 f_handle_create_req(ctx, ud, exp_cause);
Harald Welte94ade362017-08-04 00:36:55 +0200336 }
337 }
338 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200339 T_default.stop;
Harald Welte94ade362017-08-04 00:36:55 +0200340 }
341
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +0200342 function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT {
343 var Gtp1cUnitdata ud;
344 var default d;
345
346 T_default.start;
347 d := activate(pingpong());
348 alt {
349 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud {
350 if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) {
351 setverdict(pass);
352 } else if (not istemplatekind(expect_cause, "omit") and
353 ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and
354 ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) {
355 setverdict(pass);
356 } else {
357 setverdict(fail);
358 }
359
360 if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
361 setverdict(pass);
362 } else {
363 setverdict(fail);
364 }
365 }
366 }
367 deactivate(d);
368 T_default.stop;
369 }
370
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200371 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 +0200372 var Gtp1cUnitdata ud;
373 var default d;
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200374 var OCT4 expect_teid;
375
376 /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response
377 message with cause value "Non existent" shall be zero. */
378 if (expect_causevalue == 'C0'O) {
379 expect_teid := '00000000'O;
380 } else {
381 expect_teid := ctx.teic;
382 }
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200383
Harald Welte41575e92017-08-13 13:49:57 +0200384 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 +0200385 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200386 d := activate(pingpong());
387 alt {
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +0200388 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud {
389 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200390 setverdict(pass);
391 } else {
392 setverdict(fail);
393 }
394 }
395 }
396 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200397 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200398 }
Harald Welte811651e2017-08-05 15:25:06 +0200399 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
400 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
401 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
402 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200403
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200404 /* template for sending an ICMPv4 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100405 template PDU_ICMP ts_ICMPv4_ERQ := {
406 echo := {
407 type_field := 8,
408 code := 0,
409 checksum := '0000'O,
410 identifier := '0345'O,
411 sequence_number := '0001'O,
412 data := ''O
413 }
414 }
415
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200416 /* template for receiving/matching an ICMPv4 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100417 template PDU_ICMP tr_ICMPv4_ERQ := {
418 echo := {
419 type_field := 8,
420 code := 0,
421 checksum := ?,
422 identifier := ?,
423 sequence_number := ?,
424 data := ?
425 }
426 }
427
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200428 /* template for receiving/matching an ICMPv4 echo reply */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100429 template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
430 echo_reply := {
431 type_field := 0,
432 code := 0,
433 checksum := ?,
434 identifier := ?,
435 sequence_number := ?,
436 data := data
437 }
438 }
439
440 /* template for receiving/matching an ICMPv6 Destination Unreachable */
441 template PDU_ICMP tr_ICMPv4_DU := {
442 destination_unreachable := {
443 type_field := 1,
444 code := ?,
445 checksum := ?,
446 unused := ?,
447 original_ip_msg := ?
448 }
449 }
450
451 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
452 template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
453 header := {
454 ver := 4,
455 hlen := 5,
456 tos := 0,
457 tlen := tlen,
458 id := 35902,
459 res := '0'B,
460 dfrag := '1'B,
461 mfrag := '0'B,
462 foffset := 0,
463 ttl := 64,
464 proto := proto,
465 cksum := 0,
466 srcaddr := srcaddr,
467 dstaddr := dstaddr
468 },
469 ext_headers := omit,
470 payload := payload
471 }
472
Harald Welte231b9412017-08-09 17:16:31 +0200473 /* template to generate a 'Prefix Information' ICMPv6 option */
474 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
475 prefixInformation := {
476 typeField := 3,
477 lengthIndicator := 8,
478 prefixLength := prefix_len,
479 reserved1 := '000000'B,
480 a_Bit := '0'B,
481 l_Bit := '0'B,
482 validLifetime := oct2int('FFFFFFFF'O),
483 preferredLifetime := oct2int('FFFFFFFF'O),
484 reserved2 := '00000000'O,
485 prefix := prefix
486 }
487 }
488
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200489 /* template for sending an ICMPv6 echo request */
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100490 template PDU_ICMPv6 ts_ICMPv6_ERQ := {
491 echoRequest := {
492 typeField := 128,
493 code := 0,
494 checksum := '0000'O,
495 identifier := 0,
496 sequenceNr := 0,
497 data := ''O
498 }
499 }
500
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200501 /* template for sending an ICMPv6 router solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200502 template PDU_ICMPv6 ts_ICMPv6_RS := {
503 routerSolicitation := {
504 typeField := 133,
505 code := 0,
506 checksum := '0000'O,
507 reserved := '00000000'O,
508 /* TODO: do we need 'Source link-layer address' ? */
509 options := omit
510 }
511 }
512
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200513 /* template for sending an ICMPv6 router advertisement */
Harald Welte231b9412017-08-09 17:16:31 +0200514 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
515 routerAdvertisement := {
516 typeField := 134,
517 code := 0,
518 checksum := '0000'O,
519 curHopLimit := ?,
520 reserved := '000000'B,
521 o_Bit := '0'B,
522 m_Bit := '0'B,
523 routerLifetime := oct2int('FFFF'O),
524 reachableTime := oct2int('FFFFFFFF'O),
525 retransTimer := oct2int('FFFFFFFF'O),
526 options := {
527 ts_ICMP6_OptPrefix(prefix, prefix_len)
528 }
529 }
530 }
531
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200532 /* template for sending an ICMPv6 neighbor solicitation */
Harald Welte231b9412017-08-09 17:16:31 +0200533 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
534 neighborSolicitation := {
535 typeField := 135,
536 code := 0,
537 checksum := '0000'O,
538 reserved := '00000000'O,
539 targetAddress := target_addr,
540 /* TODO: do we need 'Source link-layer address' ? */
541 options := omit
542 }
543 }
544
545 /* derive ICMPv6 link-local address from lower 64bit of link_id */
546 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
547 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
548 prefixInformation := {
549 typeField := 3,
550 lengthIndicator := 4,
551 prefixLength := prefix_len,
552 reserved1 := ?,
553 a_Bit := ?,
554 l_Bit := ?,
555 validLifetime := ?,
556 preferredLifetime := ?,
557 reserved2 := ?,
558 prefix := prefix
559 }
560 }
561
562 /* template for receiving/matching an ICMPv6 router advertisement */
563 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
564 routerAdvertisement := {
565 typeField := 134,
566 code := 0,
567 checksum := ?,
568 curHopLimit := ?,
569 reserved := ?,
570 o_Bit := '0'B,
571 m_Bit := '0'B,
572 routerLifetime := ?,
573 reachableTime := ?,
574 retransTimer := ?,
575 options := {
576 tr_ICMP6_OptPrefix(prefix, prefix_len)
577 }
578 }
579 }
580
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100581 /* template for receiving/matching an ICMPv6 Destination Unreachable */
582 template PDU_ICMPv6 tr_ICMPv6_DU := {
583 destinationUnreachable := {
584 typeField := 1,
585 code := ?,
586 checksum := ?,
587 unused := ?,
588 originalIpMsg := ?
589 }
590 }
591
Stefan Sperling6cd217e2018-03-30 15:17:34 +0200592 /* template for receiving/matching an ICMPv6 echo request */
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100593 template PDU_ICMPv6 tr_ICMPv6_ERQ := {
594 echoRequest := {
595 typeField := 128,
596 code := 0,
597 checksum := ?,
598 identifier := ?,
599 sequenceNr := ?,
600 data := ?
601 }
602 }
603
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100604 /* template for receiving/matching an ICMPv6 echo reply */
605 template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
606 echoReply := {
607 typeField := 129,
608 code := 0,
609 checksum := ?,
610 identifier := ?,
611 sequenceNr := ?,
612 data := data
613 }
614 }
615
Harald Welte231b9412017-08-09 17:16:31 +0200616 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
617 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
618 header := {
619 ver := 6,
620 trclass := 0,
621 flabel := 0,
622 plen := 0,
623 nexthead := nexthead,
624 hlim := hlim,
625 srcaddr := srcaddr,
626 dstaddr := dstaddr
627 },
628 ext_headers := omit,
629 payload := payload
630 }
631
632 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
633 return 'FE80000000000000'O & substr(link_id, 8, 8);
634 }
635
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100636 function f_ipv6_global(in OCT16 link_id) return OCT16 {
637 return substr(link_id, 0, 8) & '1234123412341234'O;
638 }
639
640 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
641 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
642 var integer i;
643 var octetstring res := substr(addr, 0, prefix);
644 for (i := prefix; i < lengthof(addr); i := i + 1) {
645 var octetstring a := addr[i] xor4b '11'O;
646 res := res & a;
647 }
648 return res;
649 }
650
Harald Welte231b9412017-08-09 17:16:31 +0200651 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
652 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
653 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
654 }
655
656 /* generate and encode ICMPv6 router solicitation */
657 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
658 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
659 var OCT16 saddr := f_ipv6_link_local(link_id);
660
661 var octetstring tmp;
662 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
663 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
664
665 return f_IPv6_enc(ip6);
666 }
667
668 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
669 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
670 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
671 return f_gen_icmpv6_router_solicitation(interface_id);
672 }
673
674 /* generate and encode ICMPv6 neighbor solicitation */
675 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
676 var octetstring tmp;
677 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
678 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
679 return f_IPv6_enc(ip6);
680 }
681
682 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
683 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
684 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
685 var OCT16 link_local := f_ipv6_link_local(interface_id);
686 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
687
688 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
689 }
690
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100691 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
692 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring {
693 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ));
694 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
695 var octetstring data := f_IPv4_enc(ip4);
696 var OCT2 cksum := f_IPv4_checksum(data);
697 data[10] := cksum[0];
698 data[11] := cksum[1];
699 return data;
700 }
701
702 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
703 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
704 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
705 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
706 var octetstring data := f_IPv6_enc(ip6);
707 return data;
708 }
709
710 /* Wait for ICMPv4 from GTP */
711 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +0200712 var Gtp1uUnitdata ud;
713 T_default.start;
714 alt {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100715 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200716 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200717 setverdict(fail);
718 stop;
719 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100720 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
721 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
722 if (ip4.header.ver != 4) {
723 repeat;
724 }
725 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
726 if (not match(icmp4, expected)) {
727 repeat;
728 }
729 }
730 [] GTPU.receive { setverdict(fail); }
731 [] T_default.timeout { setverdict(fail); }
732 }
733 T_default.stop;
734 }
735
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100736 /* Wait for ICMPv4 echo request from GTP */
737 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
738 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
739 }
740
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100741 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
742 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
743 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
744 }
745
746 /* Wait for ICMPv6 from GTP */
747 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
748 var Gtp1uUnitdata ud;
749 T_default.start;
750 alt {
Harald Welte231b9412017-08-09 17:16:31 +0200751 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
Harald Welte3e0b0392018-04-26 09:46:21 +0200752 if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) {
Stefan Sperlingc479e4f2018-04-03 19:34:16 +0200753 setverdict(fail);
754 stop;
755 }
Harald Welte231b9412017-08-09 17:16:31 +0200756 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
757 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100758 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +0200759 repeat;
760 }
761 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100762 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +0200763 repeat;
764 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100765 /* We are waiting for RA, update ctx */
766 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
767 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
768 log("RA with /64 prefix ", ctx.ip6_prefix);
769 }
Harald Welte231b9412017-08-09 17:16:31 +0200770 }
771 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
772 [] GTPU.receive { setverdict(fail); }
773 [] T_default.timeout { setverdict(fail); }
774 }
775 T_default.stop;
776 }
777
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100778 /* wait for GGSN to send us an ICMPv6 router advertisement */
779 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
780 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
781 }
782
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100783 /* Wait for ICMPv6 echo request from GTP */
784 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
785 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
786 }
787
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100788 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
789 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
790 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
791 }
792
Oliver Smithee6a0882019-03-08 11:05:46 +0100793 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
794 function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring {
795 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
796 return f_gen_icmpv6_router_solicitation(interface_id);
797 }
798
799 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
800 function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring {
801 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address;
802 var OCT16 link_local := f_ipv6_link_local(interface_id);
803 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
804
805 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
806 }
807
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100808 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
809 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
810 T_default.start;
811 alt {
812 [] GTPU.receive { setverdict(fail); }
813 [] T_default.timeout { }
814 }
815 T_default.stop;
816 }
817
Harald Welte79737b42019-04-10 10:39:30 +0200818 /* list of protocols where we don't accept duplicates */
819 const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O };
820 private function f_PCO_permits_duplicates(OCT2 id) return boolean {
821 var integer i;
822 for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) {
823 if (id == protocol_ids_nodupes[i]) {
824 return false;
825 }
826 }
827 return true;
828 }
829
830 /* ensure that every given protocol Identifier exist only exactly once in the PCO */
831 function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) {
832 var OCT2List protocol_ids := {};
833 var integer i, j;
834 for (i := 0; i < lengthof(pco.protocols); i := i+1) {
835 var OCT2 id := pco.protocols[i].protocolID;
836 for (j := 0; j < lengthof(protocol_ids); j := j+1) {
837 if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) {
838 setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols);
839 }
840 }
841 protocol_ids := protocol_ids & { id };
842 }
843 }
844
Harald Welte0ef285b2017-08-13 20:06:01 +0200845 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +0200846 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200847 f_init();
Harald Welte231b9412017-08-09 17:16:31 +0200848
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 Welte811651e2017-08-05 15:25:06 +0200850 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +0200851 f_pdp_ctx_del(ctx, '1'B);
852 }
853
Harald Welte0ef285b2017-08-13 20:06:01 +0200854 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +0200855 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
856 f_init();
857
Harald Welteed097432017-08-13 13:28:49 +0200858 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 +0200859 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
860 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100861
Harald Welte79737b42019-04-10 10:39:30 +0200862 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100863 /* verify PCO contains both primary and secondary DNS */
864 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
865 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
866 setverdict(fail, "Primary DNS IPv6 PCO option not found");
867 }
868
869 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
870 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
871 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
872 }
873
Harald Welteed7a1772017-08-09 20:26:20 +0200874 f_pdp_ctx_del(ctx, '1'B);
875 }
876
Harald Welte0ef285b2017-08-13 20:06:01 +0200877 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +0200878 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
879 f_init();
880
Harald Welteed097432017-08-13 13:28:49 +0200881 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 +0200882 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
883 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200884
Harald Welte79737b42019-04-10 10:39:30 +0200885 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte231b9412017-08-09 17:16:31 +0200886 //f_send_gtpu(ctx, c_router_solicit);
887 //f_send_gtpu(ctx, c_neigh_solicit);
888
889 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
890 f_wait_rtr_adv(ctx);
891 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
892
Harald Welte811651e2017-08-05 15:25:06 +0200893 f_pdp_ctx_del(ctx, '1'B);
Harald Welte94ade362017-08-04 00:36:55 +0200894 }
895
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100896 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
897 Test we can send ICMPv6 ping over GTPU to DNS server. */
898 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
899 f_init();
900 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
901 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
902 f_pdp_ctx_act(ctx);
903
904 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
905 f_wait_rtr_adv(ctx);
906 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
907
908 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
909
910 /* Check if we can use valid link-local src addr. */
911 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
912 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
913 f_wait_icmp6_echo_reply(ctx);
914
915 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
916 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
917 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
918 f_wait_gtpu_fail(ctx);
919
920 /* Check if we can use valid global src addr, should work */
921 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
922 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
923 f_wait_icmp6_echo_reply(ctx);
924
925 /* Assert that packets with wrong global src addr are dropped by GGSN */
926 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
927 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
928 f_wait_gtpu_fail(ctx);
929
930 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped) */
931 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
932 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
933 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
934 f_wait_gtpu_fail(ctx);
935
936 f_pdp_ctx_del(ctx, '1'B);
937 }
938
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100939 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
940 testcase TC_pdp6_clients_interact() runs on GT_CT {
941 f_init();
942 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
943 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
944 f_pdp_ctx_act(ctxA);
945 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
946 f_wait_rtr_adv(ctxA);
947 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
948
949 f_pdp_ctx_act(ctxB);
950 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
951 f_wait_rtr_adv(ctxB);
952 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
953
954 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
955 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
956 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
957 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
958
959 /* Validate if clients can interact using ll addr. */
960 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
961 f_wait_gtpu_fail(ctxB);
962
963 /* Validate if clients can interact using global addr. */
964 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
965 f_wait_gtpu_fail(ctxB);
966
967 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +0200968 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100969 }
970
Harald Welte0ef285b2017-08-13 20:06:01 +0200971 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +0200972 testcase TC_pdp4_act_deact() runs on GT_CT {
973 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200974 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 +0200975 f_pdp_ctx_act(ctx);
976 f_pdp_ctx_del(ctx, '1'B);
977 }
978
Harald Welte0ef285b2017-08-13 20:06:01 +0200979 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +0200980 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
981 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100982 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
983 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +0200984 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 +0200985 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +0200986 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +0200987 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Harald Welte71a36022017-12-04 18:55:58 +0100988 /* verify IPCP is at all contained */
989 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
990 setverdict(fail, "IPCP not found in PCO");
991 }
992 /* verify IPCP contains both primary and secondary DNS */
993 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100994 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
995 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
996 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
997 } else {
998 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
999 }
Harald Welte71a36022017-12-04 18:55:58 +01001000 }
Harald Welteed7a1772017-08-09 20:26:20 +02001001 f_pdp_ctx_del(ctx, '1'B);
1002 }
1003
Harald Weltef8298542019-04-10 10:15:28 +02001004 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */
1005 testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT {
1006 f_init();
1007 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1008 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1009 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1010 ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS);
1011 f_pdp_ctx_act(ctx);
1012 f_PCO_ensure_no_duplicates(ctx.pco_neg);
1013 /* verify IPCP is at all contained */
1014 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1015 setverdict(fail, "IPCP not found in PCO");
1016 }
1017 /* verify IPCP contains both primary and secondary DNS */
1018 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1019 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1020 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1021 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1022 } else {
1023 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1024 }
1025 }
1026 /* verify that PAP is contained */
1027 if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) {
1028 setverdict(fail, "PAP not found in PCO");
1029 }
1030 var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O));
1031 if (not match(pap, tr_PAP_AuthAck)) {
1032 setverdict(fail, "PAP isn't an AuthenticateAck: ", pap);
1033 }
1034 f_pdp_ctx_del(ctx, '1'B);
1035 }
1036
Harald Welte0ef285b2017-08-13 20:06:01 +02001037 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001038 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1039 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001040 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 +02001041 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001042 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001043
Harald Welte79737b42019-04-10 10:39:30 +02001044 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001045 /* verify PCO contains both primary and secondary DNS */
1046 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1047 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1048 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1049 }
1050
1051 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1052 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1053 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1054 }
1055
Harald Welteed7a1772017-08-09 20:26:20 +02001056 f_pdp_ctx_del(ctx, '1'B);
1057 }
1058
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001059 /* Test PDP context activation for dynamic IPv4 EUA.
1060 Test we can send ICMPv6 ping over GTPU to DNS server. */
1061 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1062 f_init();
1063 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1064 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1065 f_pdp_ctx_act(ctx);
1066
Harald Welte79737b42019-04-10 10:39:30 +02001067 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001068 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1069
1070 /* Check if we can use valid global src addr, should work */
1071 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1072 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1073 f_wait_icmp4_echo_reply(ctx);
1074
1075 /* Assert that packets with wrong global src addr are dropped by GGSN */
1076 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1077 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1078 f_wait_gtpu_fail(ctx);
1079
1080 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1081 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1082 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1083 f_wait_gtpu_fail(ctx);
1084 f_pdp_ctx_del(ctx, '1'B);
1085 }
1086
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001087 /* Helper function for tests below. */
1088 function f_pdp4_clients_interact() runs on GT_CT {
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001089 f_init();
1090 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1091 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1092 f_pdp_ctx_act(ctxA);
1093 f_pdp_ctx_act(ctxB);
1094 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1095 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1096 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1097 f_wait_icmp4_echo_request(ctxB);
1098
1099 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001100 f_pdp_ctx_del(ctxB, '1'B);
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001101 }
1102
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001103 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1104 testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001105 use_gtpu_txseq := true;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001106 f_pdp4_clients_interact();
1107 }
1108
1109 /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */
1110 testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT {
Harald Welte3e0b0392018-04-26 09:46:21 +02001111 use_gtpu_txseq := false;
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001112 f_pdp4_clients_interact();
1113 }
1114
Harald Weltedca80052017-08-13 20:01:38 +02001115 testcase TC_echo_req_resp() runs on GT_CT {
1116 f_init();
1117 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1118 T_default.start;
1119 alt {
1120 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1121 [] GTPC.receive { repeat; };
1122 [] T_default.timeout { setverdict(fail); }
1123 }
1124 T_default.stop;
1125 }
1126
Philipp Maier33e52612018-05-30 17:22:02 +02001127 /* Test if the parser can cope with PCO that only contain either a
1128 * single primary DNS or a secondary DNS. */
1129 testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT {
1130
1131 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1132 * the test is executed.
1133 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1134
1135 f_init();
1136 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1137 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1138 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1139 var octetstring pco_neg_dns;
1140 var octetstring pco_neg_dns_expected;
1141
1142 /* PCO with primary DNS only */
1143 ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP);
1144 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001145 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Philipp Maier33e52612018-05-30 17:22:02 +02001146 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1147 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1148 /* Note: The prepended hex bytes encode the following information:
1149 * 0x02 = Configuration ACK
1150 * 0x00 = Identifier
1151 * 0x000a = Length
1152 * 0x81 = Type (Primary DNS Server Address)
1153 * 0x06 = Length
1154 * (4 byte IP-Address appended) */
1155 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1156 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1157 }
1158 f_pdp_ctx_del(ctx, '1'B);
1159
1160 /* PCO with secondary DNS only */
Harald Welte7ef6d102021-04-01 21:24:35 +02001161 ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Philipp Maier33e52612018-05-30 17:22:02 +02001162 ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP);
1163 f_pdp_ctx_act(ctx);
1164 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1165 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1166 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1167 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1168 }
1169 f_pdp_ctx_del(ctx, '1'B);
1170 }
1171
1172 /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container.
1173 * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run
1174 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */
1175 testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT {
1176
1177 /* Note: an unpatched osmo-ggsn version will enter an endless-loop when
1178 * the test is executed.
1179 * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
1180
1181 f_init();
1182 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1183 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1184 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1185 var octetstring pco_neg_dns;
1186 var octetstring pco_neg_dns_expected;
1187
1188 ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP);
1189 f_pdp_ctx_act(ctx);
1190
1191 /* Check if primary DNS is contained */
1192 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1);
1193 pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1
1194 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1195 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1196 }
Philipp Maier33e52612018-05-30 17:22:02 +02001197
1198 /* Check if secondary DNS is contained */
Stefan Sperling8e7a3962018-07-19 19:24:38 +02001199 /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */
1200 pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2);
Philipp Maier33e52612018-05-30 17:22:02 +02001201 pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2
1202 if (not match(pco_neg_dns, pco_neg_dns_expected)) {
1203 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1204 }
1205 f_pdp_ctx_del(ctx, '1'B);
1206 }
1207
Oliver Smithee6a0882019-03-08 11:05:46 +01001208 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */
1209 testcase TC_pdp46_act_deact() runs on GT_CT {
1210 f_init();
1211 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1212 f_pdp_ctx_act(ctx);
1213 f_pdp_ctx_del(ctx, '1'B);
1214 }
1215
1216 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */
1217 testcase TC_pdp46_act_deact_ipcp() runs on GT_CT {
1218 f_init();
1219 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1220 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1221 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1222 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
1223 f_pdp_ctx_act(ctx);
Harald Welte79737b42019-04-10 10:39:30 +02001224 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001225 /* verify IPCP is at all contained */
1226 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1227 setverdict(fail, "IPCP not found in PCO");
1228 }
Harald Welte79737b42019-04-10 10:39:30 +02001229 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001230 /* verify IPCP contains both primary and secondary IPv4 DNS */
1231 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
1232 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1233 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1234 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1235 } else {
1236 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1237 }
1238 }
1239 f_pdp_ctx_del(ctx, '1'B);
1240 }
1241
1242 /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
1243 testcase TC_pdp46_act_deact_icmp6() runs on GT_CT {
1244 f_init();
1245 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1246 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1247 f_pdp_ctx_act(ctx);
1248
1249 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx));
1250 f_wait_rtr_adv(ctx);
1251 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx));
1252
1253 f_pdp_ctx_del(ctx, '1'B);
1254 }
1255
1256 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */
1257 testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT {
1258 f_init();
1259
1260 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1261 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1262 f_pdp_ctx_act(ctx);
1263
Harald Welte79737b42019-04-10 10:39:30 +02001264 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001265 /* verify PCO contains both primary and secondary IPv4 DNS */
1266 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1267 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1268 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1269 }
1270
1271 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1272 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1273 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1274 }
1275
1276 f_pdp_ctx_del(ctx, '1'B);
1277 }
1278
1279 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */
1280 testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT {
1281 f_init();
1282
1283 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1284 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1285 f_pdp_ctx_act(ctx);
1286
Harald Welte79737b42019-04-10 10:39:30 +02001287 f_PCO_ensure_no_duplicates(ctx.pco_neg);
Oliver Smithee6a0882019-03-08 11:05:46 +01001288 /* verify PCO contains both primary and secondary IPv6 DNS */
1289 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1290 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1291 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1292 }
1293
1294 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1295 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1296 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1297 }
1298
1299 f_pdp_ctx_del(ctx, '1'B);
1300 }
1301
1302 /* Test PDP context activation for dynamic IPv4v6 EUA.
1303 Test we can send ICMPv6 ping over GTPU to DNS server. */
1304 testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT {
1305 f_init();
1306 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1307 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1308 f_pdp_ctx_act(ctx);
1309
1310 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1311
1312 /* Check if we can use valid global src addr, should work */
1313 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address;
1314 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1315 f_wait_icmp4_echo_reply(ctx);
1316
1317 /* Assert that packets with wrong global src addr are dropped by GGSN */
1318 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1319 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1320 f_wait_gtpu_fail(ctx);
1321
1322 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1323 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1324 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1325 f_wait_gtpu_fail(ctx);
1326 f_pdp_ctx_del(ctx, '1'B);
1327 }
1328
1329 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1330 testcase TC_pdp46_clients_interact() runs on GT_CT {
1331 f_init();
1332 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1333 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn)));
1334 f_pdp_ctx_act(ctxA);
1335 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA));
1336 f_wait_rtr_adv(ctxA);
1337 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA));
1338
1339 f_pdp_ctx_act(ctxB);
1340 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB));
1341 f_wait_rtr_adv(ctxB);
1342 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB));
1343
1344 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1345 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1346 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1347 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address);
1348
1349 /* Validate if clients can interact using ll addr. */
1350 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1351 f_wait_gtpu_fail(ctxB);
1352
1353 /* Validate if clients can interact using global addr. */
1354 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1355 f_wait_gtpu_fail(ctxB);
1356
1357 f_pdp_ctx_del(ctxA, '1'B);
Pau Espin Pedrolbb2bb062019-09-03 12:28:12 +02001358 f_pdp_ctx_del(ctxB, '1'B);
Oliver Smithee6a0882019-03-08 11:05:46 +01001359 }
1360
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001361 /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */
1362 testcase TC_pdp46_act_deact_apn4() runs on GT_CT {
1363 f_init();
1364 /* A typical MS first attempts v4v6, and if rejected, then tries v4 and v6 separetly */
1365 var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn)));
1366 f_pdp_ctx_act(ctx46, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1367
1368 var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1369 f_pdp_ctx_act(ctx4, '80'O); /* Normal accept cause */
1370
1371 var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv6Dyn)));
1372 f_pdp_ctx_act(ctx6, 'DC'O); /* Cause: Unknown PDP address or PDP type */
1373
1374 f_pdp_ctx_del(ctx4, '1'B);
1375 }
1376
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001377 /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */
1378 testcase TC_pdp_act2_recovery() runs on GT_CT {
1379 var Gtp1cUnitdata ud;
1380 var default d;
1381 var boolean ctxA_deleted := false;
1382 var boolean ctxB_created := false;
1383
1384 f_init();
1385 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1386 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1387 f_pdp_ctx_act(ctxA);
1388
1389 g_restart_ctr := int2oct(oct2int(g_restart_ctr) + 1, 1);
1390
1391 log("sending 2nd CreatePDP (recovery increased)");
1392 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr,
1393 ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn,
1394 g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req));
1395 T_default.start;
1396 d := activate(pingpong());
1397 alt {
1398 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud {
1399 f_handle_create_req(ctxB, ud);
1400 if (not ctxB_created) {
1401 ctxB_created := true;
1402 setverdict(pass);
1403 } else {
1404 setverdict(fail, "Repeated createPDPContextResponse(ctxB)");
1405 }
1406
1407 if (not ctxA_deleted) {
1408 repeat;
1409 }
1410 }
1411 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud {
1412 if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) {
1413 setverdict(pass);
1414 } else {
1415 setverdict(fail);
1416 }
1417
1418 if (not ctxA_deleted) {
1419 ctxA_deleted := true;
1420 setverdict(pass);
1421 } else {
1422 setverdict(fail, "Repeated deletePDPContextRequest(ctxA)");
1423 }
1424
1425 if (not ctxB_created) {
1426 repeat;
1427 }
1428 }
1429 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud {
1430 setverdict(fail, "GGSN dropping still valid pdp ctx");
1431 }
1432 }
1433 deactivate(d);
1434 T_default.stop;
1435
1436 f_pdp_ctx_del(ctxB, '1'B);
1437 }
1438
1439
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001440 /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent
1441 responses (60 seconds): If same delete req is sent and duplicate is
1442 detected, saved duplicate response should be sent back. */
1443 testcase TC_act_deact_retrans_duplicate() runs on GT_CT {
1444 f_init();
1445 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1446 f_pdp_ctx_act(ctx);
1447 f_pdp_ctx_del(ctx, '1'B);
1448 /* leave some time in between to make sure retransmit response queue keeps packets for a while */
1449 f_sleep(1.0);
1450 /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a
1451 duplicate. If it was not a duplicate, osmo-ggsn would answer
1452 with a failure since that PDP ctx was already deleted. */
1453 g_c_seq_nr := g_c_seq_nr - 1;
1454 f_pdp_ctx_del(ctx, '1'B);
1455
1456 /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */
1457 var OCT1 cause_nonexistent := 'C0'O;
1458 f_pdp_ctx_del(ctx, '1'B, cause_nonexistent);
1459 }
1460
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001461 /* Activate PDP context + trigger Recovery procedure through EchoResp */
1462 testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT {
1463 var Gtp1cUnitdata ud;
1464 g_use_echo := true;
1465 f_init();
1466 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1467 f_pdp_ctx_act(ctx);
1468
1469 /* Wait to receive echo request and send initial Restart counter */
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
1475 /* Wait to receive second echo request and send incremented Restart
1476 counter. This will fake a restarted SGSN, and pdp ctx allocated
1477 should be released by GGSN */
1478 g_restart_ctr := int2oct(oct2int(g_restart_ctr) + 1, 1);
1479 GTPC.receive(tr_GTPC_PING(?)) -> value ud {
1480 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
1481 GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr));
1482 };
1483 f_pdp_ctx_exp_del_req(ctx, omit, true);
1484 setverdict(pass);
1485 }
1486
Harald Welte94ade362017-08-04 00:36:55 +02001487 control {
Harald Welteed7a1772017-08-09 20:26:20 +02001488 execute(TC_pdp4_act_deact());
1489 execute(TC_pdp4_act_deact_ipcp());
Harald Weltef8298542019-04-10 10:15:28 +02001490 execute(TC_pdp4_act_deact_ipcp_pap_broken());
Harald Welteed7a1772017-08-09 20:26:20 +02001491 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001492 execute(TC_pdp4_act_deact_gtpu_access());
Stefan Sperlingc479e4f2018-04-03 19:34:16 +02001493 execute(TC_pdp4_clients_interact_with_txseq());
1494 execute(TC_pdp4_clients_interact_without_txseq());
Philipp Maier33e52612018-05-30 17:22:02 +02001495 execute(TC_pdp4_act_deact_with_single_dns());
1496 execute(TC_pdp4_act_deact_with_separate_dns());
Harald Welteed7a1772017-08-09 20:26:20 +02001497
1498 execute(TC_pdp6_act_deact());
1499 execute(TC_pdp6_act_deact_pcodns());
1500 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001501 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001502 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02001503
Oliver Smithee6a0882019-03-08 11:05:46 +01001504 execute(TC_pdp46_act_deact());
1505 execute(TC_pdp46_act_deact_ipcp());
1506 execute(TC_pdp46_act_deact_icmp6());
1507 execute(TC_pdp46_act_deact_pcodns4());
1508 execute(TC_pdp46_act_deact_pcodns6());
1509 execute(TC_pdp46_act_deact_gtpu_access());
1510 execute(TC_pdp46_clients_interact());
Pau Espin Pedrol22d597f2019-08-21 16:16:58 +02001511 execute(TC_pdp46_act_deact_apn4());
Oliver Smithee6a0882019-03-08 11:05:46 +01001512
Harald Weltedca80052017-08-13 20:01:38 +02001513 execute(TC_echo_req_resp());
Pau Espin Pedrolfa1ca022019-08-23 18:58:53 +02001514 execute(TC_pdp_act2_recovery());
Pau Espin Pedrol9a5f42f2019-05-27 20:04:35 +02001515 execute(TC_act_deact_retrans_duplicate());
Pau Espin Pedrol6916ec42019-08-23 16:15:07 +02001516
Pau Espin Pedrol6f319f92020-01-03 20:18:57 +01001517 execute(TC_pdp_act_restart_ctr_echo());
Harald Welte94ade362017-08-04 00:36:55 +02001518 }
Harald Welte379d45a2017-08-03 09:55:15 +02001519}