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