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