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; |
| 9 | import from GTPC_Types all; |
| 10 | import from GTPU_Types all; |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 11 | import from IP_Types all; |
| 12 | import from ICMPv6_Types all; |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 13 | import from Native_Functions all; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 14 | |
| 15 | const integer GTP0_PORT := 3386; |
| 16 | const integer GTP1C_PORT := 2123; |
| 17 | const integer GTP1U_PORT := 2152; |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 18 | |
| 19 | modulepar { |
| 20 | charstring m_bind_ip_gtpc := "127.23.42.1"; |
| 21 | charstring m_bind_ip_gtpu := "127.23.42.1"; |
| 22 | |
| 23 | charstring m_ggsn_ip_gtpc := "127.0.0.6"; |
| 24 | charstring m_ggsn_ip_gtpu := "127.0.0.6"; |
| 25 | } |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 26 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 27 | type set PdpContext { |
| 28 | hexstring imsi, |
| 29 | octetstring msisdn optional, |
| 30 | octetstring apn, |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 31 | ProtConfigOptions pco_req optional, |
| 32 | ProtConfigOptions pco_neg optional, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 33 | EndUserAddress eua, |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 34 | OCT16 ip6_prefix optional, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 35 | BIT4 nsapi, |
| 36 | /* TEI (Data) local side */ |
| 37 | OCT4 teid, |
| 38 | /* TEI (Control) local side */ |
| 39 | OCT4 teic, |
| 40 | /* TEI (Data) remote side */ |
| 41 | OCT4 teid_remote, |
| 42 | /* TEI (Control) remote side */ |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 43 | OCT4 teic_remote |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 44 | } |
| 45 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 46 | type component GT_CT { |
| 47 | port GTPC_PT GTPC; |
| 48 | port GTPU_PT GTPU; |
| 49 | |
Harald Welte | 0be142b | 2017-08-13 13:28:10 +0200 | [diff] [blame] | 50 | var boolean g_initialized := false; |
| 51 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 52 | var OCT1 g_restart_ctr := '01'O; |
| 53 | /* FIXME: unify with g_bind_ip + parse from config file */ |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 54 | var OCT4 g_sgsn_ip_c; |
| 55 | var OCT4 g_sgsn_ip_u; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 56 | /* FIXME: parse remName from config file */ |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 57 | var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT }; |
| 58 | 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] | 59 | timer T_default := 3.0; |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 60 | |
| 61 | /* next to-be-sent GTP-C sequence number */ |
| 62 | var uint16_t g_c_seq_nr; |
| 63 | /* next to-be-sent GTP-U sequence number */ |
| 64 | var uint16_t g_d_seq_nr; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | function f_init() runs on GT_CT { |
Harald Welte | 0be142b | 2017-08-13 13:28:10 +0200 | [diff] [blame] | 68 | if (g_initialized == true) { |
| 69 | return; |
| 70 | } |
| 71 | g_initialized := true; |
| 72 | |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 73 | g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc); |
| 74 | g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu); |
| 75 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 76 | var Result res; |
| 77 | map(self:GTPC, system:GTPC); |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 78 | 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] | 79 | log("GTP1C ConnectionID: ", res.connId); |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 80 | g_peer_c.connId := res.connId; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 81 | |
| 82 | map(self:GTPU, system:GTPU); |
Harald Welte | ddeecbb | 2017-08-18 22:53:30 +0200 | [diff] [blame] | 83 | 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] | 84 | g_peer_u.connId:= res.connId; |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 85 | |
| 86 | g_restart_ctr := f_rnd_octstring(1); |
Harald Welte | 11dbc7b | 2017-08-13 18:57:56 +0200 | [diff] [blame] | 87 | g_c_seq_nr := f_rnd_int(65535); |
| 88 | g_d_seq_nr := f_rnd_int(65535); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /* generalized GTP-C receive template */ |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 92 | template PDU_GTPC tr_GTP1C_PDU(template OCT1 msg_type, template OCT4 teid, template GTPC_PDUs pdu := ?) := { |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 93 | /* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an |
| 94 | * error if this flag is set to '1'. */ |
| 95 | pn_bit := '0'B, |
| 96 | /* Sequence number flag (S) shall be set to '1'. */ |
| 97 | s_bit := '1'B, |
| 98 | e_bit := ?, |
| 99 | spare := ?, |
| 100 | /* Protocol Type flag (PT) shall be set to '1'.*/ |
| 101 | pt := '1'B, |
| 102 | /* Version shall be set to decimal 1 ('001'). */ |
| 103 | version := '001'B, |
| 104 | messageType := msg_type, |
| 105 | lengthf := ?, |
| 106 | teid := teid, |
| 107 | opt_part := *, |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 108 | gtpc_pdu := pdu |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | /* generalized GTP-C send template */ |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 112 | template PDU_GTPC ts_GTP1C_PDU(OCT1 msg_type, OCT4 teid, GTPC_PDUs pdu, uint16_t seq_nr) := { |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 113 | /* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an |
| 114 | * error if this flag is set to '1'. */ |
| 115 | pn_bit := '0'B, |
| 116 | /* Sequence number flag (S) shall be set to '1'. */ |
| 117 | s_bit := '1'B, |
| 118 | e_bit := '0'B, |
| 119 | spare := '0'B, |
| 120 | /* Protocol Type flag (PT) shall be set to '1'.*/ |
| 121 | pt := '1'B, |
| 122 | /* Version shall be set to decimal 1 ('001'). */ |
| 123 | version := '001'B, |
| 124 | messageType := msg_type, |
| 125 | lengthf := 0, /* we assume encoder overwrites this */ |
| 126 | teid := teid, |
| 127 | opt_part := { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 128 | sequenceNumber := int2oct(seq_nr, 2), |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 129 | npduNumber := '00'O, |
| 130 | nextExtHeader := '00'O, |
| 131 | gTPC_extensionHeader_List := omit |
| 132 | }, |
| 133 | gtpc_pdu := pdu |
| 134 | } |
| 135 | |
| 136 | /* recovery IE */ |
| 137 | template Recovery_gtpc ts_Recovery(OCT1 restart_counter) := { |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 138 | type_gtpc := '0E'O, |
| 139 | restartCounter := restart_counter |
| 140 | } |
| 141 | |
| 142 | template Recovery_gtpc tr_Recovery(template OCT1 restart_counter) := { |
| 143 | type_gtpc := '0E'O, |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 144 | restartCounter := restart_counter |
| 145 | } |
| 146 | |
| 147 | /* template matching reception of GTP-C echo-request */ |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 148 | template Gtp1cUnitdata tr_GTPC_MsgType(template GtpPeer peer, template OCT1 msg_type, template OCT4 teid, template GTPC_PDUs pdus := ?) := { |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 149 | peer := peer, |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 150 | gtpc := tr_GTP1C_PDU(msg_type, teid, pdus) |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /* template matching reception of GTP-C echo-request */ |
| 154 | template Gtp1cUnitdata tr_GTPC_PING(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoRequest, '00000000'O); |
| 155 | |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 156 | template GTPC_PDUs tr_EchoRespPDU(template OCT1 restart_counter) := { |
| 157 | echoResponse := { |
| 158 | recovery := tr_Recovery(restart_counter), |
| 159 | private_extension_gtpc := * |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | /* template matching reception of GTP-C echo-response */ |
| 164 | template Gtp1cUnitdata tr_GTPC_PONG(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoResponse, '00000000'O, tr_EchoRespPDU(?)); |
| 165 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 166 | template GTPC_PDUs ts_EchoRespPDU(OCT1 restart_counter) := { |
| 167 | echoResponse := { |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 168 | recovery := ts_Recovery(restart_counter), |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 169 | private_extension_gtpc := omit |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | /* master template for senidng a GTP-C echo response */ |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 174 | template Gtp1cUnitdata ts_GTPC_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := { |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 175 | peer := peer, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 176 | gtpc := ts_GTP1C_PDU(echoResponse, '00000000'O, valueof(ts_EchoRespPDU(rest_ctr)), seq) |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 177 | } |
| 178 | |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 179 | template GTPC_PDUs ts_EchoReqPDU := { |
| 180 | echoRequest := { |
| 181 | private_extension_gtpc := omit |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | /* master template for sending a GTP-C echo request */ |
| 186 | template Gtp1cUnitdata ts_GTPC_PING(GtpPeer peer, uint16_t seq) := { |
| 187 | peer := peer, |
| 188 | gtpc := ts_GTP1C_PDU(echoRequest, '00000000'O, valueof(ts_EchoReqPDU), seq) |
| 189 | } |
| 190 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 191 | template EndUserAddress t_EuaIPv4(template OCT4 ip_addr) := { |
| 192 | type_gtpc := '80'O, |
| 193 | endUserAddress := { |
| 194 | endUserAddressIPv4 := { |
| 195 | lengthf := 2, |
| 196 | pdp_typeorg := '0001'B, |
| 197 | spare := '1111'B, |
| 198 | pdp_typenum := '21'O, |
| 199 | ipv4_address := ip_addr |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | template EndUserAddress t_EuaIPv4Dyn := t_EuaIPv4(omit); |
Harald Welte | 99ef9a4 | 2017-08-14 21:42:03 +0200 | [diff] [blame] | 204 | template EndUserAddress tr_EuaIPv4(template OCT4 ip_addr) modifies t_EuaIPv4 := { |
| 205 | endUserAddress := { |
| 206 | endUserAddressIPv4 := { |
| 207 | lengthf := 2+lengthof(ip_addr) |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 212 | template EndUserAddress t_EuaIPv6(template OCT16 ip_addr) := { |
| 213 | type_gtpc := '80'O, |
| 214 | endUserAddress := { |
| 215 | endUserAddressIPv6 := { |
| 216 | lengthf := 2, |
| 217 | pdp_typeorg := '0001'B, |
| 218 | spare := '1111'B, |
| 219 | pdp_typenum := '57'O, |
| 220 | ipv6_address := ip_addr |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | template EndUserAddress t_EuaIPv6Dyn := t_EuaIPv6(omit); |
Harald Welte | 99ef9a4 | 2017-08-14 21:42:03 +0200 | [diff] [blame] | 225 | template EndUserAddress tr_EuaIPv6(template OCT16 ip_addr) modifies t_EuaIPv6 := { |
| 226 | endUserAddress := { |
| 227 | endUserAddressIPv6 := { |
| 228 | lengthf := 2+lengthof(ip_addr) |
| 229 | } |
| 230 | } |
| 231 | } |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 232 | |
| 233 | template AccessPointName ts_APN(octetstring apn) := { |
| 234 | type_gtpc := '83'O, |
| 235 | lengthf := lengthof(apn), |
| 236 | apn_value := apn |
| 237 | } |
| 238 | |
| 239 | template GSN_Address_GTPC ts_GsnAddr(octetstring ip_addr) := { |
| 240 | type_gtpc := '85'O, |
| 241 | lengthf := lengthof(ip_addr), |
| 242 | addressf := ip_addr |
| 243 | } |
| 244 | |
| 245 | template MSISDN ts_Msisdn(octetstring msisdn) := { |
| 246 | type_gtpc := '86'O, |
| 247 | lengthf := lengthof(msisdn), |
| 248 | msisdn := msisdn |
| 249 | } |
| 250 | |
| 251 | template QualityOfServiceProfile ts_QosDefault := { |
| 252 | type_gtpc := '87'O, |
| 253 | lengthf := 4, |
| 254 | allocRetensionPrio := '00'O, |
| 255 | qos_ProfileValue := { |
| 256 | reliabilityClass := '011'B, |
| 257 | delayClass := '001'B, |
| 258 | spare1 := '00'B, |
| 259 | precedenceClass := '010'B, |
| 260 | spare2 := '0'B, |
| 261 | peakThroughput := '1001'B, |
| 262 | meanThroughput := '11111'B, |
| 263 | spare3 := '000'B, |
| 264 | deliverErroneusSDU := omit, |
| 265 | deliveryOrder := omit, |
| 266 | trafficClass := omit, |
| 267 | maxSDUSize := omit, |
| 268 | maxBitrateUplink := omit, |
| 269 | maxBitrateDownlink := omit, |
| 270 | sduErrorRatio := omit, |
| 271 | residualBER := omit, |
| 272 | trafficHandlingPriority := omit, |
| 273 | transferDelay := omit, |
| 274 | guaranteedBitRateUplink := omit, |
| 275 | guaranteedBitRateDownlink := omit, |
| 276 | sourceStatisticsDescriptor := omit, |
| 277 | signallingIndication := omit, |
| 278 | spare4 := omit, |
| 279 | maxBitrateDownlinkExt := omit, |
| 280 | guaranteedBitRateDownlinkExt := omit, |
| 281 | maxBitrateUplinkExt := omit, |
| 282 | guaranteedBitRateUplinkExt := omit |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | template IMSI_gtpc ts_Imsi(hexstring digits) := { |
| 287 | type_gtpc := '02'O, |
| 288 | digits := digits, |
| 289 | padding := 'F'H |
| 290 | } |
| 291 | |
| 292 | template GTPC_PDUs ts_CreatePdpPDU(hexstring imsi, OCT1 restart_ctr, OCT4 teid_data, OCT4 teid_ctrl, |
| 293 | BIT4 nsapi, EndUserAddress eua, octetstring apn, |
| 294 | octetstring sgsn_ip_sign, octetstring sgsn_ip_data, |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 295 | octetstring msisdn, template ProtConfigOptions pco := omit) := { |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 296 | createPDPContextRequest := { |
| 297 | imsi := ts_Imsi(imsi), |
| 298 | rai := omit, |
| 299 | recovery := ts_Recovery(restart_ctr), |
| 300 | selectionMode := { |
| 301 | type_gtpc := '0F'O, |
| 302 | selectModeValue := '00'B, |
| 303 | spare := '111111'B |
| 304 | }, |
| 305 | teidDataI := { |
| 306 | type_gtpc := '00'O, |
| 307 | teidDataI := teid_data |
| 308 | }, |
| 309 | teidControlPlane := { |
| 310 | type_gtpc := '00'O, |
| 311 | teidControlPlane := teid_ctrl |
| 312 | }, |
| 313 | nsapi := { |
| 314 | type_gtpc := '00'O, |
| 315 | nsapi := nsapi, |
| 316 | unused := '0000'B |
| 317 | }, |
| 318 | linked_nsapi := omit, |
| 319 | charging_char := omit, |
| 320 | trace_ref := omit, |
| 321 | trace_type := omit, |
| 322 | endUserAddress := eua, |
| 323 | accessPointName := ts_APN(apn), |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 324 | protConfigOptions := pco, |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 325 | sgsn_addr_signalling := ts_GsnAddr(sgsn_ip_sign), |
| 326 | sgsn_addr_traffic := ts_GsnAddr(sgsn_ip_data), |
| 327 | msisdn := ts_Msisdn(msisdn), |
| 328 | qualityOfServiceProfile := ts_QosDefault, |
| 329 | tft := omit, |
| 330 | triggerId := omit, |
| 331 | omcId := omit, |
| 332 | commonFlags := omit, |
| 333 | aPN_Restriction := omit, |
| 334 | ratType := omit, |
| 335 | userLocationInformation := omit, |
| 336 | mS_TimeZone := omit, |
| 337 | imeisv := omit, |
| 338 | camelChargingInformationContainer := omit, |
| 339 | additionalTraceInfo := omit, |
| 340 | correlationID := omit, |
| 341 | evolvedAllocationRetentionPriorityI := omit, |
| 342 | extendedCommonFlags := omit, |
| 343 | userCSGInformation := omit, |
| 344 | aPN_AMBR := omit, |
| 345 | signallingPriorityIndication := omit, |
| 346 | cN_OperatorSelectionEntity := omit, |
| 347 | private_extension_gtpc := omit |
| 348 | } |
| 349 | } |
| 350 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 351 | template Gtp1cUnitdata ts_GTPC_CreatePDP(GtpPeer peer, uint16_t seq, hexstring imsi, |
| 352 | OCT1 restart_ctr, OCT4 teid_data, |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 353 | OCT4 teid_ctrl, BIT4 nsapi, EndUserAddress eua, |
| 354 | octetstring apn, octetstring sgsn_ip_sign, |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 355 | octetstring sgsn_ip_data, octetstring msisdn, |
| 356 | template ProtConfigOptions pco := omit) := { |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 357 | peer := peer, |
| 358 | gtpc := ts_GTP1C_PDU(createPDPContextRequest, '00000000'O, |
| 359 | valueof(ts_CreatePdpPDU(imsi, restart_ctr, teid_data, teid_ctrl, |
| 360 | nsapi, eua, apn, sgsn_ip_sign, |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 361 | sgsn_ip_data, msisdn, pco)), seq) |
| 362 | } |
| 363 | |
Harald Welte | 99ef9a4 | 2017-08-14 21:42:03 +0200 | [diff] [blame] | 364 | /* PCO send base template */ |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 365 | template ProtConfigOptions ts_PCO := { |
| 366 | type_gtpc := '84'O, |
| 367 | lengthf := 0, |
| 368 | configProtocol := '000'B, |
| 369 | spare := '0000'B, |
| 370 | extension0 := '1'B, |
| 371 | protocols := {} |
| 372 | } |
Harald Welte | 99ef9a4 | 2017-08-14 21:42:03 +0200 | [diff] [blame] | 373 | /* PCO receive base template */ |
| 374 | template ProtConfigOptions tr_PCO := { |
| 375 | type_gtpc := '84'O, |
| 376 | lengthf := ?, |
| 377 | configProtocol := '000'B, |
| 378 | spare := ?, |
| 379 | extension0 := '1'B, |
| 380 | protocols := {} |
| 381 | } |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 382 | |
| 383 | template ProtConfigOptions ts_PCO_IPv6_DNS modifies ts_PCO := { |
| 384 | protocols := { |
| 385 | { protocolID := '0003'O, lengthProtoID := 0, protoIDContents := ''O } |
| 386 | } |
| 387 | } |
Harald Welte | 99ef9a4 | 2017-08-14 21:42:03 +0200 | [diff] [blame] | 388 | template ProtConfigOptions tr_PCO_IPv6_DNS_resp(template OCT16 contents) modifies tr_PCO := { |
| 389 | protocols := { |
| 390 | { protocolID := '0003'O, lengthProtoID := 16, protoIDContents := contents } |
| 391 | } |
| 392 | } |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 393 | |
| 394 | template ProtConfigOptions ts_PCO_IPv4_DNS_IPCP modifies ts_PCO := { |
| 395 | protocols := { |
| 396 | { protocolID := '8021'O, lengthProtoID := 16, protoIDContents := '01000010810600000000830600000000'O } |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | template ProtConfigOptions ts_PCO_IPv4_DNS_CONT modifies ts_PCO := { |
| 401 | protocols := { |
| 402 | { protocolID := '000d'O, lengthProtoID := 0, protoIDContents := ''O } |
| 403 | } |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 404 | } |
Harald Welte | 99ef9a4 | 2017-08-14 21:42:03 +0200 | [diff] [blame] | 405 | template ProtConfigOptions tr_PCO_IPv4_DNS_CONT_resp(template OCT4 contents) modifies tr_PCO := { |
| 406 | protocols := { |
| 407 | { protocolID := '000d'O, lengthProtoID := 4, protoIDContents := contents } |
| 408 | } |
| 409 | } |
| 410 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 411 | |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 412 | function f_teardown_ind_IE(in template BIT1 ind) return template TearDownInd { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 413 | /* |
| 414 | if (not isvalue(ind)) { |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 415 | return omit; |
| 416 | } |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 417 | */ |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 418 | var TearDownInd ret := { |
| 419 | type_gtpc := '13'O, |
| 420 | tdInd := valueof(ind), |
| 421 | spare:= '0000000'B |
| 422 | } |
| 423 | return ret; |
| 424 | } |
| 425 | |
| 426 | template GTPC_PDUs ts_DeletePdpPDU(BIT4 nsapi, template BIT1 teardown_ind) := { |
| 427 | deletePDPContextRequest := { |
| 428 | cause := omit, |
| 429 | tearDownIndicator := f_teardown_ind_IE(teardown_ind), |
| 430 | nsapi := { |
| 431 | type_gtpc := '14'O, |
| 432 | nsapi := nsapi, |
| 433 | unused := '0000'B |
| 434 | }, |
| 435 | protConfigOptions := omit, |
| 436 | userLocationInformation := omit, |
| 437 | mS_TimeZone := omit, |
| 438 | extendedCommonFlags := omit, |
| 439 | uLI_Timestamp := omit, |
| 440 | private_extension_gtpc := omit |
| 441 | } |
| 442 | } |
| 443 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 444 | template Gtp1cUnitdata ts_GTPC_DeletePDP(GtpPeer peer, uint16_t seq, OCT4 teid, |
| 445 | BIT4 nsapi, template BIT1 teardown_ind) := { |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 446 | peer := peer, |
| 447 | gtpc := ts_GTP1C_PDU(deletePDPContextRequest, teid, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 448 | valueof(ts_DeletePdpPDU(nsapi, teardown_ind)), seq) |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 452 | /* GTP-U */ |
| 453 | |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 454 | template PDU_GTPU tr_GTP1U_PDU(template OCT1 msg_type, template OCT4 teid, template GTPU_IEs ies := ?) := { |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 455 | pn_bit := ?, |
| 456 | s_bit := ?, |
| 457 | e_bit := ?, |
| 458 | spare := ?, |
| 459 | /* Protocol Type flag (PT) shall be set to '1' in GTP */ |
| 460 | pt := '1'B, |
| 461 | /* Version shall be set to decimal 1 ('001'). */ |
| 462 | version := '001'B, |
| 463 | messageType := msg_type, |
| 464 | lengthf := ?, |
| 465 | teid := teid, |
| 466 | opt_part := *, |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 467 | gtpu_IEs := ies |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /* generalized GTP-U send template */ |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 471 | template PDU_GTPU ts_GTP1U_PDU(OCT1 msg_type, uint16_t seq, OCT4 teid, GTPU_IEs ies) := { |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 472 | /* N-PDU Number flag (PN): the GTP-U header contains a meaningful N-PDU Number field if the PN |
| 473 | * flag is set to 1. */ |
| 474 | pn_bit := '0'B, /* we assume the encoder overwrites this if an optional part is given */ |
| 475 | /* If the Sequence Number flag (S) is set to '1' the sequence number field is present and |
| 476 | * meaningful otherwise it is set to '0'. For GTP-U messages Echo Request, Echo Response, |
| 477 | * Error Indication and Supported Extension Headers Notification, the S flag shall be set to '1'. */ |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 478 | s_bit := '1'B, /* we assume the encoder overwrites this if an optional part is given */ |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 479 | /* Extension header presence */ |
| 480 | e_bit := '0'B, |
| 481 | spare := '0'B, |
| 482 | /* Protocol Type flag (PT) shall be set to '1' in GTP */ |
| 483 | pt := '1'B, |
| 484 | /* Version shall be set to decimal 1 ('001'). */ |
| 485 | version := '001'B, |
| 486 | messageType := msg_type, |
| 487 | lengthf := 0, /* we assume encoder overwrites this */ |
| 488 | teid := teid, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 489 | opt_part := { |
| 490 | sequenceNumber := int2oct(seq, 2), |
| 491 | npduNumber := '00'O, |
| 492 | nextExtHeader := '00'O, |
| 493 | gTPU_extensionHeader_List := omit |
| 494 | }, |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 495 | gtpu_IEs := ies |
| 496 | } |
| 497 | |
| 498 | template Gtp1uUnitdata tr_GTPU_MsgType(template GtpPeer peer, template OCT1 msg_type, template OCT4 teid) := { |
| 499 | peer := peer, |
| 500 | gtpu := tr_GTP1U_PDU(msg_type, teid) |
| 501 | } |
| 502 | |
| 503 | |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 504 | /* template matching reception of GTP-U echo-request */ |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 505 | template Gtp1uUnitdata tr_GTPU_PING(template GtpPeer peer) := tr_GTPU_MsgType(peer, echoRequest, '00000000'O); |
| 506 | |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 507 | /* template matching reception of GTP-U GPDU */ |
| 508 | template GTPU_IEs t_GPDU(template octetstring data) := { |
| 509 | g_PDU_IEs := { |
| 510 | data := data |
| 511 | } |
| 512 | } |
| 513 | template Gtp1uUnitdata tr_GTPU_GPDU(template GtpPeer peer, template OCT4 teid, template octetstring data := ?) := { |
| 514 | peer := peer, |
| 515 | gtpu := tr_GTP1U_PDU('FF'O, teid, t_GPDU(data)) |
| 516 | } |
| 517 | |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 518 | template GTPU_IEs ts_UEchoRespPDU(OCT1 restart_counter) := { |
| 519 | echoResponse_IEs := { |
| 520 | recovery_gtpu := { |
| 521 | type_gtpu := '00'O, /* we assume encoder fixes? */ |
| 522 | restartCounter := restart_counter |
| 523 | }, |
| 524 | private_extension_gtpu := omit |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | /* master template for sending a GTP-U echo response */ |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 529 | template Gtp1uUnitdata ts_GTPU_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := { |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 530 | peer := peer, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 531 | gtpu := ts_GTP1U_PDU(echoResponse, seq, '00000000'O, valueof(ts_UEchoRespPDU(rest_ctr))) |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 532 | } |
| 533 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 534 | /* master template for sending a GTP-U user plane data */ |
| 535 | template Gtp1uUnitdata ts_GTP1U_GPDU(GtpPeer peer, uint16_t seq, OCT4 teid, octetstring data) := { |
| 536 | peer := peer, |
| 537 | gtpu := ts_GTP1U_PDU('FF'O, seq, teid, { g_PDU_IEs := { data := data }}) |
| 538 | } |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 539 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 540 | /* Altstep implementing responses to any incoming echo requests */ |
| 541 | altstep pingpong() runs on GT_CT { |
| 542 | var Gtp1cUnitdata ud; |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 543 | var Gtp1uUnitdata udu; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 544 | [] GTPC.receive(tr_GTPC_PING(?)) -> value ud { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 545 | var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber); |
| 546 | GTPC.send(ts_GTPC_PONG(ud.peer, seq, '00'O)); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 547 | repeat; |
| 548 | }; |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 549 | [] GTPU.receive(tr_GTPU_PING(?)) -> value udu { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 550 | var uint16_t seq := oct2int(udu.gtpu.opt_part.sequenceNumber); |
| 551 | GTPU.send(ts_GTPU_PONG(udu.peer, seq, '00'O)); |
Harald Welte | 3af8948 | 2017-08-04 16:20:23 +0200 | [diff] [blame] | 552 | }; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 553 | [] T_default.timeout { setverdict(fail); }; |
| 554 | } |
| 555 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 556 | /* 'internet' in DNS encoding */ |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 557 | const octetstring c_ApnInternet := '08696E7465726E6574'O; |
| 558 | const octetstring c_ApnInet6 := '05696E657436'O; |
| 559 | const octetstring c_ApnInet46 := '06696E65743436'O; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 560 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 561 | /* return random integer between 0 and max */ |
| 562 | function f_rnd_int(integer max) return integer { |
| 563 | return float2int(rnd()*int2float(max)); |
| 564 | } |
| 565 | |
| 566 | /* return random NSAPI */ |
| 567 | function f_rnd_nsapi() return BIT4 { |
| 568 | return int2bit(f_rnd_int(16), 4); |
| 569 | } |
| 570 | |
| 571 | /* return random TEI[DC] */ |
| 572 | function f_rnd_tei() return OCT4 { |
| 573 | return int2oct(f_rnd_int(4294967296), 4); |
| 574 | } |
| 575 | |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 576 | /* return hexstring composed of random digits */ |
| 577 | function f_rnd_hexstring(in integer len, in integer max := 15) return hexstring { |
| 578 | var integer i; |
| 579 | var hexstring ret := ''H; |
| 580 | for (i := 0; i < len; i := i + 1) { |
| 581 | ret := ret & int2hex(f_rnd_int(max), 1); |
| 582 | } |
| 583 | return ret; |
| 584 | } |
| 585 | |
| 586 | /* return octetstring composed of random bytes */ |
| 587 | function f_rnd_octstring(in integer len) return octetstring { |
| 588 | var integer i; |
| 589 | var octetstring ret := ''O; |
| 590 | for (i := 0; i < len; i := i + 1) { |
| 591 | ret := ret & int2oct(f_rnd_int(255), 1); |
| 592 | } |
| 593 | return ret; |
| 594 | } |
| 595 | |
| 596 | function f_rnd_imsi(in hexstring prefix) return hexstring { |
| 597 | return prefix & f_rnd_hexstring(15 - lengthof(prefix), 9); |
| 598 | } |
| 599 | |
| 600 | function f_rnd_msisdn(in octetstring prefix, integer len := 6) return octetstring { |
| 601 | return prefix & f_rnd_octstring(len - lengthof(prefix)); |
| 602 | } |
| 603 | |
| 604 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 605 | /* define an (internal) representation of a PDP context */ |
| 606 | template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn, |
| 607 | EndUserAddress eua) := { |
| 608 | imsi := imsi, |
| 609 | msisdn := msisdn, |
| 610 | nsapi := f_rnd_nsapi(), |
| 611 | apn := apn, |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 612 | pco_req := omit, |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 613 | eua := eua, |
| 614 | teid := f_rnd_tei(), |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 615 | teic := f_rnd_tei() |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /* send GTP-C for a given context and increment sequence number */ |
Harald Welte | 41575e9 | 2017-08-13 13:49:57 +0200 | [diff] [blame] | 619 | function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 620 | GTPC.send(data); |
Harald Welte | 5438b9d | 2017-08-13 13:27:48 +0200 | [diff] [blame] | 621 | g_c_seq_nr := g_c_seq_nr + 1; |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | /* send GTP-U for a given context and increment sequence number */ |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 625 | 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] | 626 | GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data)); |
| 627 | g_d_seq_nr := g_d_seq_nr + 1; |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /* send a PDP context activation */ |
| 631 | function f_pdp_ctx_act(inout PdpContext ctx) runs on GT_CT { |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 632 | var Gtp1cUnitdata ud; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 633 | var default d; |
| 634 | |
| 635 | log("sending CreatePDP"); |
Harald Welte | 41575e9 | 2017-08-13 13:49:57 +0200 | [diff] [blame] | 636 | 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] | 637 | ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn, |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 638 | 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] | 639 | T_default.start; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 640 | d := activate(pingpong()); |
| 641 | alt { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 642 | [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud { |
| 643 | var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse; |
| 644 | if (cpr.cause.causevalue == '80'O) { |
Harald Welte | 99ef9a4 | 2017-08-14 21:42:03 +0200 | [diff] [blame] | 645 | /* Check if EUA type corresponds to requested type */ |
| 646 | if (match(ctx.eua, t_EuaIPv4(?)) and |
| 647 | not match(cpr.endUserAddress, tr_EuaIPv4(?))){ |
| 648 | setverdict(fail); |
| 649 | } |
| 650 | if (match(ctx.eua, t_EuaIPv6(?)) and |
| 651 | not match(cpr.endUserAddress, tr_EuaIPv6(?))) { |
| 652 | setverdict(fail); |
| 653 | } |
| 654 | /* Check if PCO response corresponds to request */ |
| 655 | if (ispresent(ctx.pco_req)) { |
| 656 | if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and |
| 657 | not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) { |
| 658 | log("IPv4 DNS Container requested, but missing"); |
| 659 | setverdict(fail); |
| 660 | } |
| 661 | if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and |
| 662 | not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) { |
| 663 | log("IPv6 DNS Container requested, but missing"); |
| 664 | setverdict(fail); |
| 665 | } |
| 666 | } |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 667 | ctx.teid_remote := cpr.teidDataI.teidDataI; |
| 668 | ctx.teic_remote := cpr.teidControlPlane.teidControlPlane; |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 669 | ctx.eua := cpr.endUserAddress; |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 670 | ctx.pco_neg := cpr.protConfigOptions; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 671 | setverdict(pass); |
| 672 | } else { |
| 673 | setverdict(fail); |
| 674 | } |
| 675 | } |
| 676 | } |
| 677 | deactivate(d); |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 678 | T_default.stop; |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 679 | } |
| 680 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 681 | 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] | 682 | var Gtp1cUnitdata ud; |
| 683 | var default d; |
| 684 | |
Harald Welte | 41575e9 | 2017-08-13 13:49:57 +0200 | [diff] [blame] | 685 | 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] | 686 | T_default.start; |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 687 | d := activate(pingpong()); |
| 688 | alt { |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 689 | [] 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] | 690 | if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == '80'O) { |
| 691 | setverdict(pass); |
| 692 | } else { |
| 693 | setverdict(fail); |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | deactivate(d); |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 698 | T_default.stop; |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 699 | } |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 700 | /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */ |
| 701 | const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O; |
| 702 | /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */ |
| 703 | const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O; |
Harald Welte | f1e0d5a | 2017-08-05 08:51:22 +0200 | [diff] [blame] | 704 | |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 705 | /* template to generate a 'Prefix Information' ICMPv6 option */ |
| 706 | template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := { |
| 707 | prefixInformation := { |
| 708 | typeField := 3, |
| 709 | lengthIndicator := 8, |
| 710 | prefixLength := prefix_len, |
| 711 | reserved1 := '000000'B, |
| 712 | a_Bit := '0'B, |
| 713 | l_Bit := '0'B, |
| 714 | validLifetime := oct2int('FFFFFFFF'O), |
| 715 | preferredLifetime := oct2int('FFFFFFFF'O), |
| 716 | reserved2 := '00000000'O, |
| 717 | prefix := prefix |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | /* template for an ICMPv6 router solicitation */ |
| 722 | template PDU_ICMPv6 ts_ICMPv6_RS := { |
| 723 | routerSolicitation := { |
| 724 | typeField := 133, |
| 725 | code := 0, |
| 726 | checksum := '0000'O, |
| 727 | reserved := '00000000'O, |
| 728 | /* TODO: do we need 'Source link-layer address' ? */ |
| 729 | options := omit |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | /* template for an ICMPv6 router advertisement */ |
| 734 | template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := { |
| 735 | routerAdvertisement := { |
| 736 | typeField := 134, |
| 737 | code := 0, |
| 738 | checksum := '0000'O, |
| 739 | curHopLimit := ?, |
| 740 | reserved := '000000'B, |
| 741 | o_Bit := '0'B, |
| 742 | m_Bit := '0'B, |
| 743 | routerLifetime := oct2int('FFFF'O), |
| 744 | reachableTime := oct2int('FFFFFFFF'O), |
| 745 | retransTimer := oct2int('FFFFFFFF'O), |
| 746 | options := { |
| 747 | ts_ICMP6_OptPrefix(prefix, prefix_len) |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := { |
| 753 | neighborSolicitation := { |
| 754 | typeField := 135, |
| 755 | code := 0, |
| 756 | checksum := '0000'O, |
| 757 | reserved := '00000000'O, |
| 758 | targetAddress := target_addr, |
| 759 | /* TODO: do we need 'Source link-layer address' ? */ |
| 760 | options := omit |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | /* derive ICMPv6 link-local address from lower 64bit of link_id */ |
| 765 | /* template for receiving/matching an ICMPv6 'Prefix Information' option */ |
| 766 | template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := { |
| 767 | prefixInformation := { |
| 768 | typeField := 3, |
| 769 | lengthIndicator := 4, |
| 770 | prefixLength := prefix_len, |
| 771 | reserved1 := ?, |
| 772 | a_Bit := ?, |
| 773 | l_Bit := ?, |
| 774 | validLifetime := ?, |
| 775 | preferredLifetime := ?, |
| 776 | reserved2 := ?, |
| 777 | prefix := prefix |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | /* template for receiving/matching an ICMPv6 router advertisement */ |
| 782 | template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := { |
| 783 | routerAdvertisement := { |
| 784 | typeField := 134, |
| 785 | code := 0, |
| 786 | checksum := ?, |
| 787 | curHopLimit := ?, |
| 788 | reserved := ?, |
| 789 | o_Bit := '0'B, |
| 790 | m_Bit := '0'B, |
| 791 | routerLifetime := ?, |
| 792 | reachableTime := ?, |
| 793 | retransTimer := ?, |
| 794 | options := { |
| 795 | tr_ICMP6_OptPrefix(prefix, prefix_len) |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */ |
| 801 | template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := { |
| 802 | header := { |
| 803 | ver := 6, |
| 804 | trclass := 0, |
| 805 | flabel := 0, |
| 806 | plen := 0, |
| 807 | nexthead := nexthead, |
| 808 | hlim := hlim, |
| 809 | srcaddr := srcaddr, |
| 810 | dstaddr := dstaddr |
| 811 | }, |
| 812 | ext_headers := omit, |
| 813 | payload := payload |
| 814 | } |
| 815 | |
| 816 | function f_ipv6_link_local(in OCT16 link_id) return OCT16 { |
| 817 | return 'FE80000000000000'O & substr(link_id, 8, 8); |
| 818 | } |
| 819 | |
| 820 | /* Compute solicited-node multicast address as per RFC4291 2.7.1 */ |
| 821 | function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 { |
| 822 | return 'FF0200000000000000000001FF'O & substr(addr, 13, 3); |
| 823 | } |
| 824 | |
| 825 | /* generate and encode ICMPv6 router solicitation */ |
| 826 | function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring { |
| 827 | const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O; |
| 828 | var OCT16 saddr := f_ipv6_link_local(link_id); |
| 829 | |
| 830 | var octetstring tmp; |
| 831 | tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast); |
| 832 | var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp)); |
| 833 | |
| 834 | return f_IPv6_enc(ip6); |
| 835 | } |
| 836 | |
| 837 | /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */ |
| 838 | function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring { |
| 839 | var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address; |
| 840 | return f_gen_icmpv6_router_solicitation(interface_id); |
| 841 | } |
| 842 | |
| 843 | /* generate and encode ICMPv6 neighbor solicitation */ |
| 844 | function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring { |
| 845 | var octetstring tmp; |
| 846 | tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr); |
| 847 | var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp)); |
| 848 | return f_IPv6_enc(ip6); |
| 849 | } |
| 850 | |
| 851 | /* generate and encode ICMPv6 neighbor solicitation for PDP Context */ |
| 852 | function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring { |
| 853 | var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address; |
| 854 | var OCT16 link_local := f_ipv6_link_local(interface_id); |
| 855 | var OCT16 daddr := f_ipv6_sol_node_mcast(link_local); |
| 856 | |
| 857 | return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local); |
| 858 | } |
| 859 | |
| 860 | /* wait for GGSN to send us an ICMPv6 router advertisement */ |
| 861 | function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT { |
| 862 | var Gtp1uUnitdata ud; |
| 863 | T_default.start; |
| 864 | alt { |
| 865 | //'6???????????3aff'O |
| 866 | [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud { |
| 867 | var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data; |
| 868 | var IPv6_packet ip6 := f_IPv6_dec(gpdu); |
| 869 | if (ip6.header.ver != 6 or ip6.header.nexthead != 58 or ip6.header.hlim != 255) { |
| 870 | repeat; |
| 871 | } |
| 872 | var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload); |
| 873 | if (not match(icmp6, tr_ICMPv6_RA(?, 64))) { |
| 874 | repeat; |
| 875 | } |
| 876 | ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix; |
| 877 | log("RA with /64 prefix ", ctx.ip6_prefix); |
| 878 | } |
| 879 | [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; } |
| 880 | [] GTPU.receive { setverdict(fail); } |
| 881 | [] T_default.timeout { setverdict(fail); } |
| 882 | } |
| 883 | T_default.stop; |
| 884 | } |
| 885 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 886 | /* 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] | 887 | testcase TC_pdp6_act_deact() runs on GT_CT { |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 888 | f_init(); |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 889 | |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 890 | 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] | 891 | f_pdp_ctx_act(ctx); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 892 | f_pdp_ctx_del(ctx, '1'B); |
| 893 | } |
| 894 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 895 | /* 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] | 896 | testcase TC_pdp6_act_deact_pcodns() runs on GT_CT { |
| 897 | f_init(); |
| 898 | |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 899 | 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] | 900 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 901 | f_pdp_ctx_act(ctx); |
| 902 | f_pdp_ctx_del(ctx, '1'B); |
| 903 | } |
| 904 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 905 | /* 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] | 906 | testcase TC_pdp6_act_deact_icmp6() runs on GT_CT { |
| 907 | f_init(); |
| 908 | |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 909 | 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] | 910 | ctx.pco_req := valueof(ts_PCO_IPv6_DNS); |
| 911 | f_pdp_ctx_act(ctx); |
Harald Welte | 231b941 | 2017-08-09 17:16:31 +0200 | [diff] [blame] | 912 | |
| 913 | //f_send_gtpu(ctx, c_router_solicit); |
| 914 | //f_send_gtpu(ctx, c_neigh_solicit); |
| 915 | |
| 916 | f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx)); |
| 917 | f_wait_rtr_adv(ctx); |
| 918 | f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx)); |
| 919 | |
Harald Welte | 811651e | 2017-08-05 15:25:06 +0200 | [diff] [blame] | 920 | f_pdp_ctx_del(ctx, '1'B); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 921 | } |
| 922 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 923 | /* Test PDP context activation for dynamic IPv4 EUA without DNS request */ |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 924 | testcase TC_pdp4_act_deact() runs on GT_CT { |
| 925 | f_init(); |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 926 | 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] | 927 | f_pdp_ctx_act(ctx); |
| 928 | f_pdp_ctx_del(ctx, '1'B); |
| 929 | } |
| 930 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 931 | /* 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] | 932 | testcase TC_pdp4_act_deact_ipcp() runs on GT_CT { |
| 933 | f_init(); |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 934 | 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] | 935 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 936 | f_pdp_ctx_act(ctx); |
| 937 | f_pdp_ctx_del(ctx, '1'B); |
| 938 | } |
| 939 | |
Harald Welte | 0ef285b | 2017-08-13 20:06:01 +0200 | [diff] [blame] | 940 | /* 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] | 941 | testcase TC_pdp4_act_deact_pcodns() runs on GT_CT { |
| 942 | f_init(); |
Harald Welte | ed09743 | 2017-08-13 13:28:49 +0200 | [diff] [blame] | 943 | 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] | 944 | ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT); |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 945 | f_pdp_ctx_act(ctx); |
| 946 | f_pdp_ctx_del(ctx, '1'B); |
| 947 | } |
| 948 | |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 949 | testcase TC_echo_req_resp() runs on GT_CT { |
| 950 | f_init(); |
| 951 | f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr)); |
| 952 | T_default.start; |
| 953 | alt { |
| 954 | [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); }; |
| 955 | [] GTPC.receive { repeat; }; |
| 956 | [] T_default.timeout { setverdict(fail); } |
| 957 | } |
| 958 | T_default.stop; |
| 959 | } |
| 960 | |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 961 | control { |
Harald Welte | ed7a177 | 2017-08-09 20:26:20 +0200 | [diff] [blame] | 962 | execute(TC_pdp4_act_deact()); |
| 963 | execute(TC_pdp4_act_deact_ipcp()); |
| 964 | execute(TC_pdp4_act_deact_pcodns()); |
| 965 | |
| 966 | execute(TC_pdp6_act_deact()); |
| 967 | execute(TC_pdp6_act_deact_pcodns()); |
| 968 | execute(TC_pdp6_act_deact_icmp6()); |
Harald Welte | dca8005 | 2017-08-13 20:01:38 +0200 | [diff] [blame] | 969 | |
| 970 | execute(TC_echo_req_resp()); |
Harald Welte | 94ade36 | 2017-08-04 00:36:55 +0200 | [diff] [blame] | 971 | } |
Harald Welte | 379d45a | 2017-08-03 09:55:15 +0200 | [diff] [blame] | 972 | } |