blob: 28f461ce00446b95091f1f890ab8c23278247fc4 [file] [log] [blame]
Harald Welte379d45a2017-08-03 09:55:15 +02001module GGSN_Tests {
2
Harald Welte94ade362017-08-04 00:36:55 +02003 import from General_Types all;
Harald Welte811651e2017-08-05 15:25:06 +02004 import from Osmocom_Types all;
Harald Welte94ade362017-08-04 00:36:55 +02005 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 Welte71a36022017-12-04 18:55:58 +010011 import from IPCP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020012 import from IP_Types all;
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +010013 import from ICMP_Types all;
Harald Welte231b9412017-08-09 17:16:31 +020014 import from ICMPv6_Types all;
Harald Welteddeecbb2017-08-18 22:53:30 +020015 import from Native_Functions all;
Harald Welte94ade362017-08-04 00:36:55 +020016
17 const integer GTP0_PORT := 3386;
18 const integer GTP1C_PORT := 2123;
19 const integer GTP1U_PORT := 2152;
Harald Welteddeecbb2017-08-18 22:53:30 +020020
21 modulepar {
22 charstring m_bind_ip_gtpc := "127.23.42.1";
23 charstring m_bind_ip_gtpu := "127.23.42.1";
24
25 charstring m_ggsn_ip_gtpc := "127.0.0.6";
26 charstring m_ggsn_ip_gtpu := "127.0.0.6";
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010027
28 charstring m_ggsn_ip4_dns1 := "192.168.100.1"
29 charstring m_ggsn_ip4_dns2 := "8.8.8.8"
Pau Espin Pedrol363ba482018-01-29 18:42:00 +010030 charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888"
31 charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844"
Harald Welteddeecbb2017-08-18 22:53:30 +020032 }
Harald Welte94ade362017-08-04 00:36:55 +020033
Harald Welte811651e2017-08-05 15:25:06 +020034 type set PdpContext {
35 hexstring imsi,
36 octetstring msisdn optional,
37 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020038 ProtConfigOptions pco_req optional,
39 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020040 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020041 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020042 BIT4 nsapi,
43 /* TEI (Data) local side */
44 OCT4 teid,
45 /* TEI (Control) local side */
46 OCT4 teic,
47 /* TEI (Data) remote side */
48 OCT4 teid_remote,
49 /* TEI (Control) remote side */
Harald Welte5438b9d2017-08-13 13:27:48 +020050 OCT4 teic_remote
Harald Welte811651e2017-08-05 15:25:06 +020051 }
52
Harald Welte94ade362017-08-04 00:36:55 +020053 type component GT_CT {
54 port GTPC_PT GTPC;
55 port GTPU_PT GTPU;
56
Harald Welte0be142b2017-08-13 13:28:10 +020057 var boolean g_initialized := false;
58
Harald Welte94ade362017-08-04 00:36:55 +020059 var OCT1 g_restart_ctr := '01'O;
60 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +020061 var OCT4 g_sgsn_ip_c;
62 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +020063 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +020064 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
65 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +020066 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +020067
68 /* next to-be-sent GTP-C sequence number */
69 var uint16_t g_c_seq_nr;
70 /* next to-be-sent GTP-U sequence number */
71 var uint16_t g_d_seq_nr;
Harald Welte94ade362017-08-04 00:36:55 +020072 }
73
74 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +020075 if (g_initialized == true) {
76 return;
77 }
78 g_initialized := true;
79
Harald Welteddeecbb2017-08-18 22:53:30 +020080 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
81 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
82
Harald Welte94ade362017-08-04 00:36:55 +020083 var Result res;
84 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +020085 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +020086 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +020087 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +020088
89 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +020090 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +020091 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +020092
93 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +020094 g_c_seq_nr := f_rnd_int(65535);
95 g_d_seq_nr := f_rnd_int(65535);
Harald Welte94ade362017-08-04 00:36:55 +020096 }
97
98 /* generalized GTP-C receive template */
Harald Weltedca80052017-08-13 20:01:38 +020099 template PDU_GTPC tr_GTP1C_PDU(template OCT1 msg_type, template OCT4 teid, template GTPC_PDUs pdu := ?) := {
Harald Welte94ade362017-08-04 00:36:55 +0200100 /* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an
101 * error if this flag is set to '1'. */
102 pn_bit := '0'B,
103 /* Sequence number flag (S) shall be set to '1'. */
104 s_bit := '1'B,
105 e_bit := ?,
106 spare := ?,
107 /* Protocol Type flag (PT) shall be set to '1'.*/
108 pt := '1'B,
109 /* Version shall be set to decimal 1 ('001'). */
110 version := '001'B,
111 messageType := msg_type,
112 lengthf := ?,
113 teid := teid,
114 opt_part := *,
Harald Weltedca80052017-08-13 20:01:38 +0200115 gtpc_pdu := pdu
Harald Welte94ade362017-08-04 00:36:55 +0200116 }
117
118 /* generalized GTP-C send template */
Harald Welte811651e2017-08-05 15:25:06 +0200119 template PDU_GTPC ts_GTP1C_PDU(OCT1 msg_type, OCT4 teid, GTPC_PDUs pdu, uint16_t seq_nr) := {
Harald Welte94ade362017-08-04 00:36:55 +0200120 /* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an
121 * error if this flag is set to '1'. */
122 pn_bit := '0'B,
123 /* Sequence number flag (S) shall be set to '1'. */
124 s_bit := '1'B,
125 e_bit := '0'B,
126 spare := '0'B,
127 /* Protocol Type flag (PT) shall be set to '1'.*/
128 pt := '1'B,
129 /* Version shall be set to decimal 1 ('001'). */
130 version := '001'B,
131 messageType := msg_type,
132 lengthf := 0, /* we assume encoder overwrites this */
133 teid := teid,
134 opt_part := {
Harald Welte811651e2017-08-05 15:25:06 +0200135 sequenceNumber := int2oct(seq_nr, 2),
Harald Welte94ade362017-08-04 00:36:55 +0200136 npduNumber := '00'O,
137 nextExtHeader := '00'O,
138 gTPC_extensionHeader_List := omit
139 },
140 gtpc_pdu := pdu
141 }
142
143 /* recovery IE */
144 template Recovery_gtpc ts_Recovery(OCT1 restart_counter) := {
Harald Weltedca80052017-08-13 20:01:38 +0200145 type_gtpc := '0E'O,
146 restartCounter := restart_counter
147 }
148
149 template Recovery_gtpc tr_Recovery(template OCT1 restart_counter) := {
150 type_gtpc := '0E'O,
Harald Welte94ade362017-08-04 00:36:55 +0200151 restartCounter := restart_counter
152 }
153
154 /* template matching reception of GTP-C echo-request */
Harald Weltedca80052017-08-13 20:01:38 +0200155 template Gtp1cUnitdata tr_GTPC_MsgType(template GtpPeer peer, template OCT1 msg_type, template OCT4 teid, template GTPC_PDUs pdus := ?) := {
Harald Welte94ade362017-08-04 00:36:55 +0200156 peer := peer,
Harald Weltedca80052017-08-13 20:01:38 +0200157 gtpc := tr_GTP1C_PDU(msg_type, teid, pdus)
Harald Welte94ade362017-08-04 00:36:55 +0200158 }
159
160 /* template matching reception of GTP-C echo-request */
161 template Gtp1cUnitdata tr_GTPC_PING(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoRequest, '00000000'O);
162
Harald Weltedca80052017-08-13 20:01:38 +0200163 template GTPC_PDUs tr_EchoRespPDU(template OCT1 restart_counter) := {
164 echoResponse := {
165 recovery := tr_Recovery(restart_counter),
166 private_extension_gtpc := *
167 }
168 }
169
170 /* template matching reception of GTP-C echo-response */
171 template Gtp1cUnitdata tr_GTPC_PONG(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoResponse, '00000000'O, tr_EchoRespPDU(?));
172
Harald Welte94ade362017-08-04 00:36:55 +0200173 template GTPC_PDUs ts_EchoRespPDU(OCT1 restart_counter) := {
174 echoResponse := {
Harald Weltedca80052017-08-13 20:01:38 +0200175 recovery := ts_Recovery(restart_counter),
Harald Welte94ade362017-08-04 00:36:55 +0200176 private_extension_gtpc := omit
177 }
178 }
179
180 /* master template for senidng a GTP-C echo response */
Harald Welte811651e2017-08-05 15:25:06 +0200181 template Gtp1cUnitdata ts_GTPC_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := {
Harald Welte94ade362017-08-04 00:36:55 +0200182 peer := peer,
Harald Welte811651e2017-08-05 15:25:06 +0200183 gtpc := ts_GTP1C_PDU(echoResponse, '00000000'O, valueof(ts_EchoRespPDU(rest_ctr)), seq)
Harald Welte94ade362017-08-04 00:36:55 +0200184 }
185
Harald Weltedca80052017-08-13 20:01:38 +0200186 template GTPC_PDUs ts_EchoReqPDU := {
187 echoRequest := {
188 private_extension_gtpc := omit
189 }
190 }
191
192 /* master template for sending a GTP-C echo request */
193 template Gtp1cUnitdata ts_GTPC_PING(GtpPeer peer, uint16_t seq) := {
194 peer := peer,
195 gtpc := ts_GTP1C_PDU(echoRequest, '00000000'O, valueof(ts_EchoReqPDU), seq)
196 }
197
Harald Welte94ade362017-08-04 00:36:55 +0200198 template EndUserAddress t_EuaIPv4(template OCT4 ip_addr) := {
199 type_gtpc := '80'O,
200 endUserAddress := {
201 endUserAddressIPv4 := {
202 lengthf := 2,
203 pdp_typeorg := '0001'B,
204 spare := '1111'B,
205 pdp_typenum := '21'O,
206 ipv4_address := ip_addr
207 }
208 }
209 }
210 template EndUserAddress t_EuaIPv4Dyn := t_EuaIPv4(omit);
Harald Welte99ef9a42017-08-14 21:42:03 +0200211 template EndUserAddress tr_EuaIPv4(template OCT4 ip_addr) modifies t_EuaIPv4 := {
212 endUserAddress := {
213 endUserAddressIPv4 := {
Harald Weltebb5a19e2017-09-21 22:50:41 +0800214 lengthf := 2+lengthof(ip_addr)
Harald Welte99ef9a42017-08-14 21:42:03 +0200215 }
216 }
217 }
218
Harald Welte94ade362017-08-04 00:36:55 +0200219 template EndUserAddress t_EuaIPv6(template OCT16 ip_addr) := {
220 type_gtpc := '80'O,
221 endUserAddress := {
222 endUserAddressIPv6 := {
223 lengthf := 2,
224 pdp_typeorg := '0001'B,
225 spare := '1111'B,
226 pdp_typenum := '57'O,
227 ipv6_address := ip_addr
228 }
229 }
230 }
231 template EndUserAddress t_EuaIPv6Dyn := t_EuaIPv6(omit);
Harald Welte99ef9a42017-08-14 21:42:03 +0200232 template EndUserAddress tr_EuaIPv6(template OCT16 ip_addr) modifies t_EuaIPv6 := {
233 endUserAddress := {
234 endUserAddressIPv6 := {
235 lengthf := 2+lengthof(ip_addr)
236 }
237 }
238 }
Harald Welte94ade362017-08-04 00:36:55 +0200239
240 template AccessPointName ts_APN(octetstring apn) := {
241 type_gtpc := '83'O,
242 lengthf := lengthof(apn),
243 apn_value := apn
244 }
245
246 template GSN_Address_GTPC ts_GsnAddr(octetstring ip_addr) := {
247 type_gtpc := '85'O,
248 lengthf := lengthof(ip_addr),
249 addressf := ip_addr
250 }
251
252 template MSISDN ts_Msisdn(octetstring msisdn) := {
253 type_gtpc := '86'O,
254 lengthf := lengthof(msisdn),
255 msisdn := msisdn
256 }
257
258 template QualityOfServiceProfile ts_QosDefault := {
259 type_gtpc := '87'O,
260 lengthf := 4,
261 allocRetensionPrio := '00'O,
262 qos_ProfileValue := {
263 reliabilityClass := '011'B,
264 delayClass := '001'B,
265 spare1 := '00'B,
266 precedenceClass := '010'B,
267 spare2 := '0'B,
268 peakThroughput := '1001'B,
269 meanThroughput := '11111'B,
270 spare3 := '000'B,
271 deliverErroneusSDU := omit,
272 deliveryOrder := omit,
273 trafficClass := omit,
274 maxSDUSize := omit,
275 maxBitrateUplink := omit,
276 maxBitrateDownlink := omit,
277 sduErrorRatio := omit,
278 residualBER := omit,
279 trafficHandlingPriority := omit,
280 transferDelay := omit,
281 guaranteedBitRateUplink := omit,
282 guaranteedBitRateDownlink := omit,
283 sourceStatisticsDescriptor := omit,
284 signallingIndication := omit,
285 spare4 := omit,
286 maxBitrateDownlinkExt := omit,
287 guaranteedBitRateDownlinkExt := omit,
288 maxBitrateUplinkExt := omit,
289 guaranteedBitRateUplinkExt := omit
290 }
291 }
292
293 template IMSI_gtpc ts_Imsi(hexstring digits) := {
294 type_gtpc := '02'O,
295 digits := digits,
296 padding := 'F'H
297 }
298
299 template GTPC_PDUs ts_CreatePdpPDU(hexstring imsi, OCT1 restart_ctr, OCT4 teid_data, OCT4 teid_ctrl,
300 BIT4 nsapi, EndUserAddress eua, octetstring apn,
301 octetstring sgsn_ip_sign, octetstring sgsn_ip_data,
Harald Welteed7a1772017-08-09 20:26:20 +0200302 octetstring msisdn, template ProtConfigOptions pco := omit) := {
Harald Welte94ade362017-08-04 00:36:55 +0200303 createPDPContextRequest := {
304 imsi := ts_Imsi(imsi),
305 rai := omit,
306 recovery := ts_Recovery(restart_ctr),
307 selectionMode := {
308 type_gtpc := '0F'O,
309 selectModeValue := '00'B,
310 spare := '111111'B
311 },
312 teidDataI := {
313 type_gtpc := '00'O,
314 teidDataI := teid_data
315 },
316 teidControlPlane := {
317 type_gtpc := '00'O,
318 teidControlPlane := teid_ctrl
319 },
320 nsapi := {
321 type_gtpc := '00'O,
322 nsapi := nsapi,
323 unused := '0000'B
324 },
325 linked_nsapi := omit,
326 charging_char := omit,
327 trace_ref := omit,
328 trace_type := omit,
329 endUserAddress := eua,
330 accessPointName := ts_APN(apn),
Harald Welteed7a1772017-08-09 20:26:20 +0200331 protConfigOptions := pco,
Harald Welte94ade362017-08-04 00:36:55 +0200332 sgsn_addr_signalling := ts_GsnAddr(sgsn_ip_sign),
333 sgsn_addr_traffic := ts_GsnAddr(sgsn_ip_data),
334 msisdn := ts_Msisdn(msisdn),
335 qualityOfServiceProfile := ts_QosDefault,
336 tft := omit,
337 triggerId := omit,
338 omcId := omit,
339 commonFlags := omit,
340 aPN_Restriction := omit,
341 ratType := omit,
342 userLocationInformation := omit,
343 mS_TimeZone := omit,
344 imeisv := omit,
345 camelChargingInformationContainer := omit,
346 additionalTraceInfo := omit,
347 correlationID := omit,
348 evolvedAllocationRetentionPriorityI := omit,
349 extendedCommonFlags := omit,
350 userCSGInformation := omit,
351 aPN_AMBR := omit,
352 signallingPriorityIndication := omit,
353 cN_OperatorSelectionEntity := omit,
354 private_extension_gtpc := omit
355 }
356 }
357
Harald Welte811651e2017-08-05 15:25:06 +0200358 template Gtp1cUnitdata ts_GTPC_CreatePDP(GtpPeer peer, uint16_t seq, hexstring imsi,
359 OCT1 restart_ctr, OCT4 teid_data,
Harald Welte94ade362017-08-04 00:36:55 +0200360 OCT4 teid_ctrl, BIT4 nsapi, EndUserAddress eua,
361 octetstring apn, octetstring sgsn_ip_sign,
Harald Welteed7a1772017-08-09 20:26:20 +0200362 octetstring sgsn_ip_data, octetstring msisdn,
363 template ProtConfigOptions pco := omit) := {
Harald Welte94ade362017-08-04 00:36:55 +0200364 peer := peer,
365 gtpc := ts_GTP1C_PDU(createPDPContextRequest, '00000000'O,
366 valueof(ts_CreatePdpPDU(imsi, restart_ctr, teid_data, teid_ctrl,
367 nsapi, eua, apn, sgsn_ip_sign,
Harald Welteed7a1772017-08-09 20:26:20 +0200368 sgsn_ip_data, msisdn, pco)), seq)
369 }
370
Harald Welte99ef9a42017-08-14 21:42:03 +0200371 /* PCO send base template */
Harald Welteed7a1772017-08-09 20:26:20 +0200372 template ProtConfigOptions ts_PCO := {
373 type_gtpc := '84'O,
374 lengthf := 0,
375 configProtocol := '000'B,
376 spare := '0000'B,
377 extension0 := '1'B,
378 protocols := {}
379 }
Harald Welte99ef9a42017-08-14 21:42:03 +0200380 /* PCO receive base template */
381 template ProtConfigOptions tr_PCO := {
382 type_gtpc := '84'O,
383 lengthf := ?,
384 configProtocol := '000'B,
385 spare := ?,
386 extension0 := '1'B,
387 protocols := {}
388 }
Harald Welteed7a1772017-08-09 20:26:20 +0200389
390 template ProtConfigOptions ts_PCO_IPv6_DNS modifies ts_PCO := {
391 protocols := {
392 { protocolID := '0003'O, lengthProtoID := 0, protoIDContents := ''O }
393 }
394 }
Harald Welte99ef9a42017-08-14 21:42:03 +0200395 template ProtConfigOptions tr_PCO_IPv6_DNS_resp(template OCT16 contents) modifies tr_PCO := {
396 protocols := {
Harald Welte3ab91d62017-08-25 14:46:39 +0200397 *, { protocolID := '0003'O, lengthProtoID := 16, protoIDContents := contents }, *
Harald Welte99ef9a42017-08-14 21:42:03 +0200398 }
399 }
Harald Welteed7a1772017-08-09 20:26:20 +0200400
401 template ProtConfigOptions ts_PCO_IPv4_DNS_IPCP modifies ts_PCO := {
402 protocols := {
Harald Welteab4ca942017-09-07 18:41:52 +0200403 /* dummy PAP entry to check if our parser in the GGSN can properly iterate over
404 * the list of protocols, see Change-Id Icc2e6716c33d78d3c3e000f529806228d8aa155e */
405 { protocolID := 'C023'O, lengthProtoID := 0, protoIDContents := ''O },
Harald Welteeb9184d2017-12-04 19:01:47 +0100406 { protocolID := '8021'O, lengthProtoID := 16, protoIDContents :=
407 enc_IpcpPacket(valueof(ts_IPCP_ReqDNS)) }
Harald Welteed7a1772017-08-09 20:26:20 +0200408 }
409 }
410
Harald Welte71a36022017-12-04 18:55:58 +0100411 template ProtocolElement tr_PCO_Proto(OCT2 prot_id) := {
412 protocolID := prot_id,
413 lengthProtoID := ?,
414 protoIDContents := ?
415 }
416 template ProtConfigOptions tr_PCO_Contains(OCT2 prot_id) modifies tr_PCO := {
417 protocols := { *, tr_PCO_Proto(prot_id), * }
418 }
419
Harald Welteed7a1772017-08-09 20:26:20 +0200420 template ProtConfigOptions ts_PCO_IPv4_DNS_CONT modifies ts_PCO := {
421 protocols := {
422 { protocolID := '000d'O, lengthProtoID := 0, protoIDContents := ''O }
423 }
Harald Welte94ade362017-08-04 00:36:55 +0200424 }
Harald Welte99ef9a42017-08-14 21:42:03 +0200425 template ProtConfigOptions tr_PCO_IPv4_DNS_CONT_resp(template OCT4 contents) modifies tr_PCO := {
426 protocols := {
Harald Welte3ab91d62017-08-25 14:46:39 +0200427 *, { protocolID := '000d'O, lengthProtoID := 4, protoIDContents := contents }, *
Harald Welte99ef9a42017-08-14 21:42:03 +0200428 }
429 }
430
Harald Welte71a36022017-12-04 18:55:58 +0100431 /* extract a given protocol payload from PCO */
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100432 function f_PCO_extract_proto(ProtConfigOptions pco, OCT2 protocol, integer nth_match := 1) return octetstring {
Harald Welte71a36022017-12-04 18:55:58 +0100433 var integer i;
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100434 var integer num_matches := 0;
Harald Welte71a36022017-12-04 18:55:58 +0100435 for (i := 0; i < lengthof(pco.protocols); i := i + 1) {
436 if (pco.protocols[i].protocolID == protocol) {
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100437 num_matches := num_matches + 1;
438 if (num_matches == nth_match) {
439 return pco.protocols[i].protoIDContents;
440 }
Harald Welte71a36022017-12-04 18:55:58 +0100441 }
442 }
443 setverdict(fail);
444 return ''O;
445 }
446
447 template IpcpPacket tr_IPCP(template LcpCode code, template uint8_t identifier,
448 template IpcpOptionList opts) := {
449 code := code,
450 identifier := identifier,
451 len := ?,
452 options := opts
453 }
454 template IpcpOption tr_IPCP_PrimaryDns(template OCT4 addr) := {
455 code := IPCP_OPT_PrimaryDNS,
456 len := 6,
457 data := addr
458 }
459 template IpcpOption tr_IPCP_SecondaryDns(template OCT4 addr) := {
460 code := IPCP_OPT_SecondaryDNS,
461 len := 6,
462 data := addr
463 }
Harald Welte71a36022017-12-04 18:55:58 +0100464 template IpcpPacket tr_IPCP_Ack_DNS(template uint8_t identifier := ?, template OCT4 dns1 := ?,
465 template OCT4 dns2 := ?) :=
466 tr_IPCP(LCP_Configure_Ack, identifier,
467 { *, tr_IPCP_PrimaryDns(dns1), *, tr_IPCP_SecondaryDns(dns2), * });
468
Harald Welteeb9184d2017-12-04 19:01:47 +0100469 template IpcpPacket ts_IPCP(LcpCode code, uint8_t identifier, template IpcpOptionList opts) := {
470 code := code,
471 identifier := identifier,
472 len := 0, /* overwritten */
473 options := opts
474 }
475 template IpcpPacket ts_IPCP_ReqDNS(uint8_t identifier := 0) :=
476 ts_IPCP(LCP_Configure_Request, identifier,
477 { tr_IPCP_PrimaryDns('00000000'O), tr_IPCP_SecondaryDns('00000000'O) });
Harald Welte94ade362017-08-04 00:36:55 +0200478
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200479 function f_teardown_ind_IE(in template BIT1 ind) return template TearDownInd {
Harald Welte811651e2017-08-05 15:25:06 +0200480/*
481 if (not isvalue(ind)) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200482 return omit;
483 }
Harald Welte811651e2017-08-05 15:25:06 +0200484*/
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200485 var TearDownInd ret := {
486 type_gtpc := '13'O,
487 tdInd := valueof(ind),
488 spare:= '0000000'B
489 }
490 return ret;
491 }
492
493 template GTPC_PDUs ts_DeletePdpPDU(BIT4 nsapi, template BIT1 teardown_ind) := {
494 deletePDPContextRequest := {
495 cause := omit,
496 tearDownIndicator := f_teardown_ind_IE(teardown_ind),
497 nsapi := {
498 type_gtpc := '14'O,
499 nsapi := nsapi,
500 unused := '0000'B
501 },
502 protConfigOptions := omit,
503 userLocationInformation := omit,
504 mS_TimeZone := omit,
505 extendedCommonFlags := omit,
506 uLI_Timestamp := omit,
507 private_extension_gtpc := omit
508 }
509 }
510
Harald Welte811651e2017-08-05 15:25:06 +0200511 template Gtp1cUnitdata ts_GTPC_DeletePDP(GtpPeer peer, uint16_t seq, OCT4 teid,
512 BIT4 nsapi, template BIT1 teardown_ind) := {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200513 peer := peer,
514 gtpc := ts_GTP1C_PDU(deletePDPContextRequest, teid,
Harald Welte811651e2017-08-05 15:25:06 +0200515 valueof(ts_DeletePdpPDU(nsapi, teardown_ind)), seq)
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200516 }
517
518
Harald Welte3af89482017-08-04 16:20:23 +0200519 /* GTP-U */
520
Harald Welte231b9412017-08-09 17:16:31 +0200521 template PDU_GTPU tr_GTP1U_PDU(template OCT1 msg_type, template OCT4 teid, template GTPU_IEs ies := ?) := {
Harald Welte3af89482017-08-04 16:20:23 +0200522 pn_bit := ?,
523 s_bit := ?,
524 e_bit := ?,
525 spare := ?,
526 /* Protocol Type flag (PT) shall be set to '1' in GTP */
527 pt := '1'B,
528 /* Version shall be set to decimal 1 ('001'). */
529 version := '001'B,
530 messageType := msg_type,
531 lengthf := ?,
532 teid := teid,
533 opt_part := *,
Harald Welte231b9412017-08-09 17:16:31 +0200534 gtpu_IEs := ies
Harald Welte3af89482017-08-04 16:20:23 +0200535 }
536
537 /* generalized GTP-U send template */
Harald Welte811651e2017-08-05 15:25:06 +0200538 template PDU_GTPU ts_GTP1U_PDU(OCT1 msg_type, uint16_t seq, OCT4 teid, GTPU_IEs ies) := {
Harald Welte3af89482017-08-04 16:20:23 +0200539 /* N-PDU Number flag (PN): the GTP-U header contains a meaningful N-PDU Number field if the PN
540 * flag is set to 1. */
541 pn_bit := '0'B, /* we assume the encoder overwrites this if an optional part is given */
542 /* If the Sequence Number flag (S) is set to '1' the sequence number field is present and
543 * meaningful otherwise it is set to '0'. For GTP-U messages Echo Request, Echo Response,
544 * Error Indication and Supported Extension Headers Notification, the S flag shall be set to '1'. */
Harald Welte811651e2017-08-05 15:25:06 +0200545 s_bit := '1'B, /* we assume the encoder overwrites this if an optional part is given */
Harald Welte3af89482017-08-04 16:20:23 +0200546 /* Extension header presence */
547 e_bit := '0'B,
548 spare := '0'B,
549 /* Protocol Type flag (PT) shall be set to '1' in GTP */
550 pt := '1'B,
551 /* Version shall be set to decimal 1 ('001'). */
552 version := '001'B,
553 messageType := msg_type,
554 lengthf := 0, /* we assume encoder overwrites this */
555 teid := teid,
Harald Welte811651e2017-08-05 15:25:06 +0200556 opt_part := {
557 sequenceNumber := int2oct(seq, 2),
558 npduNumber := '00'O,
559 nextExtHeader := '00'O,
560 gTPU_extensionHeader_List := omit
561 },
Harald Welte3af89482017-08-04 16:20:23 +0200562 gtpu_IEs := ies
563 }
564
565 template Gtp1uUnitdata tr_GTPU_MsgType(template GtpPeer peer, template OCT1 msg_type, template OCT4 teid) := {
566 peer := peer,
567 gtpu := tr_GTP1U_PDU(msg_type, teid)
568 }
569
570
Harald Welte231b9412017-08-09 17:16:31 +0200571 /* template matching reception of GTP-U echo-request */
Harald Welte3af89482017-08-04 16:20:23 +0200572 template Gtp1uUnitdata tr_GTPU_PING(template GtpPeer peer) := tr_GTPU_MsgType(peer, echoRequest, '00000000'O);
573
Harald Welte231b9412017-08-09 17:16:31 +0200574 /* template matching reception of GTP-U GPDU */
575 template GTPU_IEs t_GPDU(template octetstring data) := {
576 g_PDU_IEs := {
577 data := data
578 }
579 }
580 template Gtp1uUnitdata tr_GTPU_GPDU(template GtpPeer peer, template OCT4 teid, template octetstring data := ?) := {
581 peer := peer,
582 gtpu := tr_GTP1U_PDU('FF'O, teid, t_GPDU(data))
583 }
584
Harald Welte3af89482017-08-04 16:20:23 +0200585 template GTPU_IEs ts_UEchoRespPDU(OCT1 restart_counter) := {
586 echoResponse_IEs := {
587 recovery_gtpu := {
588 type_gtpu := '00'O, /* we assume encoder fixes? */
589 restartCounter := restart_counter
590 },
591 private_extension_gtpu := omit
592 }
593 }
594
595 /* master template for sending a GTP-U echo response */
Harald Welte811651e2017-08-05 15:25:06 +0200596 template Gtp1uUnitdata ts_GTPU_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := {
Harald Welte3af89482017-08-04 16:20:23 +0200597 peer := peer,
Harald Welte811651e2017-08-05 15:25:06 +0200598 gtpu := ts_GTP1U_PDU(echoResponse, seq, '00000000'O, valueof(ts_UEchoRespPDU(rest_ctr)))
Harald Welte3af89482017-08-04 16:20:23 +0200599 }
600
Harald Welte811651e2017-08-05 15:25:06 +0200601 /* master template for sending a GTP-U user plane data */
602 template Gtp1uUnitdata ts_GTP1U_GPDU(GtpPeer peer, uint16_t seq, OCT4 teid, octetstring data) := {
603 peer := peer,
604 gtpu := ts_GTP1U_PDU('FF'O, seq, teid, { g_PDU_IEs := { data := data }})
605 }
Harald Welte3af89482017-08-04 16:20:23 +0200606
Harald Welte94ade362017-08-04 00:36:55 +0200607 /* Altstep implementing responses to any incoming echo requests */
608 altstep pingpong() runs on GT_CT {
609 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200610 var Gtp1uUnitdata udu;
Harald Welte94ade362017-08-04 00:36:55 +0200611 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200612 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
613 GTPC.send(ts_GTPC_PONG(ud.peer, seq, '00'O));
Harald Welte94ade362017-08-04 00:36:55 +0200614 repeat;
615 };
Harald Welte3af89482017-08-04 16:20:23 +0200616 [] GTPU.receive(tr_GTPU_PING(?)) -> value udu {
Harald Welte811651e2017-08-05 15:25:06 +0200617 var uint16_t seq := oct2int(udu.gtpu.opt_part.sequenceNumber);
618 GTPU.send(ts_GTPU_PONG(udu.peer, seq, '00'O));
Harald Welte3af89482017-08-04 16:20:23 +0200619 };
Harald Welte94ade362017-08-04 00:36:55 +0200620 [] T_default.timeout { setverdict(fail); };
621 }
622
Harald Welte811651e2017-08-05 15:25:06 +0200623 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200624 const octetstring c_ApnInternet := '08696E7465726E6574'O;
625 const octetstring c_ApnInet6 := '05696E657436'O;
626 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200627
Harald Welte811651e2017-08-05 15:25:06 +0200628 /* return random NSAPI */
629 function f_rnd_nsapi() return BIT4 {
630 return int2bit(f_rnd_int(16), 4);
631 }
632
633 /* return random TEI[DC] */
634 function f_rnd_tei() return OCT4 {
635 return int2oct(f_rnd_int(4294967296), 4);
636 }
637
638 /* define an (internal) representation of a PDP context */
639 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
640 EndUserAddress eua) := {
641 imsi := imsi,
642 msisdn := msisdn,
643 nsapi := f_rnd_nsapi(),
644 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200645 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200646 eua := eua,
647 teid := f_rnd_tei(),
Harald Welte5438b9d2017-08-13 13:27:48 +0200648 teic := f_rnd_tei()
Harald Welte811651e2017-08-05 15:25:06 +0200649 }
650
651 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200652 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200653 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200654 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200655 }
656
657 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200658 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte5438b9d2017-08-13 13:27:48 +0200659 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
660 g_d_seq_nr := g_d_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200661 }
662
663 /* send a PDP context activation */
664 function f_pdp_ctx_act(inout PdpContext ctx) runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200665 var Gtp1cUnitdata ud;
Harald Welte94ade362017-08-04 00:36:55 +0200666 var default d;
667
668 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200669 f_send_gtpc(ts_GTPC_CreatePDP(g_peer_c, g_c_seq_nr, ctx.imsi, g_restart_ctr,
Harald Welte811651e2017-08-05 15:25:06 +0200670 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200671 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req));
Harald Welte94ade362017-08-04 00:36:55 +0200672 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200673 d := activate(pingpong());
674 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200675 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
676 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
677 if (cpr.cause.causevalue == '80'O) {
Harald Welte99ef9a42017-08-14 21:42:03 +0200678 /* Check if EUA type corresponds to requested type */
679 if (match(ctx.eua, t_EuaIPv4(?)) and
680 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
681 setverdict(fail);
682 }
683 if (match(ctx.eua, t_EuaIPv6(?)) and
684 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
685 setverdict(fail);
686 }
687 /* Check if PCO response corresponds to request */
688 if (ispresent(ctx.pco_req)) {
689 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
690 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
691 log("IPv4 DNS Container requested, but missing");
692 setverdict(fail);
693 }
694 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
695 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
696 log("IPv6 DNS Container requested, but missing");
697 setverdict(fail);
698 }
699 }
Harald Welte811651e2017-08-05 15:25:06 +0200700 ctx.teid_remote := cpr.teidDataI.teidDataI;
701 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
Harald Welte231b9412017-08-09 17:16:31 +0200702 ctx.eua := cpr.endUserAddress;
Harald Welteed7a1772017-08-09 20:26:20 +0200703 ctx.pco_neg := cpr.protConfigOptions;
Harald Welte94ade362017-08-04 00:36:55 +0200704 setverdict(pass);
705 } else {
706 setverdict(fail);
707 }
708 }
709 }
710 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200711 T_default.stop;
Harald Welte94ade362017-08-04 00:36:55 +0200712 }
713
Harald Welte811651e2017-08-05 15:25:06 +0200714 function f_pdp_ctx_del(PdpContext ctx, template BIT1 teardown_ind) runs on GT_CT {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200715 var Gtp1cUnitdata ud;
716 var default d;
717
Harald Welte41575e92017-08-13 13:49:57 +0200718 f_send_gtpc(ts_GTPC_DeletePDP(g_peer_c, g_c_seq_nr, ctx.teic_remote, ctx.nsapi, teardown_ind));
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200719 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200720 d := activate(pingpong());
721 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200722 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ctx.teic)) -> value ud {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200723 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == '80'O) {
724 setverdict(pass);
725 } else {
726 setverdict(fail);
727 }
728 }
729 }
730 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200731 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200732 }
Harald Welte811651e2017-08-05 15:25:06 +0200733 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
734 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
735 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
736 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200737
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100738 /* template for an ICMPv6 echo request */
739 template PDU_ICMP ts_ICMPv4_ERQ := {
740 echo := {
741 type_field := 8,
742 code := 0,
743 checksum := '0000'O,
744 identifier := '0345'O,
745 sequence_number := '0001'O,
746 data := ''O
747 }
748 }
749
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100750 /* template for an ICMPv6 echo request */
751 template PDU_ICMP tr_ICMPv4_ERQ := {
752 echo := {
753 type_field := 8,
754 code := 0,
755 checksum := ?,
756 identifier := ?,
757 sequence_number := ?,
758 data := ?
759 }
760 }
761
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100762 /* template for an ICMPv4 echo reply */
763 template PDU_ICMP tr_ICMPv4_ERP(template octetstring data := *) := {
764 echo_reply := {
765 type_field := 0,
766 code := 0,
767 checksum := ?,
768 identifier := ?,
769 sequence_number := ?,
770 data := data
771 }
772 }
773
774 /* template for receiving/matching an ICMPv6 Destination Unreachable */
775 template PDU_ICMP tr_ICMPv4_DU := {
776 destination_unreachable := {
777 type_field := 1,
778 code := ?,
779 checksum := ?,
780 unused := ?,
781 original_ip_msg := ?
782 }
783 }
784
785 /* template to construct IPv4_packet from input arguments, ready for use in f_IPv4_enc() */
786 template IPv4_packet ts_IP4(OCT4 srcaddr, OCT4 dstaddr, LIN1 proto, LIN2_BO_LAST tlen, octetstring payload) := {
787 header := {
788 ver := 4,
789 hlen := 5,
790 tos := 0,
791 tlen := tlen,
792 id := 35902,
793 res := '0'B,
794 dfrag := '1'B,
795 mfrag := '0'B,
796 foffset := 0,
797 ttl := 64,
798 proto := proto,
799 cksum := 0,
800 srcaddr := srcaddr,
801 dstaddr := dstaddr
802 },
803 ext_headers := omit,
804 payload := payload
805 }
806
Harald Welte231b9412017-08-09 17:16:31 +0200807 /* template to generate a 'Prefix Information' ICMPv6 option */
808 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
809 prefixInformation := {
810 typeField := 3,
811 lengthIndicator := 8,
812 prefixLength := prefix_len,
813 reserved1 := '000000'B,
814 a_Bit := '0'B,
815 l_Bit := '0'B,
816 validLifetime := oct2int('FFFFFFFF'O),
817 preferredLifetime := oct2int('FFFFFFFF'O),
818 reserved2 := '00000000'O,
819 prefix := prefix
820 }
821 }
822
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100823 /* template for an ICMPv6 echo request */
824 template PDU_ICMPv6 ts_ICMPv6_ERQ := {
825 echoRequest := {
826 typeField := 128,
827 code := 0,
828 checksum := '0000'O,
829 identifier := 0,
830 sequenceNr := 0,
831 data := ''O
832 }
833 }
834
Harald Welte231b9412017-08-09 17:16:31 +0200835 /* template for an ICMPv6 router solicitation */
836 template PDU_ICMPv6 ts_ICMPv6_RS := {
837 routerSolicitation := {
838 typeField := 133,
839 code := 0,
840 checksum := '0000'O,
841 reserved := '00000000'O,
842 /* TODO: do we need 'Source link-layer address' ? */
843 options := omit
844 }
845 }
846
847 /* template for an ICMPv6 router advertisement */
848 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
849 routerAdvertisement := {
850 typeField := 134,
851 code := 0,
852 checksum := '0000'O,
853 curHopLimit := ?,
854 reserved := '000000'B,
855 o_Bit := '0'B,
856 m_Bit := '0'B,
857 routerLifetime := oct2int('FFFF'O),
858 reachableTime := oct2int('FFFFFFFF'O),
859 retransTimer := oct2int('FFFFFFFF'O),
860 options := {
861 ts_ICMP6_OptPrefix(prefix, prefix_len)
862 }
863 }
864 }
865
866 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
867 neighborSolicitation := {
868 typeField := 135,
869 code := 0,
870 checksum := '0000'O,
871 reserved := '00000000'O,
872 targetAddress := target_addr,
873 /* TODO: do we need 'Source link-layer address' ? */
874 options := omit
875 }
876 }
877
878 /* derive ICMPv6 link-local address from lower 64bit of link_id */
879 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
880 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
881 prefixInformation := {
882 typeField := 3,
883 lengthIndicator := 4,
884 prefixLength := prefix_len,
885 reserved1 := ?,
886 a_Bit := ?,
887 l_Bit := ?,
888 validLifetime := ?,
889 preferredLifetime := ?,
890 reserved2 := ?,
891 prefix := prefix
892 }
893 }
894
895 /* template for receiving/matching an ICMPv6 router advertisement */
896 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
897 routerAdvertisement := {
898 typeField := 134,
899 code := 0,
900 checksum := ?,
901 curHopLimit := ?,
902 reserved := ?,
903 o_Bit := '0'B,
904 m_Bit := '0'B,
905 routerLifetime := ?,
906 reachableTime := ?,
907 retransTimer := ?,
908 options := {
909 tr_ICMP6_OptPrefix(prefix, prefix_len)
910 }
911 }
912 }
913
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100914 /* template for receiving/matching an ICMPv6 Destination Unreachable */
915 template PDU_ICMPv6 tr_ICMPv6_DU := {
916 destinationUnreachable := {
917 typeField := 1,
918 code := ?,
919 checksum := ?,
920 unused := ?,
921 originalIpMsg := ?
922 }
923 }
924
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +0100925 /* template for an ICMPv6 echo request */
926 template PDU_ICMPv6 tr_ICMPv6_ERQ := {
927 echoRequest := {
928 typeField := 128,
929 code := 0,
930 checksum := ?,
931 identifier := ?,
932 sequenceNr := ?,
933 data := ?
934 }
935 }
936
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100937 /* template for receiving/matching an ICMPv6 echo reply */
938 template PDU_ICMPv6 tr_ICMPv6_ERP(template octetstring data := *) := {
939 echoReply := {
940 typeField := 129,
941 code := 0,
942 checksum := ?,
943 identifier := ?,
944 sequenceNr := ?,
945 data := data
946 }
947 }
948
Harald Welte231b9412017-08-09 17:16:31 +0200949 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
950 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
951 header := {
952 ver := 6,
953 trclass := 0,
954 flabel := 0,
955 plen := 0,
956 nexthead := nexthead,
957 hlim := hlim,
958 srcaddr := srcaddr,
959 dstaddr := dstaddr
960 },
961 ext_headers := omit,
962 payload := payload
963 }
964
965 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
966 return 'FE80000000000000'O & substr(link_id, 8, 8);
967 }
968
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +0100969 function f_ipv6_global(in OCT16 link_id) return OCT16 {
970 return substr(link_id, 0, 8) & '1234123412341234'O;
971 }
972
973 /* Create a new different IPv6 addr from input. Starts mangling at byte prefix. */
974 function f_ipv6_mangle(in OCT16 addr, in integer prefix := 0) return OCT16 {
975 var integer i;
976 var octetstring res := substr(addr, 0, prefix);
977 for (i := prefix; i < lengthof(addr); i := i + 1) {
978 var octetstring a := addr[i] xor4b '11'O;
979 res := res & a;
980 }
981 return res;
982 }
983
Harald Welte231b9412017-08-09 17:16:31 +0200984 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
985 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
986 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
987 }
988
989 /* generate and encode ICMPv6 router solicitation */
990 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
991 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
992 var OCT16 saddr := f_ipv6_link_local(link_id);
993
994 var octetstring tmp;
995 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
996 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
997
998 return f_IPv6_enc(ip6);
999 }
1000
1001 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
1002 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
1003 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
1004 return f_gen_icmpv6_router_solicitation(interface_id);
1005 }
1006
1007 /* generate and encode ICMPv6 neighbor solicitation */
1008 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
1009 var octetstring tmp;
1010 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
1011 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
1012 return f_IPv6_enc(ip6);
1013 }
1014
1015 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
1016 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
1017 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
1018 var OCT16 link_local := f_ipv6_link_local(interface_id);
1019 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
1020
1021 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
1022 }
1023
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001024 /* Send an ICMPv4 echo msg through GTP given pdp ctx, and ip src and dst addr */
1025 function f_gen_icmpv4_echo(OCT4 saddr, OCT4 daddr) return octetstring {
1026 var octetstring tmp := f_enc_PDU_ICMP(valueof(ts_ICMPv4_ERQ));
1027 var IPv4_packet ip4 := valueof(ts_IP4(saddr, daddr, 1, 50, tmp));
1028 var octetstring data := f_IPv4_enc(ip4);
1029 var OCT2 cksum := f_IPv4_checksum(data);
1030 data[10] := cksum[0];
1031 data[11] := cksum[1];
1032 return data;
1033 }
1034
1035 /* Send an ICMPv6 echo msg through GTP given pdp ctx, and ip src and dst addr */
1036 function f_gen_icmpv6_echo(OCT16 saddr, OCT16 daddr) return octetstring {
1037 var octetstring tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_ERQ), saddr, daddr);
1038 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
1039 var octetstring data := f_IPv6_enc(ip6);
1040 return data;
1041 }
1042
1043 /* Wait for ICMPv4 from GTP */
1044 function f_wait_icmp4(PdpContext ctx, template PDU_ICMP expected) runs on GT_CT {
Harald Welte231b9412017-08-09 17:16:31 +02001045 var Gtp1uUnitdata ud;
1046 T_default.start;
1047 alt {
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001048 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
1049 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1050 var IPv4_packet ip4 := f_IPv4_dec(gpdu);
1051 if (ip4.header.ver != 4) {
1052 repeat;
1053 }
1054 var PDU_ICMP icmp4 := f_dec_PDU_ICMP(ip4.payload);
1055 if (not match(icmp4, expected)) {
1056 repeat;
1057 }
1058 }
1059 [] GTPU.receive { setverdict(fail); }
1060 [] T_default.timeout { setverdict(fail); }
1061 }
1062 T_default.stop;
1063 }
1064
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001065 /* Wait for ICMPv4 echo request from GTP */
1066 function f_wait_icmp4_echo_request(PdpContext ctx) runs on GT_CT {
1067 f_wait_icmp4(ctx, tr_ICMPv4_ERQ);
1068 }
1069
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001070 /* Wait for ICMPv4 echo reply (or unreachable) from GTP */
1071 function f_wait_icmp4_echo_reply(PdpContext ctx) runs on GT_CT {
1072 f_wait_icmp4(ctx, (tr_ICMPv4_ERP, tr_ICMPv4_DU));
1073 }
1074
1075 /* Wait for ICMPv6 from GTP */
1076 function f_wait_icmp6(PdpContext ctx, template PDU_ICMPv6 expected) runs on GT_CT {
1077 var Gtp1uUnitdata ud;
1078 T_default.start;
1079 alt {
Harald Welte231b9412017-08-09 17:16:31 +02001080 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
1081 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
1082 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001083 if (ip6.header.ver != 6 or ip6.header.nexthead != 58) {
Harald Welte231b9412017-08-09 17:16:31 +02001084 repeat;
1085 }
1086 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001087 if (not match(icmp6, expected)) {
Harald Welte231b9412017-08-09 17:16:31 +02001088 repeat;
1089 }
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001090 /* We are waiting for RA, update ctx */
1091 if (match(icmp6, tr_ICMPv6_RA(?, 64))) {
1092 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
1093 log("RA with /64 prefix ", ctx.ip6_prefix);
1094 }
Harald Welte231b9412017-08-09 17:16:31 +02001095 }
1096 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
1097 [] GTPU.receive { setverdict(fail); }
1098 [] T_default.timeout { setverdict(fail); }
1099 }
1100 T_default.stop;
1101 }
1102
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001103 /* wait for GGSN to send us an ICMPv6 router advertisement */
1104 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
1105 f_wait_icmp6(ctx, tr_ICMPv6_RA(?, 64));
1106 }
1107
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001108 /* Wait for ICMPv6 echo request from GTP */
1109 function f_wait_icmp6_echo_request(PdpContext ctx) runs on GT_CT {
1110 f_wait_icmp6(ctx, tr_ICMPv6_ERQ);
1111 }
1112
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001113 /* Wait for ICMPv6 echo reply (or unreachable) from GTP */
1114 function f_wait_icmp6_echo_reply(PdpContext ctx) runs on GT_CT {
1115 f_wait_icmp6(ctx, (tr_ICMPv6_ERP,tr_ICMPv6_DU));
1116 }
1117
1118 /* Assert we don't receive a ICMPv4/6 echo reply (or unreachable) from GTP */
1119 function f_wait_gtpu_fail(PdpContext ctx) runs on GT_CT {
1120 T_default.start;
1121 alt {
1122 [] GTPU.receive { setverdict(fail); }
1123 [] T_default.timeout { }
1124 }
1125 T_default.stop;
1126 }
1127
Harald Welte0ef285b2017-08-13 20:06:01 +02001128 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +02001129 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +02001130 f_init();
Harald Welte231b9412017-08-09 17:16:31 +02001131
Harald Welteed097432017-08-13 13:28:49 +02001132 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welte811651e2017-08-05 15:25:06 +02001133 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +02001134 f_pdp_ctx_del(ctx, '1'B);
1135 }
1136
Harald Welte0ef285b2017-08-13 20:06:01 +02001137 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001138 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
1139 f_init();
1140
Harald Welteed097432017-08-13 13:28:49 +02001141 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001142 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1143 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001144
1145 /* verify PCO contains both primary and secondary DNS */
1146 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
1147 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
1148 setverdict(fail, "Primary DNS IPv6 PCO option not found");
1149 }
1150
1151 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
1152 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
1153 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
1154 }
1155
Harald Welteed7a1772017-08-09 20:26:20 +02001156 f_pdp_ctx_del(ctx, '1'B);
1157 }
1158
Harald Welte0ef285b2017-08-13 20:06:01 +02001159 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +02001160 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
1161 f_init();
1162
Harald Welteed097432017-08-13 13:28:49 +02001163 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001164 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1165 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +02001166
1167 //f_send_gtpu(ctx, c_router_solicit);
1168 //f_send_gtpu(ctx, c_neigh_solicit);
1169
1170 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1171 f_wait_rtr_adv(ctx);
1172 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1173
Harald Welte811651e2017-08-05 15:25:06 +02001174 f_pdp_ctx_del(ctx, '1'B);
Harald Welte94ade362017-08-04 00:36:55 +02001175 }
1176
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001177 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement.
1178 Test we can send ICMPv6 ping over GTPU to DNS server. */
1179 testcase TC_pdp6_act_deact_gtpu_access() runs on GT_CT {
1180 f_init();
1181 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1182 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
1183 f_pdp_ctx_act(ctx);
1184
1185 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
1186 f_wait_rtr_adv(ctx);
1187 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
1188
1189 var OCT16 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '0003'O);
1190
1191 /* Check if we can use valid link-local src addr. */
1192 var OCT16 saddr_ll := f_ipv6_link_local(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1193 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_ll, dns1_addr));
1194 f_wait_icmp6_echo_reply(ctx);
1195
1196 /* Check that attempting RA with another ll src addr won't work, packet dropped: */
1197 var OCT16 saddr_ll_wrong := f_ipv6_mangle(saddr_ll, 8);
1198 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_ll_wrong));
1199 f_wait_gtpu_fail(ctx);
1200
1201 /* Check if we can use valid global src addr, should work */
1202 var OCT16 saddr_glob := f_ipv6_global(ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1203 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_glob, dns1_addr));
1204 f_wait_icmp6_echo_reply(ctx);
1205
1206 /* Assert that packets with wrong global src addr are dropped by GGSN */
1207 var OCT16 saddr_wrong := f_ipv6_mangle(saddr_glob);
1208 f_send_gtpu(ctx, f_gen_icmpv6_echo(saddr_wrong, dns1_addr));
1209 f_wait_gtpu_fail(ctx);
1210
1211 /* Send an IPv4 ICMP ECHO REQUEST to APN6, should fail (packet dropped) */
1212 var OCT4 saddr_v4 := f_inet_addr("192.168.10.2");
1213 var OCT4 daddr_v4 := f_inet_addr("8.8.8.8");
1214 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_v4, daddr_v4));
1215 f_wait_gtpu_fail(ctx);
1216
1217 f_pdp_ctx_del(ctx, '1'B);
1218 }
1219
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001220 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1221 testcase TC_pdp6_clients_interact() runs on GT_CT {
1222 f_init();
1223 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1224 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInet6, valueof(t_EuaIPv6Dyn)));
1225 f_pdp_ctx_act(ctxA);
1226 f_send_gtpu(ctxA, f_icmpv6_rs_for_pdp(ctxA));
1227 f_wait_rtr_adv(ctxA);
1228 f_send_gtpu(ctxA, f_gen_icmpv6_neigh_solicit_for_pdp(ctxA));
1229
1230 f_pdp_ctx_act(ctxB);
1231 f_send_gtpu(ctxB, f_icmpv6_rs_for_pdp(ctxB));
1232 f_wait_rtr_adv(ctxB);
1233 f_send_gtpu(ctxB, f_gen_icmpv6_neigh_solicit_for_pdp(ctxB));
1234
1235 var OCT16 addrA_ll := f_ipv6_link_local(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1236 var OCT16 addrB_ll := f_ipv6_link_local(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1237 var OCT16 addrA_glob := f_ipv6_global(ctxA.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1238 var OCT16 addrB_glob := f_ipv6_global(ctxB.eua.endUserAddress.endUserAddressIPv6.ipv6_address);
1239
1240 /* Validate if clients can interact using ll addr. */
1241 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_ll, addrB_ll));
1242 f_wait_gtpu_fail(ctxB);
1243
1244 /* Validate if clients can interact using global addr. */
1245 f_send_gtpu(ctxA, f_gen_icmpv6_echo(addrA_glob, addrB_glob));
1246 f_wait_gtpu_fail(ctxB);
1247
1248 f_pdp_ctx_del(ctxA, '1'B);
1249 }
1250
Harald Welte0ef285b2017-08-13 20:06:01 +02001251 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +02001252 testcase TC_pdp4_act_deact() runs on GT_CT {
1253 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001254 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Welteed7a1772017-08-09 20:26:20 +02001255 f_pdp_ctx_act(ctx);
1256 f_pdp_ctx_del(ctx, '1'B);
1257 }
1258
Harald Welte0ef285b2017-08-13 20:06:01 +02001259 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +02001260 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
1261 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001262 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1263 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +02001264 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001265 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +02001266 f_pdp_ctx_act(ctx);
Harald Welte71a36022017-12-04 18:55:58 +01001267 /* verify IPCP is at all contained */
1268 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
1269 setverdict(fail, "IPCP not found in PCO");
1270 }
1271 /* verify IPCP contains both primary and secondary DNS */
1272 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +01001273 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
1274 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
1275 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
1276 } else {
1277 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
1278 }
Harald Welte71a36022017-12-04 18:55:58 +01001279 }
Harald Welteed7a1772017-08-09 20:26:20 +02001280 f_pdp_ctx_del(ctx, '1'B);
1281 }
1282
Harald Welte0ef285b2017-08-13 20:06:01 +02001283 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001284 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1285 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001286 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
Harald Weltedca80052017-08-13 20:01:38 +02001287 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001288 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001289
1290 /* verify PCO contains both primary and secondary DNS */
1291 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1292 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1293 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1294 }
1295
1296 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1297 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1298 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1299 }
1300
Harald Welteed7a1772017-08-09 20:26:20 +02001301 f_pdp_ctx_del(ctx, '1'B);
1302 }
1303
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001304 /* Test PDP context activation for dynamic IPv4 EUA.
1305 Test we can send ICMPv6 ping over GTPU to DNS server. */
1306 testcase TC_pdp4_act_deact_gtpu_access() runs on GT_CT {
1307 f_init();
1308 var PdpContext ctx := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1309 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
1310 f_pdp_ctx_act(ctx);
1311
1312 var OCT4 dns1_addr := f_PCO_extract_proto(ctx.pco_neg, '000d'O);
1313
1314 /* Check if we can use valid global src addr, should work */
1315 var OCT4 saddr := ctx.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1316 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr, dns1_addr));
1317 f_wait_icmp4_echo_reply(ctx);
1318
1319 /* Assert that packets with wrong global src addr are dropped by GGSN */
1320 var OCT4 saddr_wrong := substr(saddr, 0, 3) & (saddr[3] xor4b '11'O);
1321 f_send_gtpu(ctx, f_gen_icmpv4_echo(saddr_wrong, dns1_addr));
1322 f_wait_gtpu_fail(ctx);
1323
1324 /* Send an IPv6 RA to APN4, should fail (packet dropped) */
1325 var OCT16 saddr_v6 := f_inet6_addr("fde4:8dba:82e1:2000:1:2:3:4");
1326 f_send_gtpu(ctx, f_gen_icmpv6_router_solicitation(saddr_v6));
1327 f_wait_gtpu_fail(ctx);
1328 f_pdp_ctx_del(ctx, '1'B);
1329 }
1330
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001331 /* Validate if different clients (pdp ctx) can reach one another through GGSN. */
1332 testcase TC_pdp4_clients_interact() runs on GT_CT {
1333 f_init();
1334 var PdpContext ctxA := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1335 var PdpContext ctxB := valueof(t_DefinePDP(f_rnd_imsi('26242'H), '1234'O, c_ApnInternet, valueof(t_EuaIPv4Dyn)));
1336 f_pdp_ctx_act(ctxA);
1337 f_pdp_ctx_act(ctxB);
1338 var OCT4 addrA := ctxA.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1339 var OCT4 addrB := ctxB.eua.endUserAddress.endUserAddressIPv4.ipv4_address;
1340 f_send_gtpu(ctxA, f_gen_icmpv4_echo(addrA, addrB));
1341 f_wait_icmp4_echo_request(ctxB);
1342
1343 f_pdp_ctx_del(ctxA, '1'B);
1344 }
1345
Harald Weltedca80052017-08-13 20:01:38 +02001346 testcase TC_echo_req_resp() runs on GT_CT {
1347 f_init();
1348 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1349 T_default.start;
1350 alt {
1351 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1352 [] GTPC.receive { repeat; };
1353 [] T_default.timeout { setverdict(fail); }
1354 }
1355 T_default.stop;
1356 }
1357
Harald Welte94ade362017-08-04 00:36:55 +02001358 control {
Harald Welteed7a1772017-08-09 20:26:20 +02001359 execute(TC_pdp4_act_deact());
1360 execute(TC_pdp4_act_deact_ipcp());
1361 execute(TC_pdp4_act_deact_pcodns());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001362 execute(TC_pdp4_act_deact_gtpu_access());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001363 execute(TC_pdp4_clients_interact());
Harald Welteed7a1772017-08-09 20:26:20 +02001364
1365 execute(TC_pdp6_act_deact());
1366 execute(TC_pdp6_act_deact_pcodns());
1367 execute(TC_pdp6_act_deact_icmp6());
Pau Espin Pedrol3d9338f2018-01-29 20:42:54 +01001368 execute(TC_pdp6_act_deact_gtpu_access());
Pau Espin Pedrol6c7285d2018-01-30 17:20:22 +01001369 execute(TC_pdp6_clients_interact());
Harald Weltedca80052017-08-13 20:01:38 +02001370
1371 execute(TC_echo_req_resp());
Harald Welte94ade362017-08-04 00:36:55 +02001372 }
Harald Welte379d45a2017-08-03 09:55:15 +02001373}