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