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