Harald Welte | 379d45a | 2017-08-03 09:55:15 +0200 | [diff] [blame] | 1 | module GGSN_Tests { |
| 2 | |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 3 | /* 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 Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 15 | import from General_Types all; |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 16 | import from Osmocom_Types all; |
Pau Espin Pedrol | c04c69e | 2020-03-03 16:46:29 +0100 | [diff] [blame] | 17 | import from Misc_Helpers all; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 18 | 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 Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame] | 22 | import from GTP_Templates all; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 23 | import from GTPC_Types all; |
| 24 | import from GTPU_Types all; |
Harald Welte | 71a3602 | 2017-12-04 18:55:58 +0100 | [diff] [blame] | 25 | import from IPCP_Types all; |
Harald Welte | f829854 | 2019-04-10 10:15:28 +0200 | [diff] [blame] | 26 | import from PAP_Types all; |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 27 | import from IP_Types all; |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 28 | import from ICMP_Types all; |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 29 | import from ICMPv6_Types all; |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 30 | import from Native_Functions all; |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 31 | import from Osmocom_VTY_Functions all; |
| 32 | import from TELNETasp_PortType all; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 33 | |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 34 | import from DIAMETER_Types all; |
| 35 | import from DIAMETER_Templates all; |
| 36 | import from DIAMETER_Emulation all; |
| 37 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 38 | const integer GTP0_PORT := 3386; |
| 39 | const integer GTP1C_PORT := 2123; |
| 40 | const integer GTP1U_PORT := 2152; |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 41 | const integer PCRF_PORT := 3868; |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 42 | |
Pau Espin Pedrol | c1b1ddf | 2022-01-19 18:10:30 +0100 | [diff] [blame] | 43 | type enumerated GGSN_Impl { |
| 44 | GGSN_IMPL_OSMOCOM, |
| 45 | GGSN_IMPL_OPEN5GS |
| 46 | }; |
| 47 | |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 48 | modulepar { |
Stefan Sperling | cb782b9 | 2018-04-03 16:03:15 +0200 | [diff] [blame] | 49 | /* Default IP addresses. May be overridden by GGSN_Tests configuration files. */ |
| 50 | |
| 51 | /* The SGSN simulated by TTCN3 will bind to these addresses for GTP control and GTP user planes. */ |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 52 | charstring m_bind_ip_gtpc := "127.23.42.1"; |
| 53 | charstring m_bind_ip_gtpu := "127.23.42.1"; |
| 54 | |
Stefan Sperling | cb782b9 | 2018-04-03 16:03:15 +0200 | [diff] [blame] | 55 | /* Addresses the GGSN which is being tested is listening on for SGSN connections. */ |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 56 | charstring m_ggsn_ip_gtpc := "127.0.0.6"; |
| 57 | charstring m_ggsn_ip_gtpu := "127.0.0.6"; |
Pau Espin Pedrol | f69a438 | 2018-01-29 13:09:00 +0100 | [diff] [blame] | 58 | |
Stefan Sperling | cb782b9 | 2018-04-03 16:03:15 +0200 | [diff] [blame] | 59 | /* |
| 60 | * Our tests expect to see these DNS servers in 'Create PDP context responses' sent by the GGSN. |
| 61 | * These addresses must therefore match 'ip[v6] dns' options configured in osmo-ggsn.conf. |
| 62 | * |
| 63 | * These addresses are not expected to serve actual DNS requests. However, tests may expect to be |
| 64 | * able to ping these addresses (currently, IPv4 addresses must respond with an ICMP 'echo reply', |
| 65 | * and IPv6 addresses may respond with either ICMPv6 'echo reply' or 'destination unreachable'). |
| 66 | */ |
Pau Espin Pedrol | f69a438 | 2018-01-29 13:09:00 +0100 | [diff] [blame] | 67 | charstring m_ggsn_ip4_dns1 := "192.168.100.1" |
| 68 | charstring m_ggsn_ip4_dns2 := "8.8.8.8" |
Pau Espin Pedrol | 363ba48 | 2018-01-29 18:42:00 +0100 | [diff] [blame] | 69 | charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888" |
| 70 | charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844" |
Stefan Sperling | cb782b9 | 2018-04-03 16:03:15 +0200 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * Additional address ranges are defined in osmo-ggsn.conf from which addresses are assigned |
| 74 | * to MS "behind" the simulated SGSN. These addresses appear on tun devices used by osmo-ggsn. |
| 75 | * The tests expect to be able to send ping packets between any two simulated MS within the same |
| 76 | * address range. This requires IP forwarding to be enabled on the corresponding tun interfaces. |
| 77 | */ |
Pau Espin Pedrol | c1b1ddf | 2022-01-19 18:10:30 +0100 | [diff] [blame] | 78 | |
| 79 | GGSN_Impl m_ggsn_impl := GGSN_IMPL_OSMOCOM; |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 80 | } |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 81 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 82 | type set PdpContext { |
| 83 | hexstring imsi, |
| 84 | octetstring msisdn optional, |
| 85 | octetstring apn, |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 86 | ProtConfigOptions pco_req optional, |
| 87 | ProtConfigOptions pco_neg optional, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 88 | EndUserAddress eua, |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 89 | OCT16 ip6_prefix optional, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 90 | BIT4 nsapi, |
| 91 | /* TEI (Data) local side */ |
| 92 | OCT4 teid, |
| 93 | /* TEI (Control) local side */ |
| 94 | OCT4 teic, |
| 95 | /* TEI (Data) remote side */ |
| 96 | OCT4 teid_remote, |
| 97 | /* TEI (Control) remote side */ |
Pau Espin Pedrol | 38aeffb | 2022-02-01 20:46:29 +0100 | [diff] [blame] | 98 | OCT4 teic_remote, |
Pau Espin Pedrol | ca587f1 | 2022-02-02 10:42:01 +0100 | [diff] [blame] | 99 | OCT1 ratType optional, |
| 100 | UserLocationInformation uli optional |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 101 | } |
| 102 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 103 | type component GT_CT { |
| 104 | port GTPC_PT GTPC; |
| 105 | port GTPU_PT GTPU; |
| 106 | |
Harald Welte | 0be142b | 2017-08-13 13:28:10 +0200 | [diff] [blame] | 107 | var boolean g_initialized := false; |
| 108 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 109 | var OCT1 g_restart_ctr := '01'O; |
| 110 | /* FIXME: unify with g_bind_ip + parse from config file */ |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 111 | var OCT4 g_sgsn_ip_c; |
| 112 | var OCT4 g_sgsn_ip_u; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 113 | /* FIXME: parse remName from config file */ |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 114 | var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT }; |
| 115 | var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT }; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 116 | timer T_default := 3.0; |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 117 | |
| 118 | /* next to-be-sent GTP-C sequence number */ |
| 119 | var uint16_t g_c_seq_nr; |
| 120 | /* next to-be-sent GTP-U sequence number */ |
| 121 | var uint16_t g_d_seq_nr; |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 122 | |
| 123 | port TELNETasp_PT GGSNVTY; |
Harald Welte | d2394e9 | 2018-04-26 10:21:49 +0200 | [diff] [blame] | 124 | var boolean use_gtpu_txseq := false; |
Pau Espin Pedrol | 0511802 | 2022-02-17 19:49:13 +0100 | [diff] [blame] | 125 | var integer g_use_echo_intval := 0; /* 0 = disabled */ |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 126 | |
| 127 | /* emulated PCRF, used with m_ggsn_impl = GGSN_IMPL_OPEN5GS */ |
Pau Espin Pedrol | 45d5702 | 2022-03-08 13:49:02 +0100 | [diff] [blame^] | 128 | var DIAMETER_Emulation_CT vc_Gx; |
| 129 | port DIAMETER_PT Gx_UNIT; |
| 130 | port DIAMETEREM_PROC_PT Gx_PROC; |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | private function f_init_vty() runs on GT_CT { |
| 134 | map(self:GGSNVTY, system:GGSNVTY); |
| 135 | f_vty_set_prompts(GGSNVTY); |
| 136 | f_vty_transceive(GGSNVTY, "enable"); |
| 137 | } |
| 138 | |
| 139 | private function f_vty_set_gpdu_txseq(boolean enable) runs on GT_CT { |
| 140 | f_vty_enter_config(GGSNVTY); |
| 141 | f_vty_transceive(GGSNVTY, "ggsn ggsn0"); |
Pau Espin Pedrol | 205a384 | 2018-07-06 13:24:14 +0200 | [diff] [blame] | 142 | |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 143 | f_vty_transceive(GGSNVTY, "apn internet"); |
| 144 | if (enable) { |
| 145 | f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers"); |
| 146 | } else { |
| 147 | f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers"); |
| 148 | } |
Pau Espin Pedrol | 205a384 | 2018-07-06 13:24:14 +0200 | [diff] [blame] | 149 | f_vty_transceive(GGSNVTY, "exit"); |
| 150 | |
| 151 | f_vty_transceive(GGSNVTY, "apn inet6"); |
| 152 | if (enable) { |
| 153 | f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers"); |
| 154 | } else { |
| 155 | f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers"); |
| 156 | } |
| 157 | f_vty_transceive(GGSNVTY, "exit"); |
| 158 | |
| 159 | f_vty_transceive(GGSNVTY, "apn inet46"); |
| 160 | if (enable) { |
| 161 | f_vty_transceive(GGSNVTY, "g-pdu tx-sequence-numbers"); |
| 162 | } else { |
| 163 | f_vty_transceive(GGSNVTY, "no g-pdu tx-sequence-numbers"); |
| 164 | } |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 165 | f_vty_transceive(GGSNVTY, "end"); |
| 166 | } |
| 167 | |
| 168 | private function f_verify_gtpu_txseq(in PDU_GTPU gtpu, in boolean expect_gptu_txseq) return boolean { |
| 169 | if (expect_gptu_txseq) { |
| 170 | if (gtpu.s_bit != '1'B) { |
| 171 | log("GTPU sequence number expected but not present") |
| 172 | return false; |
| 173 | } |
| 174 | } else { |
| 175 | if (gtpu.s_bit != '0'B) { |
| 176 | log("GTPU sequence number not expected but present") |
| 177 | return false; |
| 178 | } |
| 179 | } |
| 180 | return true; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 181 | } |
| 182 | |
Pau Espin Pedrol | 0511802 | 2022-02-17 19:49:13 +0100 | [diff] [blame] | 183 | private function f_vty_enable_echo_interval(integer intval_sec) runs on GT_CT { |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 184 | f_vty_enter_config(GGSNVTY); |
| 185 | f_vty_transceive(GGSNVTY, "ggsn ggsn0"); |
Pau Espin Pedrol | 0511802 | 2022-02-17 19:49:13 +0100 | [diff] [blame] | 186 | if (intval_sec > 0) { |
| 187 | f_vty_transceive(GGSNVTY, "echo-interval " & int2str(intval_sec)); |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 188 | } else { |
| 189 | f_vty_transceive(GGSNVTY, "no echo-interval"); |
| 190 | } |
| 191 | f_vty_transceive(GGSNVTY, "end"); |
| 192 | } |
| 193 | |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 194 | private function DiameterForwardUnitdataCallback(PDU_DIAMETER msg) |
| 195 | runs on DIAMETER_Emulation_CT return template PDU_DIAMETER { |
| 196 | DIAMETER_UNIT.send(msg); |
| 197 | return omit; |
| 198 | } |
| 199 | |
| 200 | private function f_init_diameter(charstring id) runs on GT_CT { |
| 201 | var DIAMETEROps ops := { |
| 202 | create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback), |
| 203 | unitdata_cb := refers(DiameterForwardUnitdataCallback), |
| 204 | raw := true /* handler mode (single component for all IMSI)) */ |
| 205 | }; |
| 206 | var DIAMETER_conn_parameters pars := { |
| 207 | remote_ip := m_ggsn_ip_gtpc, |
| 208 | remote_sctp_port := -1, |
| 209 | local_ip := m_bind_ip_gtpc, |
| 210 | local_sctp_port := PCRF_PORT, |
Pau Espin Pedrol | 45d5702 | 2022-03-08 13:49:02 +0100 | [diff] [blame^] | 211 | origin_host := "pcrf.localdomain", |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 212 | origin_realm := "localdomain", |
| 213 | vendor_app_id := c_DIAMETER_3GPP_Gx_AID |
| 214 | }; |
Pau Espin Pedrol | 45d5702 | 2022-03-08 13:49:02 +0100 | [diff] [blame^] | 215 | vc_Gx := DIAMETER_Emulation_CT.create(id); |
| 216 | map(vc_Gx:DIAMETER, system:DIAMETER_CODEC_PT); |
| 217 | connect(vc_Gx:DIAMETER_UNIT, self:Gx_UNIT); |
| 218 | connect(vc_Gx:DIAMETER_PROC, self:Gx_PROC); |
| 219 | vc_Gx.start(DIAMETER_Emulation.main(ops, pars, id)); |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 220 | |
Pau Espin Pedrol | 45d5702 | 2022-03-08 13:49:02 +0100 | [diff] [blame^] | 221 | f_diameter_wait_capability(Gx_UNIT); |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 222 | /* Give some time for our emulation to get out of SUSPECT list of SUT (3 watchdong ping-pongs): |
| 223 | * RFC6733 sec 5.1 |
| 224 | * RFC3539 sec 3.4.1 [5] |
| 225 | * https://github.com/freeDiameter/freeDiameter/blob/master/libfdcore/p_psm.c#L49 |
| 226 | */ |
| 227 | f_sleep(1.0); |
| 228 | } |
| 229 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 230 | function f_init() runs on GT_CT { |
Harald Welte | 0be142b | 2017-08-13 13:28:10 +0200 | [diff] [blame] | 231 | if (g_initialized == true) { |
| 232 | return; |
| 233 | } |
| 234 | g_initialized := true; |
| 235 | |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 236 | g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc); |
| 237 | g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu); |
| 238 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 239 | var Result res; |
| 240 | map(self:GTPC, system:GTPC); |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 241 | res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}}); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 242 | log("GTP1C ConnectionID: ", res.connId); |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 243 | g_peer_c.connId := res.connId; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 244 | |
| 245 | map(self:GTPU, system:GTPU); |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 246 | res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}}); |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 247 | g_peer_u.connId:= res.connId; |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 248 | |
| 249 | g_restart_ctr := f_rnd_octstring(1); |
Harald Welte | 11dbc7b | 2017-08-13 18:57:56 +0200 | [diff] [blame] | 250 | g_c_seq_nr := f_rnd_int(65535); |
| 251 | g_d_seq_nr := f_rnd_int(65535); |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 252 | |
Pau Espin Pedrol | c1b1ddf | 2022-01-19 18:10:30 +0100 | [diff] [blame] | 253 | if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) { |
| 254 | f_init_vty(); |
| 255 | f_vty_set_gpdu_txseq(use_gtpu_txseq); |
Pau Espin Pedrol | 0511802 | 2022-02-17 19:49:13 +0100 | [diff] [blame] | 256 | f_vty_enable_echo_interval(g_use_echo_intval); |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 257 | } else if (m_ggsn_impl == GGSN_IMPL_OPEN5GS) { |
| 258 | f_init_diameter(testcasename()); |
Pau Espin Pedrol | c1b1ddf | 2022-01-19 18:10:30 +0100 | [diff] [blame] | 259 | } |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 260 | } |
| 261 | |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 262 | function f_shutdown_helper() runs on GT_CT { |
| 263 | /* Sleep N3_REQUESTS * T3_REQUEST seconds, nowadays 5*3=15s. |
| 264 | * This ensures all retransmit queues are cleared before jumping |
| 265 | * into next tests, hence avoding situation where a test resuses |
| 266 | * a seqnum still in the GGSN's resp queue (dup req detector). |
| 267 | * See OS#5485 avout decreasing time. We could also add a new |
| 268 | * VTY command that calls gtp_clear_queues() */ |
| 269 | f_sleep(15.0); |
| 270 | setverdict(pass); |
| 271 | } |
| 272 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 273 | /* Altstep implementing responses to any incoming echo requests */ |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 274 | private altstep pingpong() runs on GT_CT { |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 275 | var Gtp1cUnitdata ud; |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 276 | var Gtp1uUnitdata udu; |
Pau Espin Pedrol | 0511802 | 2022-02-17 19:49:13 +0100 | [diff] [blame] | 277 | [g_use_echo_intval > 0] GTPC.receive(tr_GTPC_PING(?)) -> value ud { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 278 | var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber); |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 279 | GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr)); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 280 | repeat; |
| 281 | }; |
Pau Espin Pedrol | 0511802 | 2022-02-17 19:49:13 +0100 | [diff] [blame] | 282 | [g_use_echo_intval == 0] GTPC.receive(tr_GTPC_PING(?)) { |
Pau Espin Pedrol | c04c69e | 2020-03-03 16:46:29 +0100 | [diff] [blame] | 283 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 284 | "GTP Echo Req rceived but not enabled in VTY"); |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 285 | }; |
Pau Espin Pedrol | c04c69e | 2020-03-03 16:46:29 +0100 | [diff] [blame] | 286 | [] T_default.timeout { |
| 287 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 288 | "pinpong T_default timeout"); |
| 289 | }; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 290 | } |
| 291 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 292 | /* 'internet' in DNS encoding */ |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 293 | const octetstring c_ApnInternet := '08696E7465726E6574'O; |
| 294 | const octetstring c_ApnInet6 := '05696E657436'O; |
| 295 | const octetstring c_ApnInet46 := '06696E65743436'O; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 296 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 297 | /* return random NSAPI */ |
| 298 | function f_rnd_nsapi() return BIT4 { |
| 299 | return int2bit(f_rnd_int(16), 4); |
| 300 | } |
| 301 | |
| 302 | /* return random TEI[DC] */ |
| 303 | function f_rnd_tei() return OCT4 { |
| 304 | return int2oct(f_rnd_int(4294967296), 4); |
| 305 | } |
| 306 | |
| 307 | /* define an (internal) representation of a PDP context */ |
| 308 | template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn, |
Pau Espin Pedrol | 38aeffb | 2022-02-01 20:46:29 +0100 | [diff] [blame] | 309 | EndUserAddress eua, OCT1 ratType := '02'O /* GERAN */) := { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 310 | imsi := imsi, |
| 311 | msisdn := msisdn, |
| 312 | nsapi := f_rnd_nsapi(), |
| 313 | apn := apn, |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 314 | pco_req := omit, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 315 | eua := eua, |
| 316 | teid := f_rnd_tei(), |
Pau Espin Pedrol | 38aeffb | 2022-02-01 20:46:29 +0100 | [diff] [blame] | 317 | teic := f_rnd_tei(), |
Pau Espin Pedrol | ca587f1 | 2022-02-02 10:42:01 +0100 | [diff] [blame] | 318 | ratType := ratType, |
| 319 | uli := { |
| 320 | type_gtpc := '98'O, |
| 321 | lengthf := 0 /* filled in by encoder */, |
| 322 | geographicLocationType := '00'O /* CGI */, |
| 323 | geographicLocation := { |
| 324 | geographicLocationCGI := ts_GeographicLocationCGI('262'H, '42F'H, '0001'O, '0002'O) |
| 325 | } |
| 326 | } |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* send GTP-C for a given context and increment sequence number */ |
Harald Welte | 41575e9 | 2017-08-13 13:49:57 +0200 | [diff] [blame] | 330 | function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 331 | GTPC.send(data); |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 332 | g_c_seq_nr := g_c_seq_nr + 1; |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /* send GTP-U for a given context and increment sequence number */ |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 336 | function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT { |
Harald Welte | 3e0b039 | 2018-04-26 09:46:21 +0200 | [diff] [blame] | 337 | if (use_gtpu_txseq) { |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 338 | GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data)); |
| 339 | g_d_seq_nr := g_d_seq_nr + 1; |
| 340 | } else { |
| 341 | GTPU.send(ts_GTP1U_GPDU(g_peer_u, omit, ctx.teid_remote, data)); |
| 342 | } |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 343 | } |
| 344 | |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 345 | function f_handle_create_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in template OCT1 exp_cause := '80'O) runs on GT_CT { |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 346 | var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse; |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 347 | |
| 348 | if (not match(cpr.cause.causevalue, exp_cause)) { |
| 349 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 350 | "CreatePDPContextResp: cause expectancies didn't match"); |
| 351 | } |
| 352 | |
| 353 | if (cpr.cause.causevalue == '80'O) { /* Accepted */ |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 354 | /* Check if EUA type corresponds to requested type */ |
| 355 | if (match(ctx.eua, t_EuaIPv4(?)) and |
| 356 | not match(cpr.endUserAddress, tr_EuaIPv4(?))){ |
Pau Espin Pedrol | 8ad031a | 2022-02-16 17:33:43 +0100 | [diff] [blame] | 357 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 358 | "EUAv4 expectancies didn't match"); |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 359 | } |
| 360 | if (match(ctx.eua, t_EuaIPv6(?)) and |
| 361 | not match(cpr.endUserAddress, tr_EuaIPv6(?))) { |
Pau Espin Pedrol | 8ad031a | 2022-02-16 17:33:43 +0100 | [diff] [blame] | 362 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 363 | "EUAv6 expectancies didn't match"); |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 364 | } |
| 365 | if (match(ctx.eua, t_EuaIPv4v6(?, ?)) and |
| 366 | not match(cpr.endUserAddress, tr_EuaIPv4v6(?, ?))) { |
Pau Espin Pedrol | 8ad031a | 2022-02-16 17:33:43 +0100 | [diff] [blame] | 367 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 368 | "EUAv4v6 expectancies didn't match"); |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 369 | } |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 370 | } else if (cpr.cause.causevalue == '81'O) { /* Cause: New PDP type due to network preference */ |
| 371 | /* ETSI TS 129 060 7.3.2 Create PDP Context Response. OS#5449 */ |
| 372 | /* This should only happen if EUA requested type is v4v6: */ |
| 373 | if (not ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) { |
| 374 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 375 | "Cause not expected when requesting a non v4v6 EUA"); |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 376 | } |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 377 | if (not match(cpr.endUserAddress, (tr_EuaIPv4(?), tr_EuaIPv6(?)))) { |
| 378 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 379 | "Cause not expected when requesting+receiving EUAv4v6"); |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 380 | } |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 381 | } else { |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 382 | if (ispresent(cpr.endUserAddress)) { |
| 383 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 384 | "EUA received on createPDPContextResponse cause=" & oct2str(cpr.cause.causevalue)); |
| 385 | } |
| 386 | setverdict(pass); |
| 387 | return; |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 388 | } |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 389 | |
| 390 | /* Check if PCO response corresponds to request */ |
| 391 | if (ispresent(ctx.pco_req)) { |
| 392 | if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and |
| 393 | not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) { |
| 394 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 395 | "IPv4 DNS Container requested, but missing"); |
| 396 | } |
| 397 | if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and |
| 398 | not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) { |
| 399 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 400 | "IPv6 DNS Container requested, but missing"); |
| 401 | } |
| 402 | } |
| 403 | ctx.teid_remote := cpr.teidDataI.teidDataI; |
| 404 | ctx.teic_remote := cpr.teidControlPlane.teidControlPlane; |
| 405 | ctx.eua := cpr.endUserAddress; |
| 406 | ctx.pco_neg := cpr.protConfigOptions; |
| 407 | setverdict(pass); |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 408 | } |
| 409 | |
Pau Espin Pedrol | cd326c5 | 2022-02-14 18:57:43 +0100 | [diff] [blame] | 410 | function f_handle_update_req(inout PdpContext ctx, in Gtp1cUnitdata ud, in OCT1 exp_cause := '80'O) runs on GT_CT { |
| 411 | var UpdatePDPContextResponseGGSN upr := ud.gtpc.gtpc_pdu.updatePDPContextResponse.updatePDPContextResponseGGSN; |
| 412 | if (exp_cause == '80'O and exp_cause == upr.cause.causevalue) { |
| 413 | ctx.teid_remote := upr.teidDataI.teidDataI; |
| 414 | ctx.teic_remote := upr.teidControlPlane.teidControlPlane; |
| 415 | if (ispresent(upr.protConfigOptions)) { |
| 416 | ctx.pco_neg := upr.protConfigOptions; |
| 417 | } |
| 418 | setverdict(pass); |
| 419 | } else if (exp_cause != '80'O and exp_cause == upr.cause.causevalue) { |
| 420 | setverdict(pass); |
| 421 | } else { |
Pau Espin Pedrol | 8ad031a | 2022-02-16 17:33:43 +0100 | [diff] [blame] | 422 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 423 | "UpdatePDPContextResp: cause expectancies didn't match"); |
Pau Espin Pedrol | cd326c5 | 2022-02-14 18:57:43 +0100 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 427 | private altstep as_DIA_CCR(DCC_NONE_CC_Request_Type req_type) runs on GT_CT { |
| 428 | var PDU_DIAMETER rx_dia; |
Pau Espin Pedrol | 45d5702 | 2022-03-08 13:49:02 +0100 | [diff] [blame^] | 429 | [] Gx_UNIT.receive(tr_DIA_CCR(req_type := req_type)) -> value rx_dia { |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 430 | var template (omit) AVP avp; |
| 431 | var octetstring sess_id; |
| 432 | var AVP_Unsigned32 req_num; |
| 433 | |
| 434 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id); |
| 435 | sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id); |
| 436 | |
| 437 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_DCC_NONE_CC_Request_Number); |
| 438 | req_num := valueof(avp.avp_data.avp_DCC_NONE_CC_Request_Number); |
| 439 | |
Pau Espin Pedrol | 45d5702 | 2022-03-08 13:49:02 +0100 | [diff] [blame^] | 440 | Gx_UNIT.send(ts_DIA_CCA(rx_dia.hop_by_hop_id, rx_dia.end_to_end_id, sess_id, |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 441 | req_type, req_num)); |
| 442 | } |
Pau Espin Pedrol | 45d5702 | 2022-03-08 13:49:02 +0100 | [diff] [blame^] | 443 | [] Gx_UNIT.receive(PDU_DIAMETER:?) -> value rx_dia { |
Pau Espin Pedrol | 8ad031a | 2022-02-16 17:33:43 +0100 | [diff] [blame] | 444 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 445 | log2str("Received unexpected DIAMETER ", rx_dia)); |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 449 | /* send a PDP context activation */ |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 450 | function f_pdp_ctx_act(inout PdpContext ctx, template OCT1 exp_cause := '80'O) runs on GT_CT return CreatePDPContextResponse { |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 451 | var Gtp1cUnitdata ud; |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 452 | var CreatePDPContextResponse cpr; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 453 | var default d; |
| 454 | |
| 455 | log("sending CreatePDP"); |
Harald Welte | 41575e9 | 2017-08-13 13:49:57 +0200 | [diff] [blame] | 456 | f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx.imsi, g_restart_ctr, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 457 | ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn, |
Pau Espin Pedrol | ca587f1 | 2022-02-02 10:42:01 +0100 | [diff] [blame] | 458 | g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req, ctx.ratType, ctx.uli)); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 459 | T_default.start; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 460 | d := activate(pingpong()); |
Pau Espin Pedrol | 45d5702 | 2022-03-08 13:49:02 +0100 | [diff] [blame^] | 461 | if (Gx_PROC.checkstate("Connected")) { |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 462 | as_DIA_CCR(INITIAL_REQUEST); |
| 463 | } |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 464 | alt { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 465 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud { |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 466 | f_handle_create_req(ctx, ud, exp_cause); |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 467 | cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 468 | } |
| 469 | } |
| 470 | deactivate(d); |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 471 | T_default.stop; |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 472 | return cpr; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 473 | } |
| 474 | |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 475 | function f_pdp_ctx_exp_del_req(PdpContext ctx, template (omit) OCT1 expect_cause := omit, boolean expect_teardown := false) runs on GT_CT { |
| 476 | var Gtp1cUnitdata ud; |
| 477 | var default d; |
| 478 | |
| 479 | T_default.start; |
| 480 | d := activate(pingpong()); |
| 481 | alt { |
| 482 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctx.teic)) -> value ud { |
| 483 | if (istemplatekind(expect_cause, "omit") and not ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue)) { |
| 484 | setverdict(pass); |
| 485 | } else if (not istemplatekind(expect_cause, "omit") and |
| 486 | ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue) and |
| 487 | ud.gtpc.gtpc_pdu.deletePDPContextRequest.cause.causevalue == valueof(expect_cause)) { |
| 488 | setverdict(pass); |
| 489 | } else { |
Pau Espin Pedrol | 8ad031a | 2022-02-16 17:33:43 +0100 | [diff] [blame] | 490 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 491 | "DeletePDPContextReq: cause expectancies didn't match"); |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | if (expect_teardown == ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) { |
| 495 | setverdict(pass); |
| 496 | } else { |
| 497 | setverdict(fail); |
Pau Espin Pedrol | 8ad031a | 2022-02-16 17:33:43 +0100 | [diff] [blame] | 498 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 499 | "DeletePDPContextReq: tearDownIndicator expectancies didn't match"); |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | } |
| 503 | deactivate(d); |
| 504 | T_default.stop; |
| 505 | } |
| 506 | |
Pau Espin Pedrol | 10ec96e | 2022-02-09 17:03:15 +0100 | [diff] [blame] | 507 | function f_pdp_ctx_del(PdpContext ctx, template BIT1 teardown_ind, OCT1 expect_causevalue := '80'O, boolean expect_diameter := true) runs on GT_CT { |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 508 | var Gtp1cUnitdata ud; |
| 509 | var default d; |
Pau Espin Pedrol | 9a5f42f | 2019-05-27 20:04:35 +0200 | [diff] [blame] | 510 | var OCT4 expect_teid; |
| 511 | |
| 512 | /* 3GPP TS 29.060 sec 7.3.6 specifies TEID used in response |
| 513 | message with cause value "Non existent" shall be zero. */ |
| 514 | if (expect_causevalue == 'C0'O) { |
| 515 | expect_teid := '00000000'O; |
| 516 | } else { |
| 517 | expect_teid := ctx.teic; |
| 518 | } |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 519 | |
Harald Welte | 41575e9 | 2017-08-13 13:49:57 +0200 | [diff] [blame] | 520 | f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, ctx.teic_remote, ctx.nsapi, teardown_ind)); |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 521 | T_default.start; |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 522 | d := activate(pingpong()); |
Pau Espin Pedrol | 45d5702 | 2022-03-08 13:49:02 +0100 | [diff] [blame^] | 523 | if (Gx_PROC.checkstate("Connected") and expect_diameter) { |
Pau Espin Pedrol | 0bcfd9d | 2022-02-02 11:01:35 +0100 | [diff] [blame] | 524 | as_DIA_CCR(TERMINATION_REQUEST); |
| 525 | } |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 526 | alt { |
Pau Espin Pedrol | 9a5f42f | 2019-05-27 20:04:35 +0200 | [diff] [blame] | 527 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, expect_teid)) -> value ud { |
| 528 | if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == expect_causevalue) { |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 529 | setverdict(pass); |
| 530 | } else { |
Pau Espin Pedrol | 8ad031a | 2022-02-16 17:33:43 +0100 | [diff] [blame] | 531 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 532 | "DeletePDPContextResp: cause expectancies didn't match"); |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | } |
| 536 | deactivate(d); |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 537 | T_default.stop; |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 538 | } |
Pau Espin Pedrol | cd326c5 | 2022-02-14 18:57:43 +0100 | [diff] [blame] | 539 | |
| 540 | /* send a Update PdP Context Request, expect Response */ |
| 541 | function f_pdp_ctx_update(inout PdpContext ctx, OCT1 exp_cause := '80'O, template (omit) OCT4 new_teid := omit, template (omit) OCT4 new_teic := omit) runs on GT_CT { |
| 542 | var Gtp1cUnitdata ud; |
| 543 | var default d; |
| 544 | |
| 545 | if (not istemplatekind(new_teid, "omit")) { |
| 546 | ctx.teid := valueof(new_teid); |
| 547 | } |
| 548 | if (not istemplatekind(new_teic, "omit")) { |
| 549 | ctx.teic := valueof(new_teic); |
| 550 | } |
| 551 | |
| 552 | log("sending UpdatePDP"); |
| 553 | f_send_gtpc(ts_GTPC_UpdatePDP(g_peer_c, ctx.teic_remote, g_c_seq_nr, ctx.imsi, g_restart_ctr, |
| 554 | ctx.teid, ctx.teic, ctx.nsapi, g_sgsn_ip_c, g_sgsn_ip_u, |
| 555 | ctx.pco_req, ctx.ratType, ctx.uli)); |
| 556 | T_default.start; |
| 557 | d := activate(pingpong()); |
| 558 | alt { |
| 559 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, updatePDPContextResponse, ctx.teic)) -> value ud { |
| 560 | f_handle_update_req(ctx, ud, exp_cause); |
| 561 | } |
| 562 | } |
| 563 | deactivate(d); |
| 564 | T_default.stop; |
| 565 | } |
| 566 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 567 | /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */ |
| 568 | const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O; |
| 569 | /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */ |
| 570 | const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O; |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 571 | |
Stefan Sperling | 6cd217e | 2018-03-30 15:17:34 +0200 | [diff] [blame] | 572 | /* template for sending an ICMPv4 echo request */ |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 573 | template PDU_ICMP ts_ICMPv4_ERQ := { |
| 574 | echo := { |
| 575 | type_field := 8, |
| 576 | code := 0, |
| 577 | checksum := '0000'O, |
| 578 | identifier := '0345'O, |
| 579 | sequence_number := '0001'O, |
| 580 | data := ''O |
| 581 | } |
| 582 | } |
| 583 | |
Stefan Sperling | 6cd217e | 2018-03-30 15:17:34 +0200 | [diff] [blame] | 584 | /* template for receiving/matching an ICMPv4 echo request */ |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 585 | template PDU_ICMP tr_ICMPv4_ERQ := { |
| 586 | echo := { |
| 587 | type_field := 8, |
| 588 | code := 0, |
| 589 | checksum := ?, |
| 590 | identifier := ?, |
| 591 | sequence_number := ?, |
| 592 | data := ? |
| 593 | } |
| 594 | } |
| 595 | |
Stefan Sperling | 6cd217e | 2018-03-30 15:17:34 +0200 | [diff] [blame] | 596 | /* template for receiving/matching an ICMPv4 echo reply */ |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 597 | template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := { |
| 598 | echo_reply := { |
| 599 | type_field := 0, |
| 600 | code := 0, |
| 601 | checksum := ?, |
| 602 | identifier := ?, |
| 603 | sequence_number := ?, |
| 604 | data := data |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | /* template for receiving/matching an ICMPv6 Destination Unreachable */ |
| 609 | template PDU_ICMP tr_ICMPv4_DU := { |
| 610 | destination_unreachable := { |
| 611 | type_field := 1, |
| 612 | code := ?, |
| 613 | checksum := ?, |
| 614 | unused := ?, |
| 615 | original_ip_msg := ? |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */ |
| 620 | template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := { |
| 621 | header := { |
| 622 | ver := 4, |
| 623 | hlen := 5, |
| 624 | tos := 0, |
| 625 | tlen := tlen, |
| 626 | id := 35902, |
| 627 | res := '0'B, |
| 628 | dfrag := '1'B, |
| 629 | mfrag := '0'B, |
| 630 | foffset := 0, |
| 631 | ttl := 64, |
| 632 | proto := proto, |
| 633 | cksum := 0, |
| 634 | srcaddr := srcaddr, |
| 635 | dstaddr := dstaddr |
| 636 | }, |
| 637 | ext_headers := omit, |
| 638 | payload := payload |
| 639 | } |
| 640 | |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 641 | /* template to generate a 'Prefix Information' ICMPv6 option */ |
| 642 | template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := { |
| 643 | prefixInformation := { |
| 644 | typeField := 3, |
| 645 | lengthIndicator := 8, |
| 646 | prefixLength := prefix_len, |
| 647 | reserved1 := '000000'B, |
| 648 | a_Bit := '0'B, |
| 649 | l_Bit := '0'B, |
| 650 | validLifetime := oct2int('FFFFFFFF'O), |
| 651 | preferredLifetime := oct2int('FFFFFFFF'O), |
| 652 | reserved2 := '00000000'O, |
| 653 | prefix := prefix |
| 654 | } |
| 655 | } |
| 656 | |
Stefan Sperling | 6cd217e | 2018-03-30 15:17:34 +0200 | [diff] [blame] | 657 | /* template for sending an ICMPv6 echo request */ |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 658 | template PDU_ICMPv6 ts_ICMPv6_ERQ := { |
| 659 | echoRequest := { |
| 660 | typeField := 128, |
| 661 | code := 0, |
| 662 | checksum := '0000'O, |
| 663 | identifier := 0, |
| 664 | sequenceNr := 0, |
| 665 | data := ''O |
| 666 | } |
| 667 | } |
| 668 | |
Stefan Sperling | 6cd217e | 2018-03-30 15:17:34 +0200 | [diff] [blame] | 669 | /* template for sending an ICMPv6 router solicitation */ |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 670 | template PDU_ICMPv6 ts_ICMPv6_RS := { |
| 671 | routerSolicitation := { |
| 672 | typeField := 133, |
| 673 | code := 0, |
| 674 | checksum := '0000'O, |
| 675 | reserved := '00000000'O, |
| 676 | /* TODO: do we need 'Source link-layer address' ? */ |
| 677 | options := omit |
| 678 | } |
| 679 | } |
| 680 | |
Stefan Sperling | 6cd217e | 2018-03-30 15:17:34 +0200 | [diff] [blame] | 681 | /* template for sending an ICMPv6 router advertisement */ |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 682 | template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := { |
| 683 | routerAdvertisement := { |
| 684 | typeField := 134, |
| 685 | code := 0, |
| 686 | checksum := '0000'O, |
| 687 | curHopLimit := ?, |
| 688 | reserved := '000000'B, |
| 689 | o_Bit := '0'B, |
| 690 | m_Bit := '0'B, |
| 691 | routerLifetime := oct2int('FFFF'O), |
| 692 | reachableTime := oct2int('FFFFFFFF'O), |
| 693 | retransTimer := oct2int('FFFFFFFF'O), |
| 694 | options := { |
| 695 | ts_ICMP6_OptPrefix(prefix, prefix_len) |
| 696 | } |
| 697 | } |
| 698 | } |
| 699 | |
Stefan Sperling | 6cd217e | 2018-03-30 15:17:34 +0200 | [diff] [blame] | 700 | /* template for sending an ICMPv6 neighbor solicitation */ |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 701 | template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := { |
| 702 | neighborSolicitation := { |
| 703 | typeField := 135, |
| 704 | code := 0, |
| 705 | checksum := '0000'O, |
| 706 | reserved := '00000000'O, |
| 707 | targetAddress := target_addr, |
| 708 | /* TODO: do we need 'Source link-layer address' ? */ |
| 709 | options := omit |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | /* derive ICMPv6 link-local address from lower 64bit of link_id */ |
| 714 | /* template for receiving/matching an ICMPv6 'Prefix Information' option */ |
| 715 | template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := { |
| 716 | prefixInformation := { |
| 717 | typeField := 3, |
| 718 | lengthIndicator := 4, |
| 719 | prefixLength := prefix_len, |
| 720 | reserved1 := ?, |
| 721 | a_Bit := ?, |
| 722 | l_Bit := ?, |
| 723 | validLifetime := ?, |
| 724 | preferredLifetime := ?, |
| 725 | reserved2 := ?, |
| 726 | prefix := prefix |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | /* template for receiving/matching an ICMPv6 router advertisement */ |
| 731 | template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := { |
| 732 | routerAdvertisement := { |
| 733 | typeField := 134, |
| 734 | code := 0, |
| 735 | checksum := ?, |
| 736 | curHopLimit := ?, |
| 737 | reserved := ?, |
| 738 | o_Bit := '0'B, |
| 739 | m_Bit := '0'B, |
| 740 | routerLifetime := ?, |
| 741 | reachableTime := ?, |
| 742 | retransTimer := ?, |
| 743 | options := { |
| 744 | tr_ICMP6_OptPrefix(prefix, prefix_len) |
| 745 | } |
| 746 | } |
| 747 | } |
| 748 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 749 | /* template for receiving/matching an ICMPv6 Destination Unreachable */ |
| 750 | template PDU_ICMPv6 tr_ICMPv6_DU := { |
| 751 | destinationUnreachable := { |
| 752 | typeField := 1, |
| 753 | code := ?, |
| 754 | checksum := ?, |
| 755 | unused := ?, |
| 756 | originalIpMsg := ? |
| 757 | } |
| 758 | } |
| 759 | |
Stefan Sperling | 6cd217e | 2018-03-30 15:17:34 +0200 | [diff] [blame] | 760 | /* template for receiving/matching an ICMPv6 echo request */ |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 761 | template PDU_ICMPv6 tr_ICMPv6_ERQ := { |
| 762 | echoRequest := { |
| 763 | typeField := 128, |
| 764 | code := 0, |
| 765 | checksum := ?, |
| 766 | identifier := ?, |
| 767 | sequenceNr := ?, |
| 768 | data := ? |
| 769 | } |
| 770 | } |
| 771 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 772 | /* template for receiving/matching an ICMPv6 echo reply */ |
| 773 | template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := { |
| 774 | echoReply := { |
| 775 | typeField := 129, |
| 776 | code := 0, |
| 777 | checksum := ?, |
| 778 | identifier := ?, |
| 779 | sequenceNr := ?, |
| 780 | data := data |
| 781 | } |
| 782 | } |
| 783 | |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 784 | /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */ |
| 785 | template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := { |
| 786 | header := { |
| 787 | ver := 6, |
| 788 | trclass := 0, |
| 789 | flabel := 0, |
| 790 | plen := 0, |
| 791 | nexthead := nexthead, |
| 792 | hlim := hlim, |
| 793 | srcaddr := srcaddr, |
| 794 | dstaddr := dstaddr |
| 795 | }, |
| 796 | ext_headers := omit, |
| 797 | payload := payload |
| 798 | } |
| 799 | |
| 800 | function f_ipv6_link_local(in OCT16 link_id) return OCT16 { |
| 801 | return 'FE80000000000000'O & substr(link_id, 8, 8); |
| 802 | } |
| 803 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 804 | function f_ipv6_global(in OCT16 link_id) return OCT16 { |
| 805 | return substr(link_id, 0, 8) & '1234123412341234'O; |
| 806 | } |
| 807 | |
| 808 | /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */ |
| 809 | function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 { |
| 810 | var integer i; |
| 811 | var octetstring res := substr(addr, 0, prefix); |
| 812 | for (i := prefix; i < lengthof(addr); i := i + 1) { |
| 813 | var octetstring a := addr[i] xor4b '11'O; |
| 814 | res := res & a; |
| 815 | } |
| 816 | return res; |
| 817 | } |
| 818 | |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 819 | /* Compute solicited-node multicast address as per RFC4291 2.7.1 */ |
| 820 | function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 { |
| 821 | return 'FF0200000000000000000001FF'O & substr(addr, 13, 3); |
| 822 | } |
| 823 | |
| 824 | /* generate and encode ICMPv6 router solicitation */ |
| 825 | function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring { |
| 826 | const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O; |
| 827 | var OCT16 saddr := f_ipv6_link_local(link_id); |
| 828 | |
| 829 | var octetstring tmp; |
| 830 | tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast); |
| 831 | var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp)); |
| 832 | |
| 833 | return f_IPv6_enc(ip6); |
| 834 | } |
| 835 | |
Pau Espin Pedrol | 5760421 | 2022-02-14 16:54:18 +0100 | [diff] [blame] | 836 | /* Get link-id from PDP Context EUA */ |
| 837 | function f_ctx_get_ipv6_interface_id(in PdpContext ctx) return OCT16 { |
| 838 | var OCT16 interface_id; |
| 839 | if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6)) { |
| 840 | interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address; |
| 841 | } else if (ischosen(ctx.eua.endUserAddress.endUserAddressIPv6)) { |
| 842 | interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address; |
| 843 | } else { |
| 844 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Unexpected request to submit icmpv6 rs in IPv4 PDP context"); |
| 845 | } |
| 846 | return interface_id; |
| 847 | } |
| 848 | |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 849 | /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */ |
| 850 | function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring { |
Pau Espin Pedrol | 5760421 | 2022-02-14 16:54:18 +0100 | [diff] [blame] | 851 | var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx); |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 852 | return f_gen_icmpv6_router_solicitation(interface_id); |
| 853 | } |
| 854 | |
| 855 | /* generate and encode ICMPv6 neighbor solicitation */ |
| 856 | function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring { |
| 857 | var octetstring tmp; |
| 858 | tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr); |
| 859 | var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp)); |
| 860 | return f_IPv6_enc(ip6); |
| 861 | } |
| 862 | |
| 863 | /* generate and encode ICMPv6 neighbor solicitation for PDP Context */ |
| 864 | function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring { |
Pau Espin Pedrol | 5760421 | 2022-02-14 16:54:18 +0100 | [diff] [blame] | 865 | var OCT16 interface_id := f_ctx_get_ipv6_interface_id(ctx); |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 866 | var OCT16 link_local := f_ipv6_link_local(interface_id); |
| 867 | var OCT16 daddr := f_ipv6_sol_node_mcast(link_local); |
| 868 | |
| 869 | return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local); |
| 870 | } |
| 871 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 872 | /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */ |
| 873 | function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring { |
| 874 | var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ)); |
| 875 | var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp)); |
| 876 | var octetstring data := f_IPv4_enc(ip4); |
| 877 | var OCT2 cksum := f_IPv4_checksum(data); |
| 878 | data[10] := cksum[0]; |
| 879 | data[11] := cksum[1]; |
| 880 | return data; |
| 881 | } |
| 882 | |
| 883 | /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */ |
| 884 | function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring { |
| 885 | var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr); |
| 886 | var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp)); |
| 887 | var octetstring data := f_IPv6_enc(ip6); |
| 888 | return data; |
| 889 | } |
| 890 | |
| 891 | /* Wait for ICMPv4 from GTP */ |
| 892 | function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT { |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 893 | var Gtp1uUnitdata ud; |
| 894 | T_default.start; |
| 895 | alt { |
Pau Espin Pedrol | cd326c5 | 2022-02-14 18:57:43 +0100 | [diff] [blame] | 896 | [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ctx.teid)) -> value ud { |
Harald Welte | 3e0b039 | 2018-04-26 09:46:21 +0200 | [diff] [blame] | 897 | if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) { |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 898 | setverdict(fail); |
| 899 | stop; |
| 900 | } |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 901 | var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data; |
| 902 | var IPv4_packet ip4 := f_IPv4_dec(gpdu); |
| 903 | if (ip4.header.ver != 4) { |
| 904 | repeat; |
| 905 | } |
| 906 | var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload); |
| 907 | if (not match(icmp4, expected)) { |
| 908 | repeat; |
| 909 | } |
| 910 | } |
Pau Espin Pedrol | cd326c5 | 2022-02-14 18:57:43 +0100 | [diff] [blame] | 911 | [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud { |
| 912 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 913 | "Received wrong local TEID"); |
| 914 | } |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 915 | [] GTPU.receive { setverdict(fail); } |
| 916 | [] T_default.timeout { setverdict(fail); } |
| 917 | } |
| 918 | T_default.stop; |
| 919 | } |
| 920 | |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 921 | /* Wait for ICMPv4 echo request from GTP */ |
| 922 | function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT { |
| 923 | f_wait_icmp4(ctx, tr_ICMPv4_ERQ); |
| 924 | } |
| 925 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 926 | /* Wait for ICMPv4 echo reply (or unreachable) from GTP */ |
| 927 | function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT { |
| 928 | f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU)); |
| 929 | } |
| 930 | |
| 931 | /* Wait for ICMPv6 from GTP */ |
| 932 | function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT { |
| 933 | var Gtp1uUnitdata ud; |
| 934 | T_default.start; |
| 935 | alt { |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 936 | [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud { |
Harald Welte | 3e0b039 | 2018-04-26 09:46:21 +0200 | [diff] [blame] | 937 | if (f_verify_gtpu_txseq(ud.gtpu, use_gtpu_txseq) == false) { |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 938 | setverdict(fail); |
| 939 | stop; |
| 940 | } |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 941 | var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data; |
| 942 | var IPv6_packet ip6 := f_IPv6_dec(gpdu); |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 943 | if (ip6.header.ver != 6 or ip6.header.nexthead != 58) { |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 944 | repeat; |
| 945 | } |
| 946 | var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload); |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 947 | if (not match(icmp6, expected)) { |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 948 | repeat; |
| 949 | } |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 950 | /* We are waiting for RA, update ctx */ |
| 951 | if (match(icmp6, tr_ICMPv6_RA(?, 64))) { |
| 952 | ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix; |
| 953 | log("RA with /64 prefix ", ctx.ip6_prefix); |
| 954 | } |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 955 | } |
| 956 | [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; } |
| 957 | [] GTPU.receive { setverdict(fail); } |
| 958 | [] T_default.timeout { setverdict(fail); } |
| 959 | } |
| 960 | T_default.stop; |
| 961 | } |
| 962 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 963 | /* wait for GGSN to send us an ICMPv6 router advertisement */ |
| 964 | function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT { |
| 965 | f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64)); |
| 966 | } |
| 967 | |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 968 | /* Wait for ICMPv6 echo request from GTP */ |
| 969 | function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT { |
| 970 | f_wait_icmp6(ctx, tr_ICMPv6_ERQ); |
| 971 | } |
| 972 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 973 | /* Wait for ICMPv6 echo reply (or unreachable) from GTP */ |
| 974 | function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT { |
| 975 | f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU)); |
| 976 | } |
| 977 | |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 978 | /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */ |
| 979 | function f_icmpv6_rs_for_pdp46(in PdpContext ctx) return octetstring { |
| 980 | var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address; |
| 981 | return f_gen_icmpv6_router_solicitation(interface_id); |
| 982 | } |
| 983 | |
| 984 | /* generate and encode ICMPv6 neighbor solicitation for PDP Context */ |
| 985 | function f_gen_icmpv6_neigh_solicit_for_pdp46(in PdpContext ctx) return octetstring { |
| 986 | var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address; |
| 987 | var OCT16 link_local := f_ipv6_link_local(interface_id); |
| 988 | var OCT16 daddr := f_ipv6_sol_node_mcast(link_local); |
| 989 | |
| 990 | return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local); |
| 991 | } |
| 992 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 993 | /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */ |
| 994 | function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT { |
| 995 | T_default.start; |
| 996 | alt { |
| 997 | [] GTPU.receive { setverdict(fail); } |
| 998 | [] T_default.timeout { } |
| 999 | } |
| 1000 | T_default.stop; |
| 1001 | } |
| 1002 | |
Harald Welte | 79737b4 | 2019-04-10 10:39:30 +0200 | [diff] [blame] | 1003 | /* list of protocols where we don't accept duplicates */ |
| 1004 | const OCT2List protocol_ids_nodupes := { 'C021'O, 'C023'O, 'C223'O, '8021'O }; |
| 1005 | private function f_PCO_permits_duplicates(OCT2 id) return boolean { |
| 1006 | var integer i; |
| 1007 | for (i := 0; i < lengthof(protocol_ids_nodupes); i := i+1) { |
| 1008 | if (id == protocol_ids_nodupes[i]) { |
| 1009 | return false; |
| 1010 | } |
| 1011 | } |
| 1012 | return true; |
| 1013 | } |
| 1014 | |
| 1015 | /* ensure that every given protocol Identifier exist only exactly once in the PCO */ |
| 1016 | function f_PCO_ensure_no_duplicates(ProtConfigOptions pco) { |
| 1017 | var OCT2List protocol_ids := {}; |
| 1018 | var integer i, j; |
| 1019 | for (i := 0; i < lengthof(pco.protocols); i := i+1) { |
| 1020 | var OCT2 id := pco.protocols[i].protocolID; |
| 1021 | for (j := 0; j < lengthof(protocol_ids); j := j+1) { |
| 1022 | if (not f_PCO_permits_duplicates(id) and id == protocol_ids[j]) { |
| 1023 | setverdict(fail, "Duplicate ProtocolID ", id, " already present in ", pco.protocols); |
| 1024 | } |
| 1025 | } |
| 1026 | protocol_ids := protocol_ids & { id }; |
| 1027 | } |
| 1028 | } |
| 1029 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 1030 | /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */ |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1031 | testcase TC_pdp6_act_deact() runs on GT_CT { |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 1032 | f_init(); |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 1033 | |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 1034 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn))); |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 1035 | f_pdp_ctx_act(ctx); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1036 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1037 | f_shutdown_helper(); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1038 | } |
| 1039 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 1040 | /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */ |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1041 | testcase TC_pdp6_act_deact_pcodns() runs on GT_CT { |
| 1042 | f_init(); |
| 1043 | |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 1044 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn))); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1045 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 1046 | f_pdp_ctx_act(ctx); |
Pau Espin Pedrol | 363ba48 | 2018-01-29 18:42:00 +0100 | [diff] [blame] | 1047 | |
Harald Welte | 79737b4 | 2019-04-10 10:39:30 +0200 | [diff] [blame] | 1048 | f_PCO_ensure_no_duplicates(ctx.pco_neg); |
Pau Espin Pedrol | 363ba48 | 2018-01-29 18:42:00 +0100 | [diff] [blame] | 1049 | /* verify PCO contains both primary and secondary DNS */ |
| 1050 | var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1); |
| 1051 | if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) { |
| 1052 | setverdict(fail, "Primary DNS IPv6 PCO option not found"); |
| 1053 | } |
| 1054 | |
| 1055 | var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2); |
| 1056 | if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) { |
| 1057 | setverdict(fail, "Secondary DNS IPv6 PCO option not found"); |
| 1058 | } |
| 1059 | |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1060 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1061 | f_shutdown_helper(); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1062 | } |
| 1063 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 1064 | /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */ |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1065 | testcase TC_pdp6_act_deact_icmp6() runs on GT_CT { |
| 1066 | f_init(); |
| 1067 | |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 1068 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn))); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1069 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 1070 | f_pdp_ctx_act(ctx); |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 1071 | |
Harald Welte | 79737b4 | 2019-04-10 10:39:30 +0200 | [diff] [blame] | 1072 | f_PCO_ensure_no_duplicates(ctx.pco_neg); |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 1073 | //f_send_gtpu(ctx, c_router_solicit); |
| 1074 | //f_send_gtpu(ctx, c_neigh_solicit); |
| 1075 | |
| 1076 | f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx)); |
| 1077 | f_wait_rtr_adv(ctx); |
| 1078 | f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx)); |
| 1079 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 1080 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1081 | f_shutdown_helper(); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 1082 | } |
| 1083 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 1084 | /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement. |
| 1085 | Test we can send ICMPv6 ping over GTPU to DNS server. */ |
| 1086 | testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT { |
| 1087 | f_init(); |
| 1088 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn))); |
| 1089 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 1090 | f_pdp_ctx_act(ctx); |
| 1091 | |
| 1092 | f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx)); |
| 1093 | f_wait_rtr_adv(ctx); |
| 1094 | f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx)); |
| 1095 | |
| 1096 | var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O); |
| 1097 | |
| 1098 | /* Check if we can use valid link-local src addr. */ |
| 1099 | var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
| 1100 | f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr)); |
Pau Espin Pedrol | b63d85f | 2022-02-07 16:11:47 +0100 | [diff] [blame] | 1101 | if (m_ggsn_impl == GGSN_IMPL_OSMOCOM) { |
| 1102 | f_wait_icmp6_echo_reply(ctx); |
| 1103 | } else { |
| 1104 | f_wait_gtpu_fail(ctx); |
| 1105 | } |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 1106 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 1107 | /* Check if we can use valid global src addr, should work */ |
| 1108 | var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
| 1109 | f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr)); |
| 1110 | f_wait_icmp6_echo_reply(ctx); |
| 1111 | |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1112 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1113 | f_shutdown_helper(); |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1114 | } |
| 1115 | |
| 1116 | /* Check that attempting RA with another ll src addr won't work, packet dropped: */ |
| 1117 | testcase TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr() runs on GT_CT { |
| 1118 | f_init(); |
| 1119 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn))); |
| 1120 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 1121 | f_pdp_ctx_act(ctx); |
| 1122 | |
| 1123 | f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx)); |
| 1124 | f_wait_rtr_adv(ctx); |
| 1125 | f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx)); |
| 1126 | |
| 1127 | var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
| 1128 | var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8); |
| 1129 | f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong)); |
| 1130 | f_wait_gtpu_fail(ctx); |
| 1131 | |
| 1132 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1133 | f_shutdown_helper(); |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | /* Assert that packets with wrong global src addr are dropped by GGSN */ |
| 1137 | testcase TC_pdp6_act_deact_gtpu_access_wrong_global_saddr() runs on GT_CT { |
| 1138 | f_init(); |
| 1139 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn))); |
| 1140 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 1141 | f_pdp_ctx_act(ctx); |
| 1142 | |
| 1143 | f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx)); |
| 1144 | f_wait_rtr_adv(ctx); |
| 1145 | f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx)); |
| 1146 | |
| 1147 | var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O); |
| 1148 | var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 1149 | var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob); |
| 1150 | f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr)); |
| 1151 | f_wait_gtpu_fail(ctx); |
| 1152 | |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1153 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1154 | f_shutdown_helper(); |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped */ |
| 1158 | testcase TC_pdp6_act_deact_gtpu_access_ipv4_apn6() runs on GT_CT { |
| 1159 | f_init(); |
| 1160 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn))); |
| 1161 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 1162 | f_pdp_ctx_act(ctx); |
| 1163 | |
| 1164 | f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx)); |
| 1165 | f_wait_rtr_adv(ctx); |
| 1166 | f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx)); |
| 1167 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 1168 | var OCT4 saddr_v4 := f_inet_addr("192.168.10.2"); |
| 1169 | var OCT4 daddr_v4 := f_inet_addr("8.8.8.8"); |
| 1170 | f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4)); |
| 1171 | f_wait_gtpu_fail(ctx); |
| 1172 | |
| 1173 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1174 | f_shutdown_helper(); |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 1175 | } |
| 1176 | |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 1177 | /* Validate if different clients (pdp ctx) can reach one another through GGSN. */ |
| 1178 | testcase TC_pdp6_clients_interact() runs on GT_CT { |
| 1179 | f_init(); |
| 1180 | var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn))); |
| 1181 | var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn))); |
| 1182 | f_pdp_ctx_act(ctxA); |
| 1183 | f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA)); |
| 1184 | f_wait_rtr_adv(ctxA); |
| 1185 | f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA)); |
| 1186 | |
| 1187 | f_pdp_ctx_act(ctxB); |
| 1188 | f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB)); |
| 1189 | f_wait_rtr_adv(ctxB); |
| 1190 | f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB)); |
| 1191 | |
| 1192 | var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
| 1193 | var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
| 1194 | var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
| 1195 | var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
| 1196 | |
| 1197 | /* Validate if clients can interact using ll addr. */ |
| 1198 | f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll)); |
| 1199 | f_wait_gtpu_fail(ctxB); |
| 1200 | |
| 1201 | /* Validate if clients can interact using global addr. */ |
| 1202 | f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob)); |
| 1203 | f_wait_gtpu_fail(ctxB); |
| 1204 | |
| 1205 | f_pdp_ctx_del(ctxA, '1'B); |
Pau Espin Pedrol | bb2bb06 | 2019-09-03 12:28:12 +0200 | [diff] [blame] | 1206 | f_pdp_ctx_del(ctxB, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1207 | f_shutdown_helper(); |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 1208 | } |
| 1209 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 1210 | /* Test PDP context activation for dynamic IPv4 EUA without DNS request */ |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1211 | testcase TC_pdp4_act_deact() runs on GT_CT { |
| 1212 | f_init(); |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 1213 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1214 | f_pdp_ctx_act(ctx); |
| 1215 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1216 | f_shutdown_helper(); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1217 | } |
| 1218 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 1219 | /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */ |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1220 | testcase TC_pdp4_act_deact_ipcp() runs on GT_CT { |
| 1221 | f_init(); |
Pau Espin Pedrol | f69a438 | 2018-01-29 13:09:00 +0100 | [diff] [blame] | 1222 | var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1); |
| 1223 | var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2); |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 1224 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 1225 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1226 | f_pdp_ctx_act(ctx); |
Harald Welte | 79737b4 | 2019-04-10 10:39:30 +0200 | [diff] [blame] | 1227 | f_PCO_ensure_no_duplicates(ctx.pco_neg); |
Harald Welte | 71a3602 | 2017-12-04 18:55:58 +0100 | [diff] [blame] | 1228 | /* verify IPCP is at all contained */ |
| 1229 | if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) { |
| 1230 | setverdict(fail, "IPCP not found in PCO"); |
| 1231 | } |
| 1232 | /* verify IPCP contains both primary and secondary DNS */ |
| 1233 | var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O)); |
Pau Espin Pedrol | f69a438 | 2018-01-29 13:09:00 +0100 | [diff] [blame] | 1234 | if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) { |
| 1235 | if (not match(ipcp, tr_IPCP_Ack_DNS(0))) { |
| 1236 | setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found"); |
| 1237 | } else { |
| 1238 | setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values"); |
| 1239 | } |
Harald Welte | 71a3602 | 2017-12-04 18:55:58 +0100 | [diff] [blame] | 1240 | } |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1241 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1242 | f_shutdown_helper(); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1243 | } |
| 1244 | |
Harald Welte | f829854 | 2019-04-10 10:15:28 +0200 | [diff] [blame] | 1245 | /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP + PAP authentication (broken) */ |
| 1246 | testcase TC_pdp4_act_deact_ipcp_pap_broken() runs on GT_CT { |
| 1247 | f_init(); |
| 1248 | var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1); |
| 1249 | var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2); |
| 1250 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1251 | ctx.pco_req := valueof(ts_PCO_PAP_IPv4_DNS); |
| 1252 | f_pdp_ctx_act(ctx); |
| 1253 | f_PCO_ensure_no_duplicates(ctx.pco_neg); |
| 1254 | /* verify IPCP is at all contained */ |
| 1255 | if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) { |
| 1256 | setverdict(fail, "IPCP not found in PCO"); |
| 1257 | } |
| 1258 | /* verify IPCP contains both primary and secondary DNS */ |
| 1259 | var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O)); |
| 1260 | if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) { |
| 1261 | if (not match(ipcp, tr_IPCP_Ack_DNS(0))) { |
| 1262 | setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found"); |
| 1263 | } else { |
| 1264 | setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values"); |
| 1265 | } |
| 1266 | } |
| 1267 | /* verify that PAP is contained */ |
| 1268 | if (not match(ctx.pco_neg, tr_PCO_Contains('C023'O))) { |
| 1269 | setverdict(fail, "PAP not found in PCO"); |
| 1270 | } |
| 1271 | var PapPacket pap := dec_PapPacket(f_PCO_extract_proto(ctx.pco_neg, 'C023'O)); |
| 1272 | if (not match(pap, tr_PAP_AuthAck)) { |
| 1273 | setverdict(fail, "PAP isn't an AuthenticateAck: ", pap); |
| 1274 | } |
| 1275 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1276 | f_shutdown_helper(); |
Harald Welte | f829854 | 2019-04-10 10:15:28 +0200 | [diff] [blame] | 1277 | } |
| 1278 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 1279 | /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */ |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1280 | testcase TC_pdp4_act_deact_pcodns() runs on GT_CT { |
| 1281 | f_init(); |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 1282 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 1283 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1284 | f_pdp_ctx_act(ctx); |
Pau Espin Pedrol | 363ba48 | 2018-01-29 18:42:00 +0100 | [diff] [blame] | 1285 | |
Harald Welte | 79737b4 | 2019-04-10 10:39:30 +0200 | [diff] [blame] | 1286 | f_PCO_ensure_no_duplicates(ctx.pco_neg); |
Pau Espin Pedrol | 363ba48 | 2018-01-29 18:42:00 +0100 | [diff] [blame] | 1287 | /* verify PCO contains both primary and secondary DNS */ |
| 1288 | var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1); |
| 1289 | if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) { |
| 1290 | setverdict(fail, "Primary DNS IPv4 PCO option not found"); |
| 1291 | } |
| 1292 | |
| 1293 | var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2); |
| 1294 | if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) { |
| 1295 | setverdict(fail, "Secondary DNS IPv4 PCO option not found"); |
| 1296 | } |
| 1297 | |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1298 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1299 | f_shutdown_helper(); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 1300 | } |
| 1301 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 1302 | /* Test PDP context activation for dynamic IPv4 EUA. |
| 1303 | Test we can send ICMPv6 ping over GTPU to DNS server. */ |
| 1304 | testcase TC_pdp4_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_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1307 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
| 1308 | f_pdp_ctx_act(ctx); |
| 1309 | |
Harald Welte | 79737b4 | 2019-04-10 10:39:30 +0200 | [diff] [blame] | 1310 | f_PCO_ensure_no_duplicates(ctx.pco_neg); |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 1311 | var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O); |
| 1312 | |
| 1313 | /* Check if we can use valid global src addr, should work */ |
| 1314 | var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address; |
| 1315 | f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr)); |
| 1316 | f_wait_icmp4_echo_reply(ctx); |
| 1317 | |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1318 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1319 | f_shutdown_helper(); |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | /* Assert that packets with wrong global src addr are dropped by GGSN */ |
| 1323 | testcase TC_pdp4_act_deact_gtpu_access_wrong_saddr() runs on GT_CT { |
| 1324 | f_init(); |
| 1325 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1326 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
| 1327 | f_pdp_ctx_act(ctx); |
| 1328 | |
| 1329 | f_PCO_ensure_no_duplicates(ctx.pco_neg); |
| 1330 | var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O); |
| 1331 | var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address; |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 1332 | var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O); |
| 1333 | f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr)); |
| 1334 | f_wait_gtpu_fail(ctx); |
| 1335 | |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1336 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1337 | f_shutdown_helper(); |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | /* Send an IPv6 RA to APN4, should fail (packet dropped) */ |
| 1341 | testcase TC_pdp4_act_deact_gtpu_access_ipv6_apn4() runs on GT_CT { |
| 1342 | f_init(); |
| 1343 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1344 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
| 1345 | f_pdp_ctx_act(ctx); |
| 1346 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 1347 | /* Send an IPv6 RA to APN4, should fail (packet dropped) */ |
| 1348 | var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4"); |
| 1349 | f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6)); |
| 1350 | f_wait_gtpu_fail(ctx); |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1351 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 1352 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1353 | f_shutdown_helper(); |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 1354 | } |
| 1355 | |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 1356 | /* Helper function for tests below. */ |
| 1357 | function f_pdp4_clients_interact() runs on GT_CT { |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 1358 | f_init(); |
| 1359 | var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1360 | var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1361 | f_pdp_ctx_act(ctxA); |
| 1362 | f_pdp_ctx_act(ctxB); |
| 1363 | var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address; |
| 1364 | var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address; |
| 1365 | f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB)); |
| 1366 | f_wait_icmp4_echo_request(ctxB); |
| 1367 | |
| 1368 | f_pdp_ctx_del(ctxA, '1'B); |
Pau Espin Pedrol | bb2bb06 | 2019-09-03 12:28:12 +0200 | [diff] [blame] | 1369 | f_pdp_ctx_del(ctxB, '1'B); |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 1370 | } |
| 1371 | |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 1372 | /* Validate if different clients (pdp ctx) can reach one another through GGSN. */ |
| 1373 | testcase TC_pdp4_clients_interact_with_txseq() runs on GT_CT { |
Harald Welte | 3e0b039 | 2018-04-26 09:46:21 +0200 | [diff] [blame] | 1374 | use_gtpu_txseq := true; |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 1375 | f_pdp4_clients_interact(); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1376 | f_shutdown_helper(); |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | /* Validate if different clients (pdp ctx) can reach one another through GGSN (without Tx sequence number). */ |
| 1380 | testcase TC_pdp4_clients_interact_without_txseq() runs on GT_CT { |
Harald Welte | 3e0b039 | 2018-04-26 09:46:21 +0200 | [diff] [blame] | 1381 | use_gtpu_txseq := false; |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 1382 | f_pdp4_clients_interact(); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1383 | f_shutdown_helper(); |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 1384 | } |
| 1385 | |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 1386 | testcase TC_echo_req_resp() runs on GT_CT { |
| 1387 | f_init(); |
| 1388 | f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr)); |
| 1389 | T_default.start; |
| 1390 | alt { |
| 1391 | [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); }; |
| 1392 | [] GTPC.receive { repeat; }; |
| 1393 | [] T_default.timeout { setverdict(fail); } |
| 1394 | } |
| 1395 | T_default.stop; |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1396 | f_shutdown_helper(); |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 1397 | } |
| 1398 | |
Pau Espin Pedrol | 480e67f | 2022-02-09 16:37:47 +0100 | [diff] [blame] | 1399 | testcase TC_echo_req_resp_gtpu() runs on GT_CT { |
| 1400 | f_init(); |
| 1401 | GTPU.send(ts_GTPU_PING(g_peer_u, g_d_seq_nr)); |
| 1402 | T_default.start; |
| 1403 | alt { |
| 1404 | [] GTPU.receive(tr_GTPU_PONG(g_peer_u)) { setverdict(pass); }; |
| 1405 | [] GTPU.receive { repeat; }; |
| 1406 | [] T_default.timeout { setverdict(fail); } |
| 1407 | } |
| 1408 | T_default.stop; |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1409 | f_shutdown_helper(); |
Pau Espin Pedrol | 480e67f | 2022-02-09 16:37:47 +0100 | [diff] [blame] | 1410 | } |
| 1411 | |
Philipp Maier | 33e5261 | 2018-05-30 17:22:02 +0200 | [diff] [blame] | 1412 | /* Test if the parser can cope with PCO that only contain either a |
| 1413 | * single primary DNS or a secondary DNS. */ |
| 1414 | testcase TC_pdp4_act_deact_with_single_dns() runs on GT_CT { |
| 1415 | |
| 1416 | /* Note: an unpatched osmo-ggsn version will enter an endless-loop when |
| 1417 | * the test is executed. |
| 1418 | * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */ |
| 1419 | |
| 1420 | f_init(); |
| 1421 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1422 | var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1); |
| 1423 | var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2); |
| 1424 | var octetstring pco_neg_dns; |
| 1425 | var octetstring pco_neg_dns_expected; |
| 1426 | |
| 1427 | /* PCO with primary DNS only */ |
| 1428 | ctx.pco_req := valueof(ts_PCO_IPv4_PRI_DNS_IPCP); |
| 1429 | f_pdp_ctx_act(ctx); |
Harald Welte | 79737b4 | 2019-04-10 10:39:30 +0200 | [diff] [blame] | 1430 | f_PCO_ensure_no_duplicates(ctx.pco_neg); |
Philipp Maier | 33e5261 | 2018-05-30 17:22:02 +0200 | [diff] [blame] | 1431 | pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1); |
| 1432 | pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1 |
| 1433 | /* Note: The prepended hex bytes encode the following information: |
| 1434 | * 0x02 = Configuration ACK |
| 1435 | * 0x00 = Identifier |
| 1436 | * 0x000a = Length |
| 1437 | * 0x81 = Type (Primary DNS Server Address) |
| 1438 | * 0x06 = Length |
| 1439 | * (4 byte IP-Address appended) */ |
| 1440 | if (not match(pco_neg_dns, pco_neg_dns_expected)) { |
| 1441 | setverdict(fail, "Primary DNS IPv4 PCO option not found"); |
| 1442 | } |
| 1443 | f_pdp_ctx_del(ctx, '1'B); |
| 1444 | |
| 1445 | /* PCO with secondary DNS only */ |
Harald Welte | 7ef6d10 | 2021-04-01 21:24:35 +0200 | [diff] [blame] | 1446 | ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
Philipp Maier | 33e5261 | 2018-05-30 17:22:02 +0200 | [diff] [blame] | 1447 | ctx.pco_req := valueof(ts_PCO_IPv4_SEC_DNS_IPCP); |
| 1448 | f_pdp_ctx_act(ctx); |
| 1449 | pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1); |
| 1450 | pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2 |
| 1451 | if (not match(pco_neg_dns, pco_neg_dns_expected)) { |
| 1452 | setverdict(fail, "Secondary DNS IPv4 PCO option not found"); |
| 1453 | } |
| 1454 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1455 | f_shutdown_helper(); |
Philipp Maier | 33e5261 | 2018-05-30 17:22:02 +0200 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | /* Test if the parser can cope with PCO that contains primary and secondary DNS in a separate IPCP container. |
| 1459 | * Note: an unpatched osmo-ggsn version will enter an endless-loop when the test is run |
| 1460 | * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288. */ |
| 1461 | testcase TC_pdp4_act_deact_with_separate_dns() runs on GT_CT { |
| 1462 | |
| 1463 | /* Note: an unpatched osmo-ggsn version will enter an endless-loop when |
| 1464 | * the test is executed. |
| 1465 | * see also: Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */ |
| 1466 | |
| 1467 | f_init(); |
| 1468 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1469 | var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1); |
| 1470 | var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2); |
| 1471 | var octetstring pco_neg_dns; |
| 1472 | var octetstring pco_neg_dns_expected; |
| 1473 | |
| 1474 | ctx.pco_req := valueof(ts_PCO_IPv4_SEPARATE_DNS_IPCP); |
| 1475 | f_pdp_ctx_act(ctx); |
| 1476 | |
| 1477 | /* Check if primary DNS is contained */ |
| 1478 | pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 1); |
| 1479 | pco_neg_dns_expected := '0200000A8106'O & ggsn_ip4_dns1 |
| 1480 | if (not match(pco_neg_dns, pco_neg_dns_expected)) { |
| 1481 | setverdict(fail, "Primary DNS IPv4 PCO option not found"); |
| 1482 | } |
Philipp Maier | 33e5261 | 2018-05-30 17:22:02 +0200 | [diff] [blame] | 1483 | |
| 1484 | /* Check if secondary DNS is contained */ |
Stefan Sperling | 8e7a396 | 2018-07-19 19:24:38 +0200 | [diff] [blame] | 1485 | /* This used to fail due to a bug in osmo-ggsn, see OS#3381 */ |
| 1486 | pco_neg_dns := f_PCO_extract_proto(ctx.pco_neg, '8021'O, 2); |
Philipp Maier | 33e5261 | 2018-05-30 17:22:02 +0200 | [diff] [blame] | 1487 | pco_neg_dns_expected := '0200000A8306'O & ggsn_ip4_dns2 |
| 1488 | if (not match(pco_neg_dns, pco_neg_dns_expected)) { |
| 1489 | setverdict(fail, "Secondary DNS IPv4 PCO option not found"); |
| 1490 | } |
| 1491 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1492 | f_shutdown_helper(); |
Philipp Maier | 33e5261 | 2018-05-30 17:22:02 +0200 | [diff] [blame] | 1493 | } |
| 1494 | |
Pau Espin Pedrol | cd326c5 | 2022-02-14 18:57:43 +0100 | [diff] [blame] | 1495 | /* Validate that SUT updates remote TEIC when requested through UpdatePDPContextRequest */ |
| 1496 | testcase TC_pdp4_act_update_teic() runs on GT_CT { |
| 1497 | f_init(); |
| 1498 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1499 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
| 1500 | f_pdp_ctx_act(ctx); |
| 1501 | |
| 1502 | /* UpdatePDPContestRequest changing the local TEIC */ |
| 1503 | var OCT4 new_teic := ctx.teic; |
| 1504 | new_teic[3] := new_teic[3] xor4b '11'O; |
| 1505 | f_pdp_ctx_update(ctx, new_teic := new_teic); |
| 1506 | |
| 1507 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1508 | f_shutdown_helper(); |
Pau Espin Pedrol | cd326c5 | 2022-02-14 18:57:43 +0100 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | /* Validate that SUT updates remote TEID when requested through UpdatePDPContextRequest */ |
| 1512 | testcase TC_pdp4_act_update_teid() runs on GT_CT { |
| 1513 | f_init(); |
| 1514 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1515 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
| 1516 | f_pdp_ctx_act(ctx); |
| 1517 | |
| 1518 | f_PCO_ensure_no_duplicates(ctx.pco_neg); |
| 1519 | var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O); |
| 1520 | var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address; |
| 1521 | |
| 1522 | /* Data is sent (back) to the local TEID established during CreatePDPContext */ |
| 1523 | f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr)); |
| 1524 | f_wait_icmp4_echo_reply(ctx); |
| 1525 | |
| 1526 | /* UpdatePDPContestRequest changing the local TEID */ |
| 1527 | var OCT4 new_teid := ctx.teid; |
| 1528 | new_teid[3] := new_teid[3] xor4b '11'O; |
| 1529 | f_pdp_ctx_update(ctx, new_teid := new_teid); |
| 1530 | |
| 1531 | /* Check if we can send data after updating the PDP context. Answer should be sent to the new TEID */ |
| 1532 | f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr)); |
| 1533 | f_wait_icmp4_echo_reply(ctx); |
| 1534 | |
| 1535 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1536 | f_shutdown_helper(); |
Pau Espin Pedrol | cd326c5 | 2022-02-14 18:57:43 +0100 | [diff] [blame] | 1537 | } |
| 1538 | |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1539 | /* Test IPv4v6 context activation for dynamic IPv4v6 EUA without DNS request */ |
| 1540 | testcase TC_pdp46_act_deact() runs on GT_CT { |
| 1541 | f_init(); |
| 1542 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn))); |
| 1543 | f_pdp_ctx_act(ctx); |
| 1544 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1545 | f_shutdown_helper(); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | /* Test PDP context activation for dynamic IPv4v6 EUA with IPv4 DNS in IPCP */ |
| 1549 | testcase TC_pdp46_act_deact_ipcp() runs on GT_CT { |
| 1550 | f_init(); |
| 1551 | var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1); |
| 1552 | var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2); |
| 1553 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn))); |
| 1554 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP); |
| 1555 | f_pdp_ctx_act(ctx); |
Harald Welte | 79737b4 | 2019-04-10 10:39:30 +0200 | [diff] [blame] | 1556 | f_PCO_ensure_no_duplicates(ctx.pco_neg); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1557 | /* verify IPCP is at all contained */ |
| 1558 | if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) { |
| 1559 | setverdict(fail, "IPCP not found in PCO"); |
| 1560 | } |
Harald Welte | 79737b4 | 2019-04-10 10:39:30 +0200 | [diff] [blame] | 1561 | f_PCO_ensure_no_duplicates(ctx.pco_neg); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1562 | /* verify IPCP contains both primary and secondary IPv4 DNS */ |
| 1563 | var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O)); |
| 1564 | if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) { |
| 1565 | if (not match(ipcp, tr_IPCP_Ack_DNS(0))) { |
| 1566 | setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found"); |
| 1567 | } else { |
| 1568 | setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values"); |
| 1569 | } |
| 1570 | } |
| 1571 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1572 | f_shutdown_helper(); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1573 | } |
| 1574 | |
| 1575 | /* Test PDP context activation for dynamic IPv4v6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */ |
| 1576 | testcase TC_pdp46_act_deact_icmp6() runs on GT_CT { |
| 1577 | f_init(); |
| 1578 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn))); |
| 1579 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 1580 | f_pdp_ctx_act(ctx); |
| 1581 | |
| 1582 | f_send_gtpu(ctx, f_icmpv6_rs_for_pdp46(ctx)); |
| 1583 | f_wait_rtr_adv(ctx); |
| 1584 | f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp46(ctx)); |
| 1585 | |
| 1586 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1587 | f_shutdown_helper(); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv4 DNS in PCO */ |
| 1591 | testcase TC_pdp46_act_deact_pcodns4() runs on GT_CT { |
| 1592 | f_init(); |
| 1593 | |
| 1594 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn))); |
| 1595 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
| 1596 | f_pdp_ctx_act(ctx); |
| 1597 | |
Harald Welte | 79737b4 | 2019-04-10 10:39:30 +0200 | [diff] [blame] | 1598 | f_PCO_ensure_no_duplicates(ctx.pco_neg); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1599 | /* verify PCO contains both primary and secondary IPv4 DNS */ |
| 1600 | var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1); |
| 1601 | if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) { |
| 1602 | setverdict(fail, "Primary DNS IPv4 PCO option not found"); |
| 1603 | } |
| 1604 | |
| 1605 | var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2); |
| 1606 | if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) { |
| 1607 | setverdict(fail, "Secondary DNS IPv4 PCO option not found"); |
| 1608 | } |
| 1609 | |
| 1610 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1611 | f_shutdown_helper(); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | /* Test IPv4v6 context activation for dynamic IPv4v6 EUA with request of IPv6 DNS in PCO */ |
| 1615 | testcase TC_pdp46_act_deact_pcodns6() runs on GT_CT { |
| 1616 | f_init(); |
| 1617 | |
| 1618 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn))); |
| 1619 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 1620 | f_pdp_ctx_act(ctx); |
| 1621 | |
Harald Welte | 79737b4 | 2019-04-10 10:39:30 +0200 | [diff] [blame] | 1622 | f_PCO_ensure_no_duplicates(ctx.pco_neg); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1623 | /* verify PCO contains both primary and secondary IPv6 DNS */ |
| 1624 | var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1); |
| 1625 | if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) { |
| 1626 | setverdict(fail, "Primary DNS IPv6 PCO option not found"); |
| 1627 | } |
| 1628 | |
| 1629 | var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2); |
| 1630 | if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) { |
| 1631 | setverdict(fail, "Secondary DNS IPv6 PCO option not found"); |
| 1632 | } |
| 1633 | |
| 1634 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1635 | f_shutdown_helper(); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | /* Test PDP context activation for dynamic IPv4v6 EUA. |
| 1639 | Test we can send ICMPv6 ping over GTPU to DNS server. */ |
| 1640 | testcase TC_pdp46_act_deact_gtpu_access() runs on GT_CT { |
| 1641 | f_init(); |
| 1642 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn))); |
| 1643 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
| 1644 | f_pdp_ctx_act(ctx); |
| 1645 | |
| 1646 | var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O); |
| 1647 | |
| 1648 | /* Check if we can use valid global src addr, should work */ |
| 1649 | var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address; |
| 1650 | f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr)); |
| 1651 | f_wait_icmp4_echo_reply(ctx); |
| 1652 | |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1653 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1654 | f_shutdown_helper(); |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | /* Assert that packets with wrong ipv4 src addr are dropped by GGSN on APN IPv4v6 */ |
| 1658 | testcase TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4() runs on GT_CT { |
| 1659 | f_init(); |
| 1660 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn))); |
| 1661 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
| 1662 | f_pdp_ctx_act(ctx); |
| 1663 | |
| 1664 | var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O); |
| 1665 | var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv4_address; |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1666 | var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O); |
| 1667 | f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr)); |
| 1668 | f_wait_gtpu_fail(ctx); |
| 1669 | |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1670 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1671 | f_shutdown_helper(); |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1672 | } |
| 1673 | |
Pau Espin Pedrol | c6ac695 | 2022-02-14 11:19:23 +0100 | [diff] [blame] | 1674 | /* Check that attempting RA with another ll src addr won't work, packet dropped: */ |
| 1675 | testcase TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6() runs on GT_CT { |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1676 | f_init(); |
| 1677 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn))); |
| 1678 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
| 1679 | f_pdp_ctx_act(ctx); |
| 1680 | |
Pau Espin Pedrol | c6ac695 | 2022-02-14 11:19:23 +0100 | [diff] [blame] | 1681 | var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address); |
| 1682 | var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8); |
| 1683 | f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong)); |
| 1684 | f_wait_gtpu_fail(ctx); |
| 1685 | |
| 1686 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1687 | f_shutdown_helper(); |
Pau Espin Pedrol | c6ac695 | 2022-02-14 11:19:23 +0100 | [diff] [blame] | 1688 | } |
| 1689 | |
| 1690 | /* Assert that packets with wrong ipv6 global src addr are dropped by GGSN on APN IPv4v6 */ |
| 1691 | testcase TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6() runs on GT_CT { |
| 1692 | f_init(); |
| 1693 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn))); |
| 1694 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 1695 | f_pdp_ctx_act(ctx); |
| 1696 | |
| 1697 | f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx)); |
| 1698 | f_wait_rtr_adv(ctx); |
| 1699 | f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx)); |
| 1700 | |
| 1701 | var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O); |
| 1702 | var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address); |
| 1703 | var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob); |
| 1704 | f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr)); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1705 | f_wait_gtpu_fail(ctx); |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 1706 | |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1707 | f_pdp_ctx_del(ctx, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1708 | f_shutdown_helper(); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1709 | } |
| 1710 | |
| 1711 | /* Validate if different clients (pdp ctx) can reach one another through GGSN. */ |
| 1712 | testcase TC_pdp46_clients_interact() runs on GT_CT { |
| 1713 | f_init(); |
| 1714 | var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn))); |
| 1715 | var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet46, valueof(t_EuaIPv4Dynv6Dyn))); |
| 1716 | f_pdp_ctx_act(ctxA); |
| 1717 | f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp46(ctxA)); |
| 1718 | f_wait_rtr_adv(ctxA); |
| 1719 | f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxA)); |
| 1720 | |
| 1721 | f_pdp_ctx_act(ctxB); |
| 1722 | f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp46(ctxB)); |
| 1723 | f_wait_rtr_adv(ctxB); |
| 1724 | f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp46(ctxB)); |
| 1725 | |
| 1726 | var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address); |
| 1727 | var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address); |
| 1728 | var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address); |
| 1729 | var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv4andIPv6.ipv6_address); |
| 1730 | |
| 1731 | /* Validate if clients can interact using ll addr. */ |
| 1732 | f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll)); |
| 1733 | f_wait_gtpu_fail(ctxB); |
| 1734 | |
| 1735 | /* Validate if clients can interact using global addr. */ |
| 1736 | f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob)); |
| 1737 | f_wait_gtpu_fail(ctxB); |
| 1738 | |
| 1739 | f_pdp_ctx_del(ctxA, '1'B); |
Pau Espin Pedrol | bb2bb06 | 2019-09-03 12:28:12 +0200 | [diff] [blame] | 1740 | f_pdp_ctx_del(ctxB, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1741 | f_shutdown_helper(); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 1742 | } |
| 1743 | |
Pau Espin Pedrol | 22d597f | 2019-08-21 16:16:58 +0200 | [diff] [blame] | 1744 | /* Test IPv4v6 context activation for dynamic IPv4v6 EUA on a v4-only APN */ |
| 1745 | testcase TC_pdp46_act_deact_apn4() runs on GT_CT { |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 1746 | const OCT1 cause_accept := '80'O; /* Normal accept cause */ |
| 1747 | const OCT1 cause_new_pdp_type := '81'O; /* Cause: New PDP type due to network preference */ |
| 1748 | const OCT1 cause_unknown_pdp := 'DC'O; /* Cause: Unknown PDP address or PDP type */ |
| 1749 | var CreatePDPContextResponse cpr; |
| 1750 | |
Pau Espin Pedrol | 22d597f | 2019-08-21 16:16:58 +0200 | [diff] [blame] | 1751 | f_init(); |
Pau Espin Pedrol | 22d597f | 2019-08-21 16:16:58 +0200 | [diff] [blame] | 1752 | var PdpContext ctx46 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dynv6Dyn))); |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 1753 | cpr := f_pdp_ctx_act(ctx46, (cause_unknown_pdp, cause_new_pdp_type)); |
Pau Espin Pedrol | 22d597f | 2019-08-21 16:16:58 +0200 | [diff] [blame] | 1754 | |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 1755 | if (cpr.cause.causevalue == cause_new_pdp_type) { |
| 1756 | /* 3GPP TS 23.060 sec 9.2.1: "If the MS requests PDP type IPv4v6, |
| 1757 | * but the operator preferences dictate the use of a single IP |
| 1758 | * version only, the PDP type shall be changed to a single address |
| 1759 | * PDP type (IPv4 or IPv6) and a reason cause shall be returned to |
| 1760 | * the MS indicating that only the assigned PDP type is allowed. In |
| 1761 | * this case, the MS shall not request another PDP context for the |
| 1762 | * other PDP type during the existence of the PDP context." */ |
| 1763 | f_pdp_ctx_del(ctx46, '1'B); |
| 1764 | } else { |
| 1765 | /* 3GPP TS 23.060 sec 9.2.1 NOTE 5: If the MS requests PDP type |
| 1766 | * IPv4v6, and the PDP context is rejected due to "unknown PDP |
| 1767 | * type", the MS can attempt to establish dual-stack connectivity |
| 1768 | * by performing two PDP context request procedures to activate an |
| 1769 | * IPv4 PDP context and an IPv6 PDP context, both to the same APN. A |
| 1770 | * typical MS first attempts v4v6, and if rejected, then tries v4 |
| 1771 | * and v6 separetly */ |
| 1772 | var PdpContext ctx4 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1773 | f_pdp_ctx_act(ctx4, cause_accept); /* Normal accept cause */ |
Pau Espin Pedrol | 22d597f | 2019-08-21 16:16:58 +0200 | [diff] [blame] | 1774 | |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 1775 | var PdpContext ctx6 := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv6Dyn))); |
| 1776 | f_pdp_ctx_act(ctx6, cause_unknown_pdp); /* Cause: Unknown PDP address or PDP type */ |
Pau Espin Pedrol | 22d597f | 2019-08-21 16:16:58 +0200 | [diff] [blame] | 1777 | |
Pau Espin Pedrol | 0f464d6 | 2022-02-23 14:04:29 +0100 | [diff] [blame] | 1778 | f_pdp_ctx_del(ctx4, '1'B); |
| 1779 | } |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1780 | f_shutdown_helper(); |
Pau Espin Pedrol | 22d597f | 2019-08-21 16:16:58 +0200 | [diff] [blame] | 1781 | } |
| 1782 | |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 1783 | /* Validate if 2nd CtxCreateReq with increased Recovery IE causes ggsn to drop 1st one (while keeping 2nd one). */ |
| 1784 | testcase TC_pdp_act2_recovery() runs on GT_CT { |
| 1785 | var Gtp1cUnitdata ud; |
| 1786 | var default d; |
| 1787 | var boolean ctxA_deleted := false; |
| 1788 | var boolean ctxB_created := false; |
| 1789 | |
| 1790 | f_init(); |
| 1791 | var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1792 | var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1793 | f_pdp_ctx_act(ctxA); |
| 1794 | |
Vadim Yanitskiy | d344b4a | 2022-02-09 18:28:18 +0600 | [diff] [blame] | 1795 | g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1); |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 1796 | |
| 1797 | log("sending 2nd CreatePDP (recovery increased)"); |
| 1798 | f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctxB.imsi, g_restart_ctr, |
| 1799 | ctxB.teid, ctxB.teic, ctxB.nsapi, ctxB.eua, ctxB.apn, |
| 1800 | g_sgsn_ip_c, g_sgsn_ip_u, ctxB.msisdn, ctxB.pco_req)); |
| 1801 | T_default.start; |
| 1802 | d := activate(pingpong()); |
| 1803 | alt { |
| 1804 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctxB.teic)) -> value ud { |
| 1805 | f_handle_create_req(ctxB, ud); |
| 1806 | if (not ctxB_created) { |
| 1807 | ctxB_created := true; |
| 1808 | setverdict(pass); |
| 1809 | } else { |
| 1810 | setverdict(fail, "Repeated createPDPContextResponse(ctxB)"); |
| 1811 | } |
| 1812 | |
| 1813 | if (not ctxA_deleted) { |
| 1814 | repeat; |
| 1815 | } |
| 1816 | } |
| 1817 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxA.teic)) -> value ud { |
| 1818 | if (ispresent(ud.gtpc.gtpc_pdu.deletePDPContextRequest.tearDownIndicator)) { |
| 1819 | setverdict(pass); |
| 1820 | } else { |
| 1821 | setverdict(fail); |
| 1822 | } |
| 1823 | |
| 1824 | if (not ctxA_deleted) { |
| 1825 | ctxA_deleted := true; |
| 1826 | setverdict(pass); |
| 1827 | } else { |
| 1828 | setverdict(fail, "Repeated deletePDPContextRequest(ctxA)"); |
| 1829 | } |
| 1830 | |
| 1831 | if (not ctxB_created) { |
| 1832 | repeat; |
| 1833 | } |
| 1834 | } |
| 1835 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextRequest, ctxB.teic)) -> value ud { |
| 1836 | setverdict(fail, "GGSN dropping still valid pdp ctx"); |
| 1837 | } |
| 1838 | } |
| 1839 | deactivate(d); |
| 1840 | T_default.stop; |
| 1841 | |
| 1842 | f_pdp_ctx_del(ctxB, '1'B); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1843 | f_shutdown_helper(); |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | |
Pau Espin Pedrol | 9a5f42f | 2019-05-27 20:04:35 +0200 | [diff] [blame] | 1847 | /* Send a duplicate echo req. osmo-ggsn maintains a queue for sent |
| 1848 | responses (60 seconds): If same delete req is sent and duplicate is |
| 1849 | detected, saved duplicate response should be sent back. */ |
| 1850 | testcase TC_act_deact_retrans_duplicate() runs on GT_CT { |
| 1851 | f_init(); |
| 1852 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1853 | f_pdp_ctx_act(ctx); |
| 1854 | f_pdp_ctx_del(ctx, '1'B); |
| 1855 | /* leave some time in between to make sure retransmit response queue keeps packets for a while */ |
| 1856 | f_sleep(1.0); |
| 1857 | /* g_c_seq_nr was increased during f_pdp_ctx_del(), we want a |
| 1858 | duplicate. If it was not a duplicate, osmo-ggsn would answer |
| 1859 | with a failure since that PDP ctx was already deleted. */ |
| 1860 | g_c_seq_nr := g_c_seq_nr - 1; |
Pau Espin Pedrol | 10ec96e | 2022-02-09 17:03:15 +0100 | [diff] [blame] | 1861 | f_pdp_ctx_del(ctx, '1'B, expect_diameter := false); |
Pau Espin Pedrol | 9a5f42f | 2019-05-27 20:04:35 +0200 | [diff] [blame] | 1862 | |
| 1863 | /* Now send a new pdp ctx del (increased seqnum). It should fail with cause "non-existent": */ |
| 1864 | var OCT1 cause_nonexistent := 'C0'O; |
Pau Espin Pedrol | 10ec96e | 2022-02-09 17:03:15 +0100 | [diff] [blame] | 1865 | f_pdp_ctx_del(ctx, '1'B, cause_nonexistent, expect_diameter := false); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1866 | f_shutdown_helper(); |
Pau Espin Pedrol | 9a5f42f | 2019-05-27 20:04:35 +0200 | [diff] [blame] | 1867 | } |
| 1868 | |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 1869 | /* Activate PDP context + trigger Recovery procedure through EchoResp */ |
| 1870 | testcase TC_pdp_act_restart_ctr_echo() runs on GT_CT { |
| 1871 | var Gtp1cUnitdata ud; |
Pau Espin Pedrol | 0511802 | 2022-02-17 19:49:13 +0100 | [diff] [blame] | 1872 | g_use_echo_intval := 5; |
| 1873 | timer T_echo; |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 1874 | f_init(); |
| 1875 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1876 | f_pdp_ctx_act(ctx); |
| 1877 | |
| 1878 | /* Wait to receive echo request and send initial Restart counter */ |
Pau Espin Pedrol | 0511802 | 2022-02-17 19:49:13 +0100 | [diff] [blame] | 1879 | T_echo.start(int2float(g_use_echo_intval) + 1.0); |
| 1880 | alt { |
| 1881 | [] GTPC.receive(tr_GTPC_PING(?)) -> value ud { |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 1882 | var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber); |
| 1883 | GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr)); |
Pau Espin Pedrol | 0511802 | 2022-02-17 19:49:13 +0100 | [diff] [blame] | 1884 | } |
| 1885 | [] T_echo.timeout { |
| 1886 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 1887 | "Timeout waiting for ping"); |
| 1888 | } |
| 1889 | } |
| 1890 | T_echo.stop; |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 1891 | |
| 1892 | /* Wait to receive second echo request and send incremented Restart |
| 1893 | counter. This will fake a restarted SGSN, and pdp ctx allocated |
| 1894 | should be released by GGSN */ |
Vadim Yanitskiy | d344b4a | 2022-02-09 18:28:18 +0600 | [diff] [blame] | 1895 | g_restart_ctr := int2oct((oct2int(g_restart_ctr) + 1) mod 256, 1); |
Pau Espin Pedrol | 0511802 | 2022-02-17 19:49:13 +0100 | [diff] [blame] | 1896 | T_echo.start(int2float(g_use_echo_intval) + 1.0); |
| 1897 | alt { |
| 1898 | [] GTPC.receive(tr_GTPC_PING(?)) -> value ud { |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 1899 | var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber); |
| 1900 | GTPC.send(ts_GTPC_PONG(ud.peer, seq, g_restart_ctr)); |
Pau Espin Pedrol | 0511802 | 2022-02-17 19:49:13 +0100 | [diff] [blame] | 1901 | } |
| 1902 | [] T_echo.timeout { |
| 1903 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 1904 | "Timeout waiting for ping"); |
| 1905 | } |
| 1906 | } |
| 1907 | T_echo.stop; |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 1908 | f_pdp_ctx_exp_del_req(ctx, omit, true); |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 1909 | f_shutdown_helper(); |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 1910 | } |
| 1911 | |
Pau Espin Pedrol | 68c2af5 | 2022-02-25 11:56:17 +0100 | [diff] [blame] | 1912 | /* Test creation, user plane and deletion of big amount (1000) of concurrent PDP context */ |
| 1913 | testcase TC_lots_of_concurrent_pdp_ctx() runs on GT_CT { |
| 1914 | var Gtp1cUnitdata udc; |
| 1915 | var Gtp1uUnitdata udu; |
| 1916 | const integer num_ctx := 1000; |
| 1917 | var PdpContext ctx[num_ctx]; |
| 1918 | timer T_next := 0.01; |
| 1919 | var integer next_req_ctx := 0; |
| 1920 | var integer rx_resp_ctx := 0; |
| 1921 | var integer rx_pong := 0; |
| 1922 | var OCT4 dns1_addr; |
| 1923 | var OCT4 saddr; |
| 1924 | var integer teic; |
| 1925 | var integer idx; |
| 1926 | |
| 1927 | f_init(); |
| 1928 | |
| 1929 | for (var integer i := 0; i < num_ctx; i := i + 1) { |
| 1930 | ctx[i] := valueof(t_DefinePDP(f_rnd_imsi('26242'H), f_rnd_msisdn('1234'O), c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 1931 | ctx[i].teic := int2oct(i+1, 4); /* +1: skip TEIC=0 */ |
| 1932 | ctx[i].teid := int2oct(i+1, 4); /* +1: skip TEID=0 */ |
| 1933 | ctx[i].pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
| 1934 | } |
| 1935 | |
| 1936 | T_default.start(60.0); |
| 1937 | |
| 1938 | T_next.start; |
| 1939 | alt { |
Pau Espin Pedrol | 45d5702 | 2022-03-08 13:49:02 +0100 | [diff] [blame^] | 1940 | [Gx_PROC.checkstate("Connected")] as_DIA_CCR(INITIAL_REQUEST) { repeat; } |
Pau Espin Pedrol | 68c2af5 | 2022-02-25 11:56:17 +0100 | [diff] [blame] | 1941 | [] pingpong(); |
| 1942 | [] T_next.timeout { |
| 1943 | f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx[next_req_ctx].imsi, g_restart_ctr, |
| 1944 | ctx[next_req_ctx].teid, ctx[next_req_ctx].teic, ctx[next_req_ctx].nsapi, |
| 1945 | ctx[next_req_ctx].eua, ctx[next_req_ctx].apn, g_sgsn_ip_c, g_sgsn_ip_u, |
| 1946 | ctx[next_req_ctx].msisdn, ctx[next_req_ctx].pco_req, ctx[next_req_ctx].ratType, |
| 1947 | ctx[next_req_ctx].uli)); |
| 1948 | next_req_ctx := next_req_ctx + 1; |
| 1949 | if (next_req_ctx < num_ctx) { |
| 1950 | T_next.start; |
| 1951 | } |
| 1952 | repeat; |
| 1953 | } |
| 1954 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc { |
| 1955 | teic := oct2int(udc.gtpc.teid); |
| 1956 | if (not match(teic, (1 .. num_ctx))) { |
| 1957 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 1958 | "Rx Unexpected TEIC"); |
| 1959 | } |
| 1960 | idx := teic - 1; |
| 1961 | f_handle_create_req(ctx[idx], udc); |
| 1962 | rx_resp_ctx := rx_resp_ctx + 1; |
| 1963 | |
| 1964 | dns1_addr := f_PCO_extract_proto(ctx[idx].pco_neg, '000d'O); |
| 1965 | saddr := ctx[idx].eua.endUserAddress.endUserAddressIPv4.ipv4_address; |
| 1966 | f_send_gtpu(ctx[idx], f_gen_icmpv4_echo(saddr, dns1_addr)); |
| 1967 | repeat; |
| 1968 | } |
| 1969 | [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value udu { |
| 1970 | var octetstring gpdu := udu.gtpu.gtpu_IEs.g_PDU_IEs.data; |
| 1971 | var IPv4_packet ip4 := f_IPv4_dec(gpdu); |
| 1972 | if (ip4.header.ver != 4) { |
| 1973 | repeat; |
| 1974 | } |
| 1975 | var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload); |
| 1976 | if (not match(icmp4, (tr_ICMPv4_ERP, tr_ICMPv4_DU))) { |
| 1977 | repeat; |
| 1978 | } |
| 1979 | rx_pong := rx_pong + 1; |
| 1980 | if (rx_pong < num_ctx) { |
| 1981 | repeat; |
| 1982 | } |
| 1983 | setverdict(pass); |
| 1984 | } |
| 1985 | [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); } |
| 1986 | [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); } |
| 1987 | } |
| 1988 | |
| 1989 | /* Let's close them now: */ |
| 1990 | next_req_ctx := 0; |
| 1991 | rx_resp_ctx := 0; |
| 1992 | T_next.start; |
| 1993 | alt { |
Pau Espin Pedrol | 45d5702 | 2022-03-08 13:49:02 +0100 | [diff] [blame^] | 1994 | [Gx_PROC.checkstate("Connected")] as_DIA_CCR(TERMINATION_REQUEST) { repeat; } |
Pau Espin Pedrol | 68c2af5 | 2022-02-25 11:56:17 +0100 | [diff] [blame] | 1995 | [] pingpong(); |
| 1996 | [] T_next.timeout { |
| 1997 | f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, ctx[next_req_ctx].teic_remote, ctx[next_req_ctx].nsapi, '1'B)); |
| 1998 | next_req_ctx := next_req_ctx + 1; |
| 1999 | if (next_req_ctx < num_ctx) { |
| 2000 | T_next.start; |
| 2001 | } |
| 2002 | repeat; |
| 2003 | } |
| 2004 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc { |
| 2005 | teic := oct2int(udc.gtpc.teid); |
| 2006 | if (not match(teic, (1 .. num_ctx))) { |
| 2007 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 2008 | "Rx Unexpected TEIC"); |
| 2009 | } |
| 2010 | rx_resp_ctx := rx_resp_ctx + 1; |
| 2011 | if (rx_resp_ctx < num_ctx) { |
| 2012 | repeat; |
| 2013 | } |
| 2014 | setverdict(pass); |
| 2015 | } |
| 2016 | [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); } |
| 2017 | [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); } |
| 2018 | } |
| 2019 | T_next.stop; |
| 2020 | |
| 2021 | T_default.stop; |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 2022 | f_shutdown_helper(); |
Pau Espin Pedrol | 68c2af5 | 2022-02-25 11:56:17 +0100 | [diff] [blame] | 2023 | } |
| 2024 | |
Pau Espin Pedrol | bfea835 | 2022-02-28 12:11:26 +0100 | [diff] [blame] | 2025 | /* Test callocation of PDP contexts until reaching addr pool exhaustion */ |
| 2026 | type record of OCT4 TEIClist; |
| 2027 | testcase TC_addr_pool_exhaustion() runs on GT_CT { |
| 2028 | var Gtp1cUnitdata udc; |
| 2029 | var Gtp1uUnitdata udu; |
| 2030 | var PdpContext ctx; |
| 2031 | timer T_next := 0.005; |
| 2032 | var integer next_req_ctx := 0; |
| 2033 | var integer rx_resp_ctx := 0; |
| 2034 | var integer num_ctx; |
| 2035 | var boolean cont_req := true; |
| 2036 | var CreatePDPContextResponse cpr; |
| 2037 | var TEIClist teic_list := {}; |
| 2038 | var integer teic; |
| 2039 | |
| 2040 | f_init(); |
| 2041 | |
| 2042 | T_default.start(120.0); |
| 2043 | |
| 2044 | T_next.start; |
| 2045 | alt { |
Pau Espin Pedrol | 45d5702 | 2022-03-08 13:49:02 +0100 | [diff] [blame^] | 2046 | [Gx_PROC.checkstate("Connected")] as_DIA_CCR(INITIAL_REQUEST) { repeat; } |
Pau Espin Pedrol | bfea835 | 2022-02-28 12:11:26 +0100 | [diff] [blame] | 2047 | [] pingpong(); |
| 2048 | [] T_next.timeout { |
| 2049 | if (cont_req) { |
| 2050 | if (next_req_ctx - rx_resp_ctx < 100) { /* if we have too many in progress, wait a bit to continue */ |
| 2051 | ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), f_rnd_msisdn('1234'O), c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 2052 | ctx.nsapi := '0001'B; |
| 2053 | ctx.teic := int2oct(next_req_ctx+1, 4); /* +1: skip TEIC=0 */ |
| 2054 | ctx.teid := int2oct(next_req_ctx+1, 4); /* +1: skip TEID=0 */ |
| 2055 | f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx.imsi, g_restart_ctr, |
| 2056 | ctx.teid, ctx.teic, ctx.nsapi, |
| 2057 | ctx.eua, ctx.apn, g_sgsn_ip_c, g_sgsn_ip_u, |
| 2058 | ctx.msisdn, ctx.pco_req, ctx.ratType, |
| 2059 | ctx.uli)); |
| 2060 | next_req_ctx := next_req_ctx + 1; |
| 2061 | } |
| 2062 | T_next.start; |
| 2063 | } |
| 2064 | repeat; |
| 2065 | } |
| 2066 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ?)) -> value udc { |
| 2067 | cpr := udc.gtpc.gtpc_pdu.createPDPContextResponse; |
| 2068 | |
| 2069 | if (cpr.cause.causevalue == '80'O) { |
| 2070 | teic_list := teic_list & {cpr.teidControlPlane.teidControlPlane}; |
| 2071 | } else { |
| 2072 | if (cont_req == true) { |
| 2073 | num_ctx := rx_resp_ctx; |
| 2074 | log("Successfully created ", num_ctx, " PDP contexts before exhausting the pool"); |
| 2075 | setverdict(pass); |
| 2076 | } |
| 2077 | cont_req := false; |
| 2078 | } |
| 2079 | rx_resp_ctx := rx_resp_ctx + 1; |
| 2080 | if (not cont_req and next_req_ctx == rx_resp_ctx) { |
| 2081 | break; |
| 2082 | } else { |
| 2083 | repeat; |
| 2084 | } |
| 2085 | } |
| 2086 | [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); } |
| 2087 | [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); } |
| 2088 | } |
| 2089 | |
| 2090 | /* Let's close them now: */ |
| 2091 | next_req_ctx := 0; |
| 2092 | rx_resp_ctx := 0; |
| 2093 | T_next.start; |
| 2094 | alt { |
Pau Espin Pedrol | 45d5702 | 2022-03-08 13:49:02 +0100 | [diff] [blame^] | 2095 | [Gx_PROC.checkstate("Connected")] as_DIA_CCR(TERMINATION_REQUEST) { repeat; } |
Pau Espin Pedrol | bfea835 | 2022-02-28 12:11:26 +0100 | [diff] [blame] | 2096 | [] pingpong(); |
| 2097 | [] T_next.timeout { |
| 2098 | f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, teic_list[next_req_ctx], '0001'B, '1'B)); |
| 2099 | next_req_ctx := next_req_ctx + 1; |
| 2100 | if (next_req_ctx < num_ctx) { |
| 2101 | T_next.start; |
| 2102 | } |
| 2103 | repeat; |
| 2104 | } |
| 2105 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ?)) -> value udc { |
| 2106 | teic := oct2int(udc.gtpc.teid); |
| 2107 | if (not match(teic, (1 .. num_ctx))) { |
| 2108 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 2109 | "Rx Unexpected TEIC"); |
| 2110 | } |
| 2111 | rx_resp_ctx := rx_resp_ctx + 1; |
| 2112 | if (rx_resp_ctx < num_ctx) { |
| 2113 | repeat; |
| 2114 | } |
| 2115 | setverdict(pass); |
| 2116 | } |
| 2117 | [] GTPC.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPC"); } |
| 2118 | [] GTPU.receive { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Rx Unexpected GTPU"); } |
| 2119 | } |
| 2120 | T_next.stop; |
| 2121 | |
| 2122 | T_default.stop; |
Pau Espin Pedrol | c441ce0 | 2022-03-07 14:35:45 +0100 | [diff] [blame] | 2123 | f_shutdown_helper(); |
Pau Espin Pedrol | bfea835 | 2022-02-28 12:11:26 +0100 | [diff] [blame] | 2124 | } |
| 2125 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 2126 | control { |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 2127 | execute(TC_pdp4_act_deact()); |
| 2128 | execute(TC_pdp4_act_deact_ipcp()); |
Harald Welte | f829854 | 2019-04-10 10:15:28 +0200 | [diff] [blame] | 2129 | execute(TC_pdp4_act_deact_ipcp_pap_broken()); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 2130 | execute(TC_pdp4_act_deact_pcodns()); |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 2131 | execute(TC_pdp4_act_deact_gtpu_access()); |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 2132 | execute(TC_pdp4_act_deact_gtpu_access_wrong_saddr()); |
| 2133 | execute(TC_pdp4_act_deact_gtpu_access_ipv6_apn4()); |
Stefan Sperling | c479e4f | 2018-04-03 19:34:16 +0200 | [diff] [blame] | 2134 | execute(TC_pdp4_clients_interact_with_txseq()); |
| 2135 | execute(TC_pdp4_clients_interact_without_txseq()); |
Philipp Maier | 33e5261 | 2018-05-30 17:22:02 +0200 | [diff] [blame] | 2136 | execute(TC_pdp4_act_deact_with_single_dns()); |
| 2137 | execute(TC_pdp4_act_deact_with_separate_dns()); |
Pau Espin Pedrol | cd326c5 | 2022-02-14 18:57:43 +0100 | [diff] [blame] | 2138 | execute(TC_pdp4_act_update_teic()); |
| 2139 | execute(TC_pdp4_act_update_teid()); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 2140 | |
| 2141 | execute(TC_pdp6_act_deact()); |
| 2142 | execute(TC_pdp6_act_deact_pcodns()); |
| 2143 | execute(TC_pdp6_act_deact_icmp6()); |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 2144 | execute(TC_pdp6_act_deact_gtpu_access()); |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 2145 | execute(TC_pdp6_act_deact_gtpu_access_wrong_ll_saddr()); |
| 2146 | execute(TC_pdp6_act_deact_gtpu_access_wrong_global_saddr()); |
| 2147 | execute(TC_pdp6_act_deact_gtpu_access_ipv4_apn6()); |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 2148 | execute(TC_pdp6_clients_interact()); |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 2149 | |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 2150 | execute(TC_pdp46_act_deact()); |
| 2151 | execute(TC_pdp46_act_deact_ipcp()); |
| 2152 | execute(TC_pdp46_act_deact_icmp6()); |
| 2153 | execute(TC_pdp46_act_deact_pcodns4()); |
| 2154 | execute(TC_pdp46_act_deact_pcodns6()); |
| 2155 | execute(TC_pdp46_act_deact_gtpu_access()); |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 2156 | execute(TC_pdp46_act_deact_gtpu_access_wrong_saddr_ipv4()); |
Pau Espin Pedrol | c6ac695 | 2022-02-14 11:19:23 +0100 | [diff] [blame] | 2157 | execute(TC_pdp46_act_deact_gtpu_access_wrong_ll_saddr_ipv6()); |
Pau Espin Pedrol | c8c0341 | 2022-02-11 13:39:26 +0100 | [diff] [blame] | 2158 | execute(TC_pdp46_act_deact_gtpu_access_wrong_global_saddr_ipv6()); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 2159 | execute(TC_pdp46_clients_interact()); |
Pau Espin Pedrol | 22d597f | 2019-08-21 16:16:58 +0200 | [diff] [blame] | 2160 | execute(TC_pdp46_act_deact_apn4()); |
Oliver Smith | ee6a088 | 2019-03-08 11:05:46 +0100 | [diff] [blame] | 2161 | |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 2162 | execute(TC_echo_req_resp()); |
Pau Espin Pedrol | 480e67f | 2022-02-09 16:37:47 +0100 | [diff] [blame] | 2163 | execute(TC_echo_req_resp_gtpu()); |
Pau Espin Pedrol | fa1ca02 | 2019-08-23 18:58:53 +0200 | [diff] [blame] | 2164 | execute(TC_pdp_act2_recovery()); |
Pau Espin Pedrol | 9a5f42f | 2019-05-27 20:04:35 +0200 | [diff] [blame] | 2165 | execute(TC_act_deact_retrans_duplicate()); |
Pau Espin Pedrol | 6916ec4 | 2019-08-23 16:15:07 +0200 | [diff] [blame] | 2166 | |
Pau Espin Pedrol | 6f319f9 | 2020-01-03 20:18:57 +0100 | [diff] [blame] | 2167 | execute(TC_pdp_act_restart_ctr_echo()); |
Pau Espin Pedrol | 68c2af5 | 2022-02-25 11:56:17 +0100 | [diff] [blame] | 2168 | |
| 2169 | execute(TC_lots_of_concurrent_pdp_ctx()); |
Pau Espin Pedrol | bfea835 | 2022-02-28 12:11:26 +0100 | [diff] [blame] | 2170 | /* Keep at the end, crashes older osmo-ggsn versions (OS#5469): */ |
| 2171 | execute(TC_addr_pool_exhaustion()); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 2172 | } |
Harald Welte | 379d45a | 2017-08-03 09:55:15 +0200 | [diff] [blame] | 2173 | } |