Harald Welte | 379d45a | 2017-08-03 09:55:15 +0200 | [diff] [blame] | 1 | module GGSN_Tests { |
| 2 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 3 | import from General_Types all; |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 4 | import from Osmocom_Types all; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 5 | import from IPL4asp_PortType all; |
| 6 | import from IPL4asp_Types all; |
| 7 | import from GTP_CodecPort all; |
| 8 | import from GTP_CodecPort_CtrlFunct all; |
Harald Welte | c69cf4e | 2018-02-17 20:57:02 +0100 | [diff] [blame^] | 9 | import from GTP_Templates all; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 10 | import from GTPC_Types all; |
| 11 | import from GTPU_Types all; |
Harald Welte | 71a3602 | 2017-12-04 18:55:58 +0100 | [diff] [blame] | 12 | import from IPCP_Types all; |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 13 | import from IP_Types all; |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 14 | import from ICMP_Types all; |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 15 | import from ICMPv6_Types all; |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 16 | import from Native_Functions all; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 17 | |
| 18 | const integer GTP0_PORT := 3386; |
| 19 | const integer GTP1C_PORT := 2123; |
| 20 | const integer GTP1U_PORT := 2152; |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 21 | |
| 22 | modulepar { |
| 23 | charstring m_bind_ip_gtpc := "127.23.42.1"; |
| 24 | charstring m_bind_ip_gtpu := "127.23.42.1"; |
| 25 | |
| 26 | charstring m_ggsn_ip_gtpc := "127.0.0.6"; |
| 27 | charstring m_ggsn_ip_gtpu := "127.0.0.6"; |
Pau Espin Pedrol | f69a438 | 2018-01-29 13:09:00 +0100 | [diff] [blame] | 28 | |
| 29 | charstring m_ggsn_ip4_dns1 := "192.168.100.1" |
| 30 | charstring m_ggsn_ip4_dns2 := "8.8.8.8" |
Pau Espin Pedrol | 363ba48 | 2018-01-29 18:42:00 +0100 | [diff] [blame] | 31 | charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888" |
| 32 | charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844" |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 33 | } |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 34 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 35 | type set PdpContext { |
| 36 | hexstring imsi, |
| 37 | octetstring msisdn optional, |
| 38 | octetstring apn, |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 39 | ProtConfigOptions pco_req optional, |
| 40 | ProtConfigOptions pco_neg optional, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 41 | EndUserAddress eua, |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 42 | OCT16 ip6_prefix optional, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 43 | BIT4 nsapi, |
| 44 | /* TEI (Data) local side */ |
| 45 | OCT4 teid, |
| 46 | /* TEI (Control) local side */ |
| 47 | OCT4 teic, |
| 48 | /* TEI (Data) remote side */ |
| 49 | OCT4 teid_remote, |
| 50 | /* TEI (Control) remote side */ |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 51 | OCT4 teic_remote |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 52 | } |
| 53 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 54 | type component GT_CT { |
| 55 | port GTPC_PT GTPC; |
| 56 | port GTPU_PT GTPU; |
| 57 | |
Harald Welte | 0be142b | 2017-08-13 13:28:10 +0200 | [diff] [blame] | 58 | var boolean g_initialized := false; |
| 59 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 60 | var OCT1 g_restart_ctr := '01'O; |
| 61 | /* FIXME: unify with g_bind_ip + parse from config file */ |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 62 | var OCT4 g_sgsn_ip_c; |
| 63 | var OCT4 g_sgsn_ip_u; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 64 | /* FIXME: parse remName from config file */ |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 65 | var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT }; |
| 66 | 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] | 67 | timer T_default := 3.0; |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 68 | |
| 69 | /* next to-be-sent GTP-C sequence number */ |
| 70 | var uint16_t g_c_seq_nr; |
| 71 | /* next to-be-sent GTP-U sequence number */ |
| 72 | var uint16_t g_d_seq_nr; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | function f_init() runs on GT_CT { |
Harald Welte | 0be142b | 2017-08-13 13:28:10 +0200 | [diff] [blame] | 76 | if (g_initialized == true) { |
| 77 | return; |
| 78 | } |
| 79 | g_initialized := true; |
| 80 | |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 81 | g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc); |
| 82 | g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu); |
| 83 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 84 | var Result res; |
| 85 | map(self:GTPC, system:GTPC); |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 86 | 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] | 87 | log("GTP1C ConnectionID: ", res.connId); |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 88 | g_peer_c.connId := res.connId; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 89 | |
| 90 | map(self:GTPU, system:GTPU); |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 91 | 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] | 92 | g_peer_u.connId:= res.connId; |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 93 | |
| 94 | g_restart_ctr := f_rnd_octstring(1); |
Harald Welte | 11dbc7b | 2017-08-13 18:57:56 +0200 | [diff] [blame] | 95 | g_c_seq_nr := f_rnd_int(65535); |
| 96 | g_d_seq_nr := f_rnd_int(65535); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 97 | } |
| 98 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 99 | /* Altstep implementing responses to any incoming echo requests */ |
| 100 | altstep pingpong() runs on GT_CT { |
| 101 | var Gtp1cUnitdata ud; |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 102 | var Gtp1uUnitdata udu; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 103 | [] GTPC.receive(tr_GTPC_PING(?)) -> value ud { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 104 | var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber); |
| 105 | GTPC.send(ts_GTPC_PONG(ud.peer, seq, '00'O)); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 106 | repeat; |
| 107 | }; |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 108 | [] GTPU.receive(tr_GTPU_PING(?)) -> value udu { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 109 | var uint16_t seq := oct2int(udu.gtpu.opt_part.sequenceNumber); |
| 110 | GTPU.send(ts_GTPU_PONG(udu.peer, seq, '00'O)); |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 111 | }; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 112 | [] T_default.timeout { setverdict(fail); }; |
| 113 | } |
| 114 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 115 | /* 'internet' in DNS encoding */ |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 116 | const octetstring c_ApnInternet := '08696E7465726E6574'O; |
| 117 | const octetstring c_ApnInet6 := '05696E657436'O; |
| 118 | const octetstring c_ApnInet46 := '06696E65743436'O; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 119 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 120 | /* return random NSAPI */ |
| 121 | function f_rnd_nsapi() return BIT4 { |
| 122 | return int2bit(f_rnd_int(16), 4); |
| 123 | } |
| 124 | |
| 125 | /* return random TEI[DC] */ |
| 126 | function f_rnd_tei() return OCT4 { |
| 127 | return int2oct(f_rnd_int(4294967296), 4); |
| 128 | } |
| 129 | |
| 130 | /* define an (internal) representation of a PDP context */ |
| 131 | template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn, |
| 132 | EndUserAddress eua) := { |
| 133 | imsi := imsi, |
| 134 | msisdn := msisdn, |
| 135 | nsapi := f_rnd_nsapi(), |
| 136 | apn := apn, |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 137 | pco_req := omit, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 138 | eua := eua, |
| 139 | teid := f_rnd_tei(), |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 140 | teic := f_rnd_tei() |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /* send GTP-C for a given context and increment sequence number */ |
Harald Welte | 41575e9 | 2017-08-13 13:49:57 +0200 | [diff] [blame] | 144 | function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 145 | GTPC.send(data); |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 146 | g_c_seq_nr := g_c_seq_nr + 1; |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /* send GTP-U for a given context and increment sequence number */ |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 150 | function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT { |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 151 | GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data)); |
| 152 | g_d_seq_nr := g_d_seq_nr + 1; |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | /* send a PDP context activation */ |
| 156 | function f_pdp_ctx_act(inout PdpContext ctx) runs on GT_CT { |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 157 | var Gtp1cUnitdata ud; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 158 | var default d; |
| 159 | |
| 160 | log("sending CreatePDP"); |
Harald Welte | 41575e9 | 2017-08-13 13:49:57 +0200 | [diff] [blame] | 161 | 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] | 162 | ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn, |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 163 | g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req)); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 164 | T_default.start; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 165 | d := activate(pingpong()); |
| 166 | alt { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 167 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud { |
| 168 | var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse; |
| 169 | if (cpr.cause.causevalue == '80'O) { |
Harald Welte | 99ef9a4 | 2017-08-14 21:42:03 +0200 | [diff] [blame] | 170 | /* Check if EUA type corresponds to requested type */ |
| 171 | if (match(ctx.eua, t_EuaIPv4(?)) and |
| 172 | not match(cpr.endUserAddress, tr_EuaIPv4(?))){ |
| 173 | setverdict(fail); |
| 174 | } |
| 175 | if (match(ctx.eua, t_EuaIPv6(?)) and |
| 176 | not match(cpr.endUserAddress, tr_EuaIPv6(?))) { |
| 177 | setverdict(fail); |
| 178 | } |
| 179 | /* Check if PCO response corresponds to request */ |
| 180 | if (ispresent(ctx.pco_req)) { |
| 181 | if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and |
| 182 | not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) { |
| 183 | log("IPv4 DNS Container requested, but missing"); |
| 184 | setverdict(fail); |
| 185 | } |
| 186 | if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and |
| 187 | not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) { |
| 188 | log("IPv6 DNS Container requested, but missing"); |
| 189 | setverdict(fail); |
| 190 | } |
| 191 | } |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 192 | ctx.teid_remote := cpr.teidDataI.teidDataI; |
| 193 | ctx.teic_remote := cpr.teidControlPlane.teidControlPlane; |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 194 | ctx.eua := cpr.endUserAddress; |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 195 | ctx.pco_neg := cpr.protConfigOptions; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 196 | setverdict(pass); |
| 197 | } else { |
| 198 | setverdict(fail); |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | deactivate(d); |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 203 | T_default.stop; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 204 | } |
| 205 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 206 | function f_pdp_ctx_del(PdpContext ctx, template BIT1 teardown_ind) runs on GT_CT { |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 207 | var Gtp1cUnitdata ud; |
| 208 | var default d; |
| 209 | |
Harald Welte | 41575e9 | 2017-08-13 13:49:57 +0200 | [diff] [blame] | 210 | 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] | 211 | T_default.start; |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 212 | d := activate(pingpong()); |
| 213 | alt { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 214 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ctx.teic)) -> value ud { |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 215 | if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == '80'O) { |
| 216 | setverdict(pass); |
| 217 | } else { |
| 218 | setverdict(fail); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | deactivate(d); |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 223 | T_default.stop; |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 224 | } |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 225 | /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */ |
| 226 | const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O; |
| 227 | /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */ |
| 228 | const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O; |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 229 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 230 | /* template for an ICMPv6 echo request */ |
| 231 | template PDU_ICMP ts_ICMPv4_ERQ := { |
| 232 | echo := { |
| 233 | type_field := 8, |
| 234 | code := 0, |
| 235 | checksum := '0000'O, |
| 236 | identifier := '0345'O, |
| 237 | sequence_number := '0001'O, |
| 238 | data := ''O |
| 239 | } |
| 240 | } |
| 241 | |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 242 | /* template for an ICMPv6 echo request */ |
| 243 | template PDU_ICMP tr_ICMPv4_ERQ := { |
| 244 | echo := { |
| 245 | type_field := 8, |
| 246 | code := 0, |
| 247 | checksum := ?, |
| 248 | identifier := ?, |
| 249 | sequence_number := ?, |
| 250 | data := ? |
| 251 | } |
| 252 | } |
| 253 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 254 | /* template for an ICMPv4 echo reply */ |
| 255 | template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := { |
| 256 | echo_reply := { |
| 257 | type_field := 0, |
| 258 | code := 0, |
| 259 | checksum := ?, |
| 260 | identifier := ?, |
| 261 | sequence_number := ?, |
| 262 | data := data |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | /* template for receiving/matching an ICMPv6 Destination Unreachable */ |
| 267 | template PDU_ICMP tr_ICMPv4_DU := { |
| 268 | destination_unreachable := { |
| 269 | type_field := 1, |
| 270 | code := ?, |
| 271 | checksum := ?, |
| 272 | unused := ?, |
| 273 | original_ip_msg := ? |
| 274 | } |
| 275 | } |
| 276 | |
| 277 | /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */ |
| 278 | template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := { |
| 279 | header := { |
| 280 | ver := 4, |
| 281 | hlen := 5, |
| 282 | tos := 0, |
| 283 | tlen := tlen, |
| 284 | id := 35902, |
| 285 | res := '0'B, |
| 286 | dfrag := '1'B, |
| 287 | mfrag := '0'B, |
| 288 | foffset := 0, |
| 289 | ttl := 64, |
| 290 | proto := proto, |
| 291 | cksum := 0, |
| 292 | srcaddr := srcaddr, |
| 293 | dstaddr := dstaddr |
| 294 | }, |
| 295 | ext_headers := omit, |
| 296 | payload := payload |
| 297 | } |
| 298 | |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 299 | /* template to generate a 'Prefix Information' ICMPv6 option */ |
| 300 | template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := { |
| 301 | prefixInformation := { |
| 302 | typeField := 3, |
| 303 | lengthIndicator := 8, |
| 304 | prefixLength := prefix_len, |
| 305 | reserved1 := '000000'B, |
| 306 | a_Bit := '0'B, |
| 307 | l_Bit := '0'B, |
| 308 | validLifetime := oct2int('FFFFFFFF'O), |
| 309 | preferredLifetime := oct2int('FFFFFFFF'O), |
| 310 | reserved2 := '00000000'O, |
| 311 | prefix := prefix |
| 312 | } |
| 313 | } |
| 314 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 315 | /* template for an ICMPv6 echo request */ |
| 316 | template PDU_ICMPv6 ts_ICMPv6_ERQ := { |
| 317 | echoRequest := { |
| 318 | typeField := 128, |
| 319 | code := 0, |
| 320 | checksum := '0000'O, |
| 321 | identifier := 0, |
| 322 | sequenceNr := 0, |
| 323 | data := ''O |
| 324 | } |
| 325 | } |
| 326 | |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 327 | /* template for an ICMPv6 router solicitation */ |
| 328 | template PDU_ICMPv6 ts_ICMPv6_RS := { |
| 329 | routerSolicitation := { |
| 330 | typeField := 133, |
| 331 | code := 0, |
| 332 | checksum := '0000'O, |
| 333 | reserved := '00000000'O, |
| 334 | /* TODO: do we need 'Source link-layer address' ? */ |
| 335 | options := omit |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | /* template for an ICMPv6 router advertisement */ |
| 340 | template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := { |
| 341 | routerAdvertisement := { |
| 342 | typeField := 134, |
| 343 | code := 0, |
| 344 | checksum := '0000'O, |
| 345 | curHopLimit := ?, |
| 346 | reserved := '000000'B, |
| 347 | o_Bit := '0'B, |
| 348 | m_Bit := '0'B, |
| 349 | routerLifetime := oct2int('FFFF'O), |
| 350 | reachableTime := oct2int('FFFFFFFF'O), |
| 351 | retransTimer := oct2int('FFFFFFFF'O), |
| 352 | options := { |
| 353 | ts_ICMP6_OptPrefix(prefix, prefix_len) |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := { |
| 359 | neighborSolicitation := { |
| 360 | typeField := 135, |
| 361 | code := 0, |
| 362 | checksum := '0000'O, |
| 363 | reserved := '00000000'O, |
| 364 | targetAddress := target_addr, |
| 365 | /* TODO: do we need 'Source link-layer address' ? */ |
| 366 | options := omit |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /* derive ICMPv6 link-local address from lower 64bit of link_id */ |
| 371 | /* template for receiving/matching an ICMPv6 'Prefix Information' option */ |
| 372 | template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := { |
| 373 | prefixInformation := { |
| 374 | typeField := 3, |
| 375 | lengthIndicator := 4, |
| 376 | prefixLength := prefix_len, |
| 377 | reserved1 := ?, |
| 378 | a_Bit := ?, |
| 379 | l_Bit := ?, |
| 380 | validLifetime := ?, |
| 381 | preferredLifetime := ?, |
| 382 | reserved2 := ?, |
| 383 | prefix := prefix |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | /* template for receiving/matching an ICMPv6 router advertisement */ |
| 388 | template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := { |
| 389 | routerAdvertisement := { |
| 390 | typeField := 134, |
| 391 | code := 0, |
| 392 | checksum := ?, |
| 393 | curHopLimit := ?, |
| 394 | reserved := ?, |
| 395 | o_Bit := '0'B, |
| 396 | m_Bit := '0'B, |
| 397 | routerLifetime := ?, |
| 398 | reachableTime := ?, |
| 399 | retransTimer := ?, |
| 400 | options := { |
| 401 | tr_ICMP6_OptPrefix(prefix, prefix_len) |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 406 | /* template for receiving/matching an ICMPv6 Destination Unreachable */ |
| 407 | template PDU_ICMPv6 tr_ICMPv6_DU := { |
| 408 | destinationUnreachable := { |
| 409 | typeField := 1, |
| 410 | code := ?, |
| 411 | checksum := ?, |
| 412 | unused := ?, |
| 413 | originalIpMsg := ? |
| 414 | } |
| 415 | } |
| 416 | |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 417 | /* template for an ICMPv6 echo request */ |
| 418 | template PDU_ICMPv6 tr_ICMPv6_ERQ := { |
| 419 | echoRequest := { |
| 420 | typeField := 128, |
| 421 | code := 0, |
| 422 | checksum := ?, |
| 423 | identifier := ?, |
| 424 | sequenceNr := ?, |
| 425 | data := ? |
| 426 | } |
| 427 | } |
| 428 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 429 | /* template for receiving/matching an ICMPv6 echo reply */ |
| 430 | template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := { |
| 431 | echoReply := { |
| 432 | typeField := 129, |
| 433 | code := 0, |
| 434 | checksum := ?, |
| 435 | identifier := ?, |
| 436 | sequenceNr := ?, |
| 437 | data := data |
| 438 | } |
| 439 | } |
| 440 | |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 441 | /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */ |
| 442 | template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := { |
| 443 | header := { |
| 444 | ver := 6, |
| 445 | trclass := 0, |
| 446 | flabel := 0, |
| 447 | plen := 0, |
| 448 | nexthead := nexthead, |
| 449 | hlim := hlim, |
| 450 | srcaddr := srcaddr, |
| 451 | dstaddr := dstaddr |
| 452 | }, |
| 453 | ext_headers := omit, |
| 454 | payload := payload |
| 455 | } |
| 456 | |
| 457 | function f_ipv6_link_local(in OCT16 link_id) return OCT16 { |
| 458 | return 'FE80000000000000'O & substr(link_id, 8, 8); |
| 459 | } |
| 460 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 461 | function f_ipv6_global(in OCT16 link_id) return OCT16 { |
| 462 | return substr(link_id, 0, 8) & '1234123412341234'O; |
| 463 | } |
| 464 | |
| 465 | /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */ |
| 466 | function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 { |
| 467 | var integer i; |
| 468 | var octetstring res := substr(addr, 0, prefix); |
| 469 | for (i := prefix; i < lengthof(addr); i := i + 1) { |
| 470 | var octetstring a := addr[i] xor4b '11'O; |
| 471 | res := res & a; |
| 472 | } |
| 473 | return res; |
| 474 | } |
| 475 | |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 476 | /* Compute solicited-node multicast address as per RFC4291 2.7.1 */ |
| 477 | function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 { |
| 478 | return 'FF0200000000000000000001FF'O & substr(addr, 13, 3); |
| 479 | } |
| 480 | |
| 481 | /* generate and encode ICMPv6 router solicitation */ |
| 482 | function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring { |
| 483 | const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O; |
| 484 | var OCT16 saddr := f_ipv6_link_local(link_id); |
| 485 | |
| 486 | var octetstring tmp; |
| 487 | tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast); |
| 488 | var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp)); |
| 489 | |
| 490 | return f_IPv6_enc(ip6); |
| 491 | } |
| 492 | |
| 493 | /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */ |
| 494 | function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring { |
| 495 | var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address; |
| 496 | return f_gen_icmpv6_router_solicitation(interface_id); |
| 497 | } |
| 498 | |
| 499 | /* generate and encode ICMPv6 neighbor solicitation */ |
| 500 | function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring { |
| 501 | var octetstring tmp; |
| 502 | tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr); |
| 503 | var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp)); |
| 504 | return f_IPv6_enc(ip6); |
| 505 | } |
| 506 | |
| 507 | /* generate and encode ICMPv6 neighbor solicitation for PDP Context */ |
| 508 | function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring { |
| 509 | var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address; |
| 510 | var OCT16 link_local := f_ipv6_link_local(interface_id); |
| 511 | var OCT16 daddr := f_ipv6_sol_node_mcast(link_local); |
| 512 | |
| 513 | return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local); |
| 514 | } |
| 515 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 516 | /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */ |
| 517 | function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring { |
| 518 | var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ)); |
| 519 | var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp)); |
| 520 | var octetstring data := f_IPv4_enc(ip4); |
| 521 | var OCT2 cksum := f_IPv4_checksum(data); |
| 522 | data[10] := cksum[0]; |
| 523 | data[11] := cksum[1]; |
| 524 | return data; |
| 525 | } |
| 526 | |
| 527 | /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */ |
| 528 | function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring { |
| 529 | var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr); |
| 530 | var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp)); |
| 531 | var octetstring data := f_IPv6_enc(ip6); |
| 532 | return data; |
| 533 | } |
| 534 | |
| 535 | /* Wait for ICMPv4 from GTP */ |
| 536 | 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] | 537 | var Gtp1uUnitdata ud; |
| 538 | T_default.start; |
| 539 | alt { |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 540 | [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud { |
| 541 | var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data; |
| 542 | var IPv4_packet ip4 := f_IPv4_dec(gpdu); |
| 543 | if (ip4.header.ver != 4) { |
| 544 | repeat; |
| 545 | } |
| 546 | var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload); |
| 547 | if (not match(icmp4, expected)) { |
| 548 | repeat; |
| 549 | } |
| 550 | } |
| 551 | [] GTPU.receive { setverdict(fail); } |
| 552 | [] T_default.timeout { setverdict(fail); } |
| 553 | } |
| 554 | T_default.stop; |
| 555 | } |
| 556 | |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 557 | /* Wait for ICMPv4 echo request from GTP */ |
| 558 | function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT { |
| 559 | f_wait_icmp4(ctx, tr_ICMPv4_ERQ); |
| 560 | } |
| 561 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 562 | /* Wait for ICMPv4 echo reply (or unreachable) from GTP */ |
| 563 | function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT { |
| 564 | f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU)); |
| 565 | } |
| 566 | |
| 567 | /* Wait for ICMPv6 from GTP */ |
| 568 | function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT { |
| 569 | var Gtp1uUnitdata ud; |
| 570 | T_default.start; |
| 571 | alt { |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 572 | [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud { |
| 573 | var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data; |
| 574 | var IPv6_packet ip6 := f_IPv6_dec(gpdu); |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 575 | if (ip6.header.ver != 6 or ip6.header.nexthead != 58) { |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 576 | repeat; |
| 577 | } |
| 578 | var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload); |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 579 | if (not match(icmp6, expected)) { |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 580 | repeat; |
| 581 | } |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 582 | /* We are waiting for RA, update ctx */ |
| 583 | if (match(icmp6, tr_ICMPv6_RA(?, 64))) { |
| 584 | ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix; |
| 585 | log("RA with /64 prefix ", ctx.ip6_prefix); |
| 586 | } |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 587 | } |
| 588 | [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; } |
| 589 | [] GTPU.receive { setverdict(fail); } |
| 590 | [] T_default.timeout { setverdict(fail); } |
| 591 | } |
| 592 | T_default.stop; |
| 593 | } |
| 594 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 595 | /* wait for GGSN to send us an ICMPv6 router advertisement */ |
| 596 | function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT { |
| 597 | f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64)); |
| 598 | } |
| 599 | |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 600 | /* Wait for ICMPv6 echo request from GTP */ |
| 601 | function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT { |
| 602 | f_wait_icmp6(ctx, tr_ICMPv6_ERQ); |
| 603 | } |
| 604 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 605 | /* Wait for ICMPv6 echo reply (or unreachable) from GTP */ |
| 606 | function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT { |
| 607 | f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU)); |
| 608 | } |
| 609 | |
| 610 | /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */ |
| 611 | function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT { |
| 612 | T_default.start; |
| 613 | alt { |
| 614 | [] GTPU.receive { setverdict(fail); } |
| 615 | [] T_default.timeout { } |
| 616 | } |
| 617 | T_default.stop; |
| 618 | } |
| 619 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 620 | /* 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] | 621 | testcase TC_pdp6_act_deact() runs on GT_CT { |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 622 | f_init(); |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 623 | |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 624 | 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] | 625 | f_pdp_ctx_act(ctx); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 626 | f_pdp_ctx_del(ctx, '1'B); |
| 627 | } |
| 628 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 629 | /* 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] | 630 | testcase TC_pdp6_act_deact_pcodns() runs on GT_CT { |
| 631 | f_init(); |
| 632 | |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 633 | 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] | 634 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 635 | f_pdp_ctx_act(ctx); |
Pau Espin Pedrol | 363ba48 | 2018-01-29 18:42:00 +0100 | [diff] [blame] | 636 | |
| 637 | /* verify PCO contains both primary and secondary DNS */ |
| 638 | var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1); |
| 639 | if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) { |
| 640 | setverdict(fail, "Primary DNS IPv6 PCO option not found"); |
| 641 | } |
| 642 | |
| 643 | var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2); |
| 644 | if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) { |
| 645 | setverdict(fail, "Secondary DNS IPv6 PCO option not found"); |
| 646 | } |
| 647 | |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 648 | f_pdp_ctx_del(ctx, '1'B); |
| 649 | } |
| 650 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 651 | /* 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] | 652 | testcase TC_pdp6_act_deact_icmp6() runs on GT_CT { |
| 653 | f_init(); |
| 654 | |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 655 | 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] | 656 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 657 | f_pdp_ctx_act(ctx); |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 658 | |
| 659 | //f_send_gtpu(ctx, c_router_solicit); |
| 660 | //f_send_gtpu(ctx, c_neigh_solicit); |
| 661 | |
| 662 | f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx)); |
| 663 | f_wait_rtr_adv(ctx); |
| 664 | f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx)); |
| 665 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 666 | f_pdp_ctx_del(ctx, '1'B); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 667 | } |
| 668 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 669 | /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement. |
| 670 | Test we can send ICMPv6 ping over GTPU to DNS server. */ |
| 671 | testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT { |
| 672 | f_init(); |
| 673 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn))); |
| 674 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 675 | f_pdp_ctx_act(ctx); |
| 676 | |
| 677 | f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx)); |
| 678 | f_wait_rtr_adv(ctx); |
| 679 | f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx)); |
| 680 | |
| 681 | var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O); |
| 682 | |
| 683 | /* Check if we can use valid link-local src addr. */ |
| 684 | var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
| 685 | f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr)); |
| 686 | f_wait_icmp6_echo_reply(ctx); |
| 687 | |
| 688 | /* Check that attempting RA with another ll src addr won't work, packet dropped: */ |
| 689 | var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8); |
| 690 | f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong)); |
| 691 | f_wait_gtpu_fail(ctx); |
| 692 | |
| 693 | /* Check if we can use valid global src addr, should work */ |
| 694 | var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
| 695 | f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr)); |
| 696 | f_wait_icmp6_echo_reply(ctx); |
| 697 | |
| 698 | /* Assert that packets with wrong global src addr are dropped by GGSN */ |
| 699 | var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob); |
| 700 | f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr)); |
| 701 | f_wait_gtpu_fail(ctx); |
| 702 | |
| 703 | /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped) */ |
| 704 | var OCT4 saddr_v4 := f_inet_addr("192.168.10.2"); |
| 705 | var OCT4 daddr_v4 := f_inet_addr("8.8.8.8"); |
| 706 | f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4)); |
| 707 | f_wait_gtpu_fail(ctx); |
| 708 | |
| 709 | f_pdp_ctx_del(ctx, '1'B); |
| 710 | } |
| 711 | |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 712 | /* Validate if different clients (pdp ctx) can reach one another through GGSN. */ |
| 713 | testcase TC_pdp6_clients_interact() runs on GT_CT { |
| 714 | f_init(); |
| 715 | var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn))); |
| 716 | var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn))); |
| 717 | f_pdp_ctx_act(ctxA); |
| 718 | f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA)); |
| 719 | f_wait_rtr_adv(ctxA); |
| 720 | f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA)); |
| 721 | |
| 722 | f_pdp_ctx_act(ctxB); |
| 723 | f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB)); |
| 724 | f_wait_rtr_adv(ctxB); |
| 725 | f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB)); |
| 726 | |
| 727 | var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
| 728 | var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
| 729 | var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
| 730 | var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address); |
| 731 | |
| 732 | /* Validate if clients can interact using ll addr. */ |
| 733 | f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll)); |
| 734 | f_wait_gtpu_fail(ctxB); |
| 735 | |
| 736 | /* Validate if clients can interact using global addr. */ |
| 737 | f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob)); |
| 738 | f_wait_gtpu_fail(ctxB); |
| 739 | |
| 740 | f_pdp_ctx_del(ctxA, '1'B); |
| 741 | } |
| 742 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 743 | /* Test PDP context activation for dynamic IPv4 EUA without DNS request */ |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 744 | testcase TC_pdp4_act_deact() runs on GT_CT { |
| 745 | f_init(); |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 746 | 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] | 747 | f_pdp_ctx_act(ctx); |
| 748 | f_pdp_ctx_del(ctx, '1'B); |
| 749 | } |
| 750 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 751 | /* 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] | 752 | testcase TC_pdp4_act_deact_ipcp() runs on GT_CT { |
| 753 | f_init(); |
Pau Espin Pedrol | f69a438 | 2018-01-29 13:09:00 +0100 | [diff] [blame] | 754 | var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1); |
| 755 | var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2); |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 756 | 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] | 757 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 758 | f_pdp_ctx_act(ctx); |
Harald Welte | 71a3602 | 2017-12-04 18:55:58 +0100 | [diff] [blame] | 759 | /* verify IPCP is at all contained */ |
| 760 | if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) { |
| 761 | setverdict(fail, "IPCP not found in PCO"); |
| 762 | } |
| 763 | /* verify IPCP contains both primary and secondary DNS */ |
| 764 | 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] | 765 | if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) { |
| 766 | if (not match(ipcp, tr_IPCP_Ack_DNS(0))) { |
| 767 | setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found"); |
| 768 | } else { |
| 769 | setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values"); |
| 770 | } |
Harald Welte | 71a3602 | 2017-12-04 18:55:58 +0100 | [diff] [blame] | 771 | } |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 772 | f_pdp_ctx_del(ctx, '1'B); |
| 773 | } |
| 774 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 775 | /* 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] | 776 | testcase TC_pdp4_act_deact_pcodns() runs on GT_CT { |
| 777 | f_init(); |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 778 | 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] | 779 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 780 | f_pdp_ctx_act(ctx); |
Pau Espin Pedrol | 363ba48 | 2018-01-29 18:42:00 +0100 | [diff] [blame] | 781 | |
| 782 | /* verify PCO contains both primary and secondary DNS */ |
| 783 | var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1); |
| 784 | if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) { |
| 785 | setverdict(fail, "Primary DNS IPv4 PCO option not found"); |
| 786 | } |
| 787 | |
| 788 | var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2); |
| 789 | if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) { |
| 790 | setverdict(fail, "Secondary DNS IPv4 PCO option not found"); |
| 791 | } |
| 792 | |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 793 | f_pdp_ctx_del(ctx, '1'B); |
| 794 | } |
| 795 | |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 796 | /* Test PDP context activation for dynamic IPv4 EUA. |
| 797 | Test we can send ICMPv6 ping over GTPU to DNS server. */ |
| 798 | testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT { |
| 799 | f_init(); |
| 800 | var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 801 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
| 802 | f_pdp_ctx_act(ctx); |
| 803 | |
| 804 | var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O); |
| 805 | |
| 806 | /* Check if we can use valid global src addr, should work */ |
| 807 | var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address; |
| 808 | f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr)); |
| 809 | f_wait_icmp4_echo_reply(ctx); |
| 810 | |
| 811 | /* Assert that packets with wrong global src addr are dropped by GGSN */ |
| 812 | var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O); |
| 813 | f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr)); |
| 814 | f_wait_gtpu_fail(ctx); |
| 815 | |
| 816 | /* Send an IPv6 RA to APN4, should fail (packet dropped) */ |
| 817 | var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4"); |
| 818 | f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6)); |
| 819 | f_wait_gtpu_fail(ctx); |
| 820 | f_pdp_ctx_del(ctx, '1'B); |
| 821 | } |
| 822 | |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 823 | /* Validate if different clients (pdp ctx) can reach one another through GGSN. */ |
| 824 | testcase TC_pdp4_clients_interact() runs on GT_CT { |
| 825 | f_init(); |
| 826 | var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 827 | var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn))); |
| 828 | f_pdp_ctx_act(ctxA); |
| 829 | f_pdp_ctx_act(ctxB); |
| 830 | var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address; |
| 831 | var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address; |
| 832 | f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB)); |
| 833 | f_wait_icmp4_echo_request(ctxB); |
| 834 | |
| 835 | f_pdp_ctx_del(ctxA, '1'B); |
| 836 | } |
| 837 | |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 838 | testcase TC_echo_req_resp() runs on GT_CT { |
| 839 | f_init(); |
| 840 | f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr)); |
| 841 | T_default.start; |
| 842 | alt { |
| 843 | [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); }; |
| 844 | [] GTPC.receive { repeat; }; |
| 845 | [] T_default.timeout { setverdict(fail); } |
| 846 | } |
| 847 | T_default.stop; |
| 848 | } |
| 849 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 850 | control { |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 851 | execute(TC_pdp4_act_deact()); |
| 852 | execute(TC_pdp4_act_deact_ipcp()); |
| 853 | execute(TC_pdp4_act_deact_pcodns()); |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 854 | execute(TC_pdp4_act_deact_gtpu_access()); |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 855 | execute(TC_pdp4_clients_interact()); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 856 | |
| 857 | execute(TC_pdp6_act_deact()); |
| 858 | execute(TC_pdp6_act_deact_pcodns()); |
| 859 | execute(TC_pdp6_act_deact_icmp6()); |
Pau Espin Pedrol | 3d9338f | 2018-01-29 20:42:54 +0100 | [diff] [blame] | 860 | execute(TC_pdp6_act_deact_gtpu_access()); |
Pau Espin Pedrol | 6c7285d | 2018-01-30 17:20:22 +0100 | [diff] [blame] | 861 | execute(TC_pdp6_clients_interact()); |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 862 | |
| 863 | execute(TC_echo_req_resp()); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 864 | } |
Harald Welte | 379d45a | 2017-08-03 09:55:15 +0200 | [diff] [blame] | 865 | } |