blob: 8b0d5e40952a9d1168b89614c32a6d96026f1815 [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;
13 import from ICMPv6_Types all;
Harald Welteddeecbb2017-08-18 22:53:30 +020014 import from Native_Functions all;
Harald Welte94ade362017-08-04 00:36:55 +020015
16 const integer GTP0_PORT := 3386;
17 const integer GTP1C_PORT := 2123;
18 const integer GTP1U_PORT := 2152;
Harald Welteddeecbb2017-08-18 22:53:30 +020019
20 modulepar {
21 charstring m_bind_ip_gtpc := "127.23.42.1";
22 charstring m_bind_ip_gtpu := "127.23.42.1";
23
24 charstring m_ggsn_ip_gtpc := "127.0.0.6";
25 charstring m_ggsn_ip_gtpu := "127.0.0.6";
26 }
Harald Welte94ade362017-08-04 00:36:55 +020027
Harald Welte811651e2017-08-05 15:25:06 +020028 type set PdpContext {
29 hexstring imsi,
30 octetstring msisdn optional,
31 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020032 ProtConfigOptions pco_req optional,
33 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020034 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020035 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020036 BIT4 nsapi,
37 /* TEI (Data) local side */
38 OCT4 teid,
39 /* TEI (Control) local side */
40 OCT4 teic,
41 /* TEI (Data) remote side */
42 OCT4 teid_remote,
43 /* TEI (Control) remote side */
Harald Welte5438b9d2017-08-13 13:27:48 +020044 OCT4 teic_remote
Harald Welte811651e2017-08-05 15:25:06 +020045 }
46
Harald Welte94ade362017-08-04 00:36:55 +020047 type component GT_CT {
48 port GTPC_PT GTPC;
49 port GTPU_PT GTPU;
50
Harald Welte0be142b2017-08-13 13:28:10 +020051 var boolean g_initialized := false;
52
Harald Welte94ade362017-08-04 00:36:55 +020053 var OCT1 g_restart_ctr := '01'O;
54 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +020055 var OCT4 g_sgsn_ip_c;
56 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +020057 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +020058 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
59 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +020060 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +020061
62 /* next to-be-sent GTP-C sequence number */
63 var uint16_t g_c_seq_nr;
64 /* next to-be-sent GTP-U sequence number */
65 var uint16_t g_d_seq_nr;
Harald Welte94ade362017-08-04 00:36:55 +020066 }
67
68 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +020069 if (g_initialized == true) {
70 return;
71 }
72 g_initialized := true;
73
Harald Welteddeecbb2017-08-18 22:53:30 +020074 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
75 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
76
Harald Welte94ade362017-08-04 00:36:55 +020077 var Result res;
78 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +020079 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +020080 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +020081 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +020082
83 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +020084 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +020085 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +020086
87 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +020088 g_c_seq_nr := f_rnd_int(65535);
89 g_d_seq_nr := f_rnd_int(65535);
Harald Welte94ade362017-08-04 00:36:55 +020090 }
91
92 /* generalized GTP-C receive template */
Harald Weltedca80052017-08-13 20:01:38 +020093 template PDU_GTPC tr_GTP1C_PDU(template OCT1 msg_type, template OCT4 teid, template GTPC_PDUs pdu := ?) := {
Harald Welte94ade362017-08-04 00:36:55 +020094 /* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an
95 * error if this flag is set to '1'. */
96 pn_bit := '0'B,
97 /* Sequence number flag (S) shall be set to '1'. */
98 s_bit := '1'B,
99 e_bit := ?,
100 spare := ?,
101 /* Protocol Type flag (PT) shall be set to '1'.*/
102 pt := '1'B,
103 /* Version shall be set to decimal 1 ('001'). */
104 version := '001'B,
105 messageType := msg_type,
106 lengthf := ?,
107 teid := teid,
108 opt_part := *,
Harald Weltedca80052017-08-13 20:01:38 +0200109 gtpc_pdu := pdu
Harald Welte94ade362017-08-04 00:36:55 +0200110 }
111
112 /* generalized GTP-C send template */
Harald Welte811651e2017-08-05 15:25:06 +0200113 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 +0200114 /* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an
115 * error if this flag is set to '1'. */
116 pn_bit := '0'B,
117 /* Sequence number flag (S) shall be set to '1'. */
118 s_bit := '1'B,
119 e_bit := '0'B,
120 spare := '0'B,
121 /* Protocol Type flag (PT) shall be set to '1'.*/
122 pt := '1'B,
123 /* Version shall be set to decimal 1 ('001'). */
124 version := '001'B,
125 messageType := msg_type,
126 lengthf := 0, /* we assume encoder overwrites this */
127 teid := teid,
128 opt_part := {
Harald Welte811651e2017-08-05 15:25:06 +0200129 sequenceNumber := int2oct(seq_nr, 2),
Harald Welte94ade362017-08-04 00:36:55 +0200130 npduNumber := '00'O,
131 nextExtHeader := '00'O,
132 gTPC_extensionHeader_List := omit
133 },
134 gtpc_pdu := pdu
135 }
136
137 /* recovery IE */
138 template Recovery_gtpc ts_Recovery(OCT1 restart_counter) := {
Harald Weltedca80052017-08-13 20:01:38 +0200139 type_gtpc := '0E'O,
140 restartCounter := restart_counter
141 }
142
143 template Recovery_gtpc tr_Recovery(template OCT1 restart_counter) := {
144 type_gtpc := '0E'O,
Harald Welte94ade362017-08-04 00:36:55 +0200145 restartCounter := restart_counter
146 }
147
148 /* template matching reception of GTP-C echo-request */
Harald Weltedca80052017-08-13 20:01:38 +0200149 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 +0200150 peer := peer,
Harald Weltedca80052017-08-13 20:01:38 +0200151 gtpc := tr_GTP1C_PDU(msg_type, teid, pdus)
Harald Welte94ade362017-08-04 00:36:55 +0200152 }
153
154 /* template matching reception of GTP-C echo-request */
155 template Gtp1cUnitdata tr_GTPC_PING(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoRequest, '00000000'O);
156
Harald Weltedca80052017-08-13 20:01:38 +0200157 template GTPC_PDUs tr_EchoRespPDU(template OCT1 restart_counter) := {
158 echoResponse := {
159 recovery := tr_Recovery(restart_counter),
160 private_extension_gtpc := *
161 }
162 }
163
164 /* template matching reception of GTP-C echo-response */
165 template Gtp1cUnitdata tr_GTPC_PONG(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoResponse, '00000000'O, tr_EchoRespPDU(?));
166
Harald Welte94ade362017-08-04 00:36:55 +0200167 template GTPC_PDUs ts_EchoRespPDU(OCT1 restart_counter) := {
168 echoResponse := {
Harald Weltedca80052017-08-13 20:01:38 +0200169 recovery := ts_Recovery(restart_counter),
Harald Welte94ade362017-08-04 00:36:55 +0200170 private_extension_gtpc := omit
171 }
172 }
173
174 /* master template for senidng a GTP-C echo response */
Harald Welte811651e2017-08-05 15:25:06 +0200175 template Gtp1cUnitdata ts_GTPC_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := {
Harald Welte94ade362017-08-04 00:36:55 +0200176 peer := peer,
Harald Welte811651e2017-08-05 15:25:06 +0200177 gtpc := ts_GTP1C_PDU(echoResponse, '00000000'O, valueof(ts_EchoRespPDU(rest_ctr)), seq)
Harald Welte94ade362017-08-04 00:36:55 +0200178 }
179
Harald Weltedca80052017-08-13 20:01:38 +0200180 template GTPC_PDUs ts_EchoReqPDU := {
181 echoRequest := {
182 private_extension_gtpc := omit
183 }
184 }
185
186 /* master template for sending a GTP-C echo request */
187 template Gtp1cUnitdata ts_GTPC_PING(GtpPeer peer, uint16_t seq) := {
188 peer := peer,
189 gtpc := ts_GTP1C_PDU(echoRequest, '00000000'O, valueof(ts_EchoReqPDU), seq)
190 }
191
Harald Welte94ade362017-08-04 00:36:55 +0200192 template EndUserAddress t_EuaIPv4(template OCT4 ip_addr) := {
193 type_gtpc := '80'O,
194 endUserAddress := {
195 endUserAddressIPv4 := {
196 lengthf := 2,
197 pdp_typeorg := '0001'B,
198 spare := '1111'B,
199 pdp_typenum := '21'O,
200 ipv4_address := ip_addr
201 }
202 }
203 }
204 template EndUserAddress t_EuaIPv4Dyn := t_EuaIPv4(omit);
Harald Welte99ef9a42017-08-14 21:42:03 +0200205 template EndUserAddress tr_EuaIPv4(template OCT4 ip_addr) modifies t_EuaIPv4 := {
206 endUserAddress := {
207 endUserAddressIPv4 := {
Harald Weltebb5a19e2017-09-21 22:50:41 +0800208 lengthf := 2+lengthof(ip_addr)
Harald Welte99ef9a42017-08-14 21:42:03 +0200209 }
210 }
211 }
212
Harald Welte94ade362017-08-04 00:36:55 +0200213 template EndUserAddress t_EuaIPv6(template OCT16 ip_addr) := {
214 type_gtpc := '80'O,
215 endUserAddress := {
216 endUserAddressIPv6 := {
217 lengthf := 2,
218 pdp_typeorg := '0001'B,
219 spare := '1111'B,
220 pdp_typenum := '57'O,
221 ipv6_address := ip_addr
222 }
223 }
224 }
225 template EndUserAddress t_EuaIPv6Dyn := t_EuaIPv6(omit);
Harald Welte99ef9a42017-08-14 21:42:03 +0200226 template EndUserAddress tr_EuaIPv6(template OCT16 ip_addr) modifies t_EuaIPv6 := {
227 endUserAddress := {
228 endUserAddressIPv6 := {
229 lengthf := 2+lengthof(ip_addr)
230 }
231 }
232 }
Harald Welte94ade362017-08-04 00:36:55 +0200233
234 template AccessPointName ts_APN(octetstring apn) := {
235 type_gtpc := '83'O,
236 lengthf := lengthof(apn),
237 apn_value := apn
238 }
239
240 template GSN_Address_GTPC ts_GsnAddr(octetstring ip_addr) := {
241 type_gtpc := '85'O,
242 lengthf := lengthof(ip_addr),
243 addressf := ip_addr
244 }
245
246 template MSISDN ts_Msisdn(octetstring msisdn) := {
247 type_gtpc := '86'O,
248 lengthf := lengthof(msisdn),
249 msisdn := msisdn
250 }
251
252 template QualityOfServiceProfile ts_QosDefault := {
253 type_gtpc := '87'O,
254 lengthf := 4,
255 allocRetensionPrio := '00'O,
256 qos_ProfileValue := {
257 reliabilityClass := '011'B,
258 delayClass := '001'B,
259 spare1 := '00'B,
260 precedenceClass := '010'B,
261 spare2 := '0'B,
262 peakThroughput := '1001'B,
263 meanThroughput := '11111'B,
264 spare3 := '000'B,
265 deliverErroneusSDU := omit,
266 deliveryOrder := omit,
267 trafficClass := omit,
268 maxSDUSize := omit,
269 maxBitrateUplink := omit,
270 maxBitrateDownlink := omit,
271 sduErrorRatio := omit,
272 residualBER := omit,
273 trafficHandlingPriority := omit,
274 transferDelay := omit,
275 guaranteedBitRateUplink := omit,
276 guaranteedBitRateDownlink := omit,
277 sourceStatisticsDescriptor := omit,
278 signallingIndication := omit,
279 spare4 := omit,
280 maxBitrateDownlinkExt := omit,
281 guaranteedBitRateDownlinkExt := omit,
282 maxBitrateUplinkExt := omit,
283 guaranteedBitRateUplinkExt := omit
284 }
285 }
286
287 template IMSI_gtpc ts_Imsi(hexstring digits) := {
288 type_gtpc := '02'O,
289 digits := digits,
290 padding := 'F'H
291 }
292
293 template GTPC_PDUs ts_CreatePdpPDU(hexstring imsi, OCT1 restart_ctr, OCT4 teid_data, OCT4 teid_ctrl,
294 BIT4 nsapi, EndUserAddress eua, octetstring apn,
295 octetstring sgsn_ip_sign, octetstring sgsn_ip_data,
Harald Welteed7a1772017-08-09 20:26:20 +0200296 octetstring msisdn, template ProtConfigOptions pco := omit) := {
Harald Welte94ade362017-08-04 00:36:55 +0200297 createPDPContextRequest := {
298 imsi := ts_Imsi(imsi),
299 rai := omit,
300 recovery := ts_Recovery(restart_ctr),
301 selectionMode := {
302 type_gtpc := '0F'O,
303 selectModeValue := '00'B,
304 spare := '111111'B
305 },
306 teidDataI := {
307 type_gtpc := '00'O,
308 teidDataI := teid_data
309 },
310 teidControlPlane := {
311 type_gtpc := '00'O,
312 teidControlPlane := teid_ctrl
313 },
314 nsapi := {
315 type_gtpc := '00'O,
316 nsapi := nsapi,
317 unused := '0000'B
318 },
319 linked_nsapi := omit,
320 charging_char := omit,
321 trace_ref := omit,
322 trace_type := omit,
323 endUserAddress := eua,
324 accessPointName := ts_APN(apn),
Harald Welteed7a1772017-08-09 20:26:20 +0200325 protConfigOptions := pco,
Harald Welte94ade362017-08-04 00:36:55 +0200326 sgsn_addr_signalling := ts_GsnAddr(sgsn_ip_sign),
327 sgsn_addr_traffic := ts_GsnAddr(sgsn_ip_data),
328 msisdn := ts_Msisdn(msisdn),
329 qualityOfServiceProfile := ts_QosDefault,
330 tft := omit,
331 triggerId := omit,
332 omcId := omit,
333 commonFlags := omit,
334 aPN_Restriction := omit,
335 ratType := omit,
336 userLocationInformation := omit,
337 mS_TimeZone := omit,
338 imeisv := omit,
339 camelChargingInformationContainer := omit,
340 additionalTraceInfo := omit,
341 correlationID := omit,
342 evolvedAllocationRetentionPriorityI := omit,
343 extendedCommonFlags := omit,
344 userCSGInformation := omit,
345 aPN_AMBR := omit,
346 signallingPriorityIndication := omit,
347 cN_OperatorSelectionEntity := omit,
348 private_extension_gtpc := omit
349 }
350 }
351
Harald Welte811651e2017-08-05 15:25:06 +0200352 template Gtp1cUnitdata ts_GTPC_CreatePDP(GtpPeer peer, uint16_t seq, hexstring imsi,
353 OCT1 restart_ctr, OCT4 teid_data,
Harald Welte94ade362017-08-04 00:36:55 +0200354 OCT4 teid_ctrl, BIT4 nsapi, EndUserAddress eua,
355 octetstring apn, octetstring sgsn_ip_sign,
Harald Welteed7a1772017-08-09 20:26:20 +0200356 octetstring sgsn_ip_data, octetstring msisdn,
357 template ProtConfigOptions pco := omit) := {
Harald Welte94ade362017-08-04 00:36:55 +0200358 peer := peer,
359 gtpc := ts_GTP1C_PDU(createPDPContextRequest, '00000000'O,
360 valueof(ts_CreatePdpPDU(imsi, restart_ctr, teid_data, teid_ctrl,
361 nsapi, eua, apn, sgsn_ip_sign,
Harald Welteed7a1772017-08-09 20:26:20 +0200362 sgsn_ip_data, msisdn, pco)), seq)
363 }
364
Harald Welte99ef9a42017-08-14 21:42:03 +0200365 /* PCO send base template */
Harald Welteed7a1772017-08-09 20:26:20 +0200366 template ProtConfigOptions ts_PCO := {
367 type_gtpc := '84'O,
368 lengthf := 0,
369 configProtocol := '000'B,
370 spare := '0000'B,
371 extension0 := '1'B,
372 protocols := {}
373 }
Harald Welte99ef9a42017-08-14 21:42:03 +0200374 /* PCO receive base template */
375 template ProtConfigOptions tr_PCO := {
376 type_gtpc := '84'O,
377 lengthf := ?,
378 configProtocol := '000'B,
379 spare := ?,
380 extension0 := '1'B,
381 protocols := {}
382 }
Harald Welteed7a1772017-08-09 20:26:20 +0200383
384 template ProtConfigOptions ts_PCO_IPv6_DNS modifies ts_PCO := {
385 protocols := {
386 { protocolID := '0003'O, lengthProtoID := 0, protoIDContents := ''O }
387 }
388 }
Harald Welte99ef9a42017-08-14 21:42:03 +0200389 template ProtConfigOptions tr_PCO_IPv6_DNS_resp(template OCT16 contents) modifies tr_PCO := {
390 protocols := {
Harald Welte3ab91d62017-08-25 14:46:39 +0200391 *, { protocolID := '0003'O, lengthProtoID := 16, protoIDContents := contents }, *
Harald Welte99ef9a42017-08-14 21:42:03 +0200392 }
393 }
Harald Welteed7a1772017-08-09 20:26:20 +0200394
395 template ProtConfigOptions ts_PCO_IPv4_DNS_IPCP modifies ts_PCO := {
396 protocols := {
Harald Welteab4ca942017-09-07 18:41:52 +0200397 /* dummy PAP entry to check if our parser in the GGSN can properly iterate over
398 * the list of protocols, see Change-Id Icc2e6716c33d78d3c3e000f529806228d8aa155e */
399 { protocolID := 'C023'O, lengthProtoID := 0, protoIDContents := ''O },
Harald Welteed7a1772017-08-09 20:26:20 +0200400 { protocolID := '8021'O, lengthProtoID := 16, protoIDContents := '01000010810600000000830600000000'O }
401 }
402 }
403
Harald Welte71a36022017-12-04 18:55:58 +0100404 template ProtocolElement tr_PCO_Proto(OCT2 prot_id) := {
405 protocolID := prot_id,
406 lengthProtoID := ?,
407 protoIDContents := ?
408 }
409 template ProtConfigOptions tr_PCO_Contains(OCT2 prot_id) modifies tr_PCO := {
410 protocols := { *, tr_PCO_Proto(prot_id), * }
411 }
412
Harald Welteed7a1772017-08-09 20:26:20 +0200413 template ProtConfigOptions ts_PCO_IPv4_DNS_CONT modifies ts_PCO := {
414 protocols := {
415 { protocolID := '000d'O, lengthProtoID := 0, protoIDContents := ''O }
416 }
Harald Welte94ade362017-08-04 00:36:55 +0200417 }
Harald Welte99ef9a42017-08-14 21:42:03 +0200418 template ProtConfigOptions tr_PCO_IPv4_DNS_CONT_resp(template OCT4 contents) modifies tr_PCO := {
419 protocols := {
Harald Welte3ab91d62017-08-25 14:46:39 +0200420 *, { protocolID := '000d'O, lengthProtoID := 4, protoIDContents := contents }, *
Harald Welte99ef9a42017-08-14 21:42:03 +0200421 }
422 }
423
Harald Welte71a36022017-12-04 18:55:58 +0100424 /* extract a given protocol payload from PCO */
425 function f_PCO_extract_proto(ProtConfigOptions pco, OCT2 protocol) return octetstring {
426 var integer i;
427 for (i := 0; i < lengthof(pco.protocols); i := i + 1) {
428 if (pco.protocols[i].protocolID == protocol) {
429 return pco.protocols[i].protoIDContents;
430 }
431 }
432 setverdict(fail);
433 return ''O;
434 }
435
436 template IpcpPacket tr_IPCP(template LcpCode code, template uint8_t identifier,
437 template IpcpOptionList opts) := {
438 code := code,
439 identifier := identifier,
440 len := ?,
441 options := opts
442 }
443 template IpcpOption tr_IPCP_PrimaryDns(template OCT4 addr) := {
444 code := IPCP_OPT_PrimaryDNS,
445 len := 6,
446 data := addr
447 }
448 template IpcpOption tr_IPCP_SecondaryDns(template OCT4 addr) := {
449 code := IPCP_OPT_SecondaryDNS,
450 len := 6,
451 data := addr
452 }
453
454 template IpcpPacket tr_IPCP_Ack_DNS(template uint8_t identifier := ?, template OCT4 dns1 := ?,
455 template OCT4 dns2 := ?) :=
456 tr_IPCP(LCP_Configure_Ack, identifier,
457 { *, tr_IPCP_PrimaryDns(dns1), *, tr_IPCP_SecondaryDns(dns2), * });
458
Harald Welte94ade362017-08-04 00:36:55 +0200459
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200460 function f_teardown_ind_IE(in template BIT1 ind) return template TearDownInd {
Harald Welte811651e2017-08-05 15:25:06 +0200461/*
462 if (not isvalue(ind)) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200463 return omit;
464 }
Harald Welte811651e2017-08-05 15:25:06 +0200465*/
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200466 var TearDownInd ret := {
467 type_gtpc := '13'O,
468 tdInd := valueof(ind),
469 spare:= '0000000'B
470 }
471 return ret;
472 }
473
474 template GTPC_PDUs ts_DeletePdpPDU(BIT4 nsapi, template BIT1 teardown_ind) := {
475 deletePDPContextRequest := {
476 cause := omit,
477 tearDownIndicator := f_teardown_ind_IE(teardown_ind),
478 nsapi := {
479 type_gtpc := '14'O,
480 nsapi := nsapi,
481 unused := '0000'B
482 },
483 protConfigOptions := omit,
484 userLocationInformation := omit,
485 mS_TimeZone := omit,
486 extendedCommonFlags := omit,
487 uLI_Timestamp := omit,
488 private_extension_gtpc := omit
489 }
490 }
491
Harald Welte811651e2017-08-05 15:25:06 +0200492 template Gtp1cUnitdata ts_GTPC_DeletePDP(GtpPeer peer, uint16_t seq, OCT4 teid,
493 BIT4 nsapi, template BIT1 teardown_ind) := {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200494 peer := peer,
495 gtpc := ts_GTP1C_PDU(deletePDPContextRequest, teid,
Harald Welte811651e2017-08-05 15:25:06 +0200496 valueof(ts_DeletePdpPDU(nsapi, teardown_ind)), seq)
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200497 }
498
499
Harald Welte3af89482017-08-04 16:20:23 +0200500 /* GTP-U */
501
Harald Welte231b9412017-08-09 17:16:31 +0200502 template PDU_GTPU tr_GTP1U_PDU(template OCT1 msg_type, template OCT4 teid, template GTPU_IEs ies := ?) := {
Harald Welte3af89482017-08-04 16:20:23 +0200503 pn_bit := ?,
504 s_bit := ?,
505 e_bit := ?,
506 spare := ?,
507 /* Protocol Type flag (PT) shall be set to '1' in GTP */
508 pt := '1'B,
509 /* Version shall be set to decimal 1 ('001'). */
510 version := '001'B,
511 messageType := msg_type,
512 lengthf := ?,
513 teid := teid,
514 opt_part := *,
Harald Welte231b9412017-08-09 17:16:31 +0200515 gtpu_IEs := ies
Harald Welte3af89482017-08-04 16:20:23 +0200516 }
517
518 /* generalized GTP-U send template */
Harald Welte811651e2017-08-05 15:25:06 +0200519 template PDU_GTPU ts_GTP1U_PDU(OCT1 msg_type, uint16_t seq, OCT4 teid, GTPU_IEs ies) := {
Harald Welte3af89482017-08-04 16:20:23 +0200520 /* N-PDU Number flag (PN): the GTP-U header contains a meaningful N-PDU Number field if the PN
521 * flag is set to 1. */
522 pn_bit := '0'B, /* we assume the encoder overwrites this if an optional part is given */
523 /* If the Sequence Number flag (S) is set to '1' the sequence number field is present and
524 * meaningful otherwise it is set to '0'. For GTP-U messages Echo Request, Echo Response,
525 * Error Indication and Supported Extension Headers Notification, the S flag shall be set to '1'. */
Harald Welte811651e2017-08-05 15:25:06 +0200526 s_bit := '1'B, /* we assume the encoder overwrites this if an optional part is given */
Harald Welte3af89482017-08-04 16:20:23 +0200527 /* Extension header presence */
528 e_bit := '0'B,
529 spare := '0'B,
530 /* Protocol Type flag (PT) shall be set to '1' in GTP */
531 pt := '1'B,
532 /* Version shall be set to decimal 1 ('001'). */
533 version := '001'B,
534 messageType := msg_type,
535 lengthf := 0, /* we assume encoder overwrites this */
536 teid := teid,
Harald Welte811651e2017-08-05 15:25:06 +0200537 opt_part := {
538 sequenceNumber := int2oct(seq, 2),
539 npduNumber := '00'O,
540 nextExtHeader := '00'O,
541 gTPU_extensionHeader_List := omit
542 },
Harald Welte3af89482017-08-04 16:20:23 +0200543 gtpu_IEs := ies
544 }
545
546 template Gtp1uUnitdata tr_GTPU_MsgType(template GtpPeer peer, template OCT1 msg_type, template OCT4 teid) := {
547 peer := peer,
548 gtpu := tr_GTP1U_PDU(msg_type, teid)
549 }
550
551
Harald Welte231b9412017-08-09 17:16:31 +0200552 /* template matching reception of GTP-U echo-request */
Harald Welte3af89482017-08-04 16:20:23 +0200553 template Gtp1uUnitdata tr_GTPU_PING(template GtpPeer peer) := tr_GTPU_MsgType(peer, echoRequest, '00000000'O);
554
Harald Welte231b9412017-08-09 17:16:31 +0200555 /* template matching reception of GTP-U GPDU */
556 template GTPU_IEs t_GPDU(template octetstring data) := {
557 g_PDU_IEs := {
558 data := data
559 }
560 }
561 template Gtp1uUnitdata tr_GTPU_GPDU(template GtpPeer peer, template OCT4 teid, template octetstring data := ?) := {
562 peer := peer,
563 gtpu := tr_GTP1U_PDU('FF'O, teid, t_GPDU(data))
564 }
565
Harald Welte3af89482017-08-04 16:20:23 +0200566 template GTPU_IEs ts_UEchoRespPDU(OCT1 restart_counter) := {
567 echoResponse_IEs := {
568 recovery_gtpu := {
569 type_gtpu := '00'O, /* we assume encoder fixes? */
570 restartCounter := restart_counter
571 },
572 private_extension_gtpu := omit
573 }
574 }
575
576 /* master template for sending a GTP-U echo response */
Harald Welte811651e2017-08-05 15:25:06 +0200577 template Gtp1uUnitdata ts_GTPU_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := {
Harald Welte3af89482017-08-04 16:20:23 +0200578 peer := peer,
Harald Welte811651e2017-08-05 15:25:06 +0200579 gtpu := ts_GTP1U_PDU(echoResponse, seq, '00000000'O, valueof(ts_UEchoRespPDU(rest_ctr)))
Harald Welte3af89482017-08-04 16:20:23 +0200580 }
581
Harald Welte811651e2017-08-05 15:25:06 +0200582 /* master template for sending a GTP-U user plane data */
583 template Gtp1uUnitdata ts_GTP1U_GPDU(GtpPeer peer, uint16_t seq, OCT4 teid, octetstring data) := {
584 peer := peer,
585 gtpu := ts_GTP1U_PDU('FF'O, seq, teid, { g_PDU_IEs := { data := data }})
586 }
Harald Welte3af89482017-08-04 16:20:23 +0200587
Harald Welte94ade362017-08-04 00:36:55 +0200588 /* Altstep implementing responses to any incoming echo requests */
589 altstep pingpong() runs on GT_CT {
590 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200591 var Gtp1uUnitdata udu;
Harald Welte94ade362017-08-04 00:36:55 +0200592 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200593 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
594 GTPC.send(ts_GTPC_PONG(ud.peer, seq, '00'O));
Harald Welte94ade362017-08-04 00:36:55 +0200595 repeat;
596 };
Harald Welte3af89482017-08-04 16:20:23 +0200597 [] GTPU.receive(tr_GTPU_PING(?)) -> value udu {
Harald Welte811651e2017-08-05 15:25:06 +0200598 var uint16_t seq := oct2int(udu.gtpu.opt_part.sequenceNumber);
599 GTPU.send(ts_GTPU_PONG(udu.peer, seq, '00'O));
Harald Welte3af89482017-08-04 16:20:23 +0200600 };
Harald Welte94ade362017-08-04 00:36:55 +0200601 [] T_default.timeout { setverdict(fail); };
602 }
603
Harald Welte811651e2017-08-05 15:25:06 +0200604 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200605 const octetstring c_ApnInternet := '08696E7465726E6574'O;
606 const octetstring c_ApnInet6 := '05696E657436'O;
607 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200608
Harald Welte811651e2017-08-05 15:25:06 +0200609 /* return random integer between 0 and max */
610 function f_rnd_int(integer max) return integer {
611 return float2int(rnd()*int2float(max));
612 }
613
614 /* return random NSAPI */
615 function f_rnd_nsapi() return BIT4 {
616 return int2bit(f_rnd_int(16), 4);
617 }
618
619 /* return random TEI[DC] */
620 function f_rnd_tei() return OCT4 {
621 return int2oct(f_rnd_int(4294967296), 4);
622 }
623
Harald Welteed097432017-08-13 13:28:49 +0200624 /* return hexstring composed of random digits */
625 function f_rnd_hexstring(in integer len, in integer max := 15) return hexstring {
626 var integer i;
627 var hexstring ret := ''H;
628 for (i := 0; i < len; i := i + 1) {
629 ret := ret & int2hex(f_rnd_int(max), 1);
630 }
631 return ret;
632 }
633
634 /* return octetstring composed of random bytes */
635 function f_rnd_octstring(in integer len) return octetstring {
636 var integer i;
637 var octetstring ret := ''O;
638 for (i := 0; i < len; i := i + 1) {
639 ret := ret & int2oct(f_rnd_int(255), 1);
640 }
641 return ret;
642 }
643
644 function f_rnd_imsi(in hexstring prefix) return hexstring {
645 return prefix & f_rnd_hexstring(15 - lengthof(prefix), 9);
646 }
647
648 function f_rnd_msisdn(in octetstring prefix, integer len := 6) return octetstring {
649 return prefix & f_rnd_octstring(len - lengthof(prefix));
650 }
651
652
Harald Welte811651e2017-08-05 15:25:06 +0200653 /* define an (internal) representation of a PDP context */
654 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
655 EndUserAddress eua) := {
656 imsi := imsi,
657 msisdn := msisdn,
658 nsapi := f_rnd_nsapi(),
659 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200660 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200661 eua := eua,
662 teid := f_rnd_tei(),
Harald Welte5438b9d2017-08-13 13:27:48 +0200663 teic := f_rnd_tei()
Harald Welte811651e2017-08-05 15:25:06 +0200664 }
665
666 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200667 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200668 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200669 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200670 }
671
672 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200673 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte5438b9d2017-08-13 13:27:48 +0200674 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
675 g_d_seq_nr := g_d_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200676 }
677
678 /* send a PDP context activation */
679 function f_pdp_ctx_act(inout PdpContext ctx) runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200680 var Gtp1cUnitdata ud;
Harald Welte94ade362017-08-04 00:36:55 +0200681 var default d;
682
683 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200684 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 +0200685 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200686 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req));
Harald Welte94ade362017-08-04 00:36:55 +0200687 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200688 d := activate(pingpong());
689 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200690 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
691 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
692 if (cpr.cause.causevalue == '80'O) {
Harald Welte99ef9a42017-08-14 21:42:03 +0200693 /* Check if EUA type corresponds to requested type */
694 if (match(ctx.eua, t_EuaIPv4(?)) and
695 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
696 setverdict(fail);
697 }
698 if (match(ctx.eua, t_EuaIPv6(?)) and
699 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
700 setverdict(fail);
701 }
702 /* Check if PCO response corresponds to request */
703 if (ispresent(ctx.pco_req)) {
704 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
705 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
706 log("IPv4 DNS Container requested, but missing");
707 setverdict(fail);
708 }
709 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
710 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
711 log("IPv6 DNS Container requested, but missing");
712 setverdict(fail);
713 }
714 }
Harald Welte811651e2017-08-05 15:25:06 +0200715 ctx.teid_remote := cpr.teidDataI.teidDataI;
716 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
Harald Welte231b9412017-08-09 17:16:31 +0200717 ctx.eua := cpr.endUserAddress;
Harald Welteed7a1772017-08-09 20:26:20 +0200718 ctx.pco_neg := cpr.protConfigOptions;
Harald Welte94ade362017-08-04 00:36:55 +0200719 setverdict(pass);
720 } else {
721 setverdict(fail);
722 }
723 }
724 }
725 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200726 T_default.stop;
Harald Welte94ade362017-08-04 00:36:55 +0200727 }
728
Harald Welte811651e2017-08-05 15:25:06 +0200729 function f_pdp_ctx_del(PdpContext ctx, template BIT1 teardown_ind) runs on GT_CT {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200730 var Gtp1cUnitdata ud;
731 var default d;
732
Harald Welte41575e92017-08-13 13:49:57 +0200733 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 +0200734 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200735 d := activate(pingpong());
736 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200737 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ctx.teic)) -> value ud {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200738 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == '80'O) {
739 setverdict(pass);
740 } else {
741 setverdict(fail);
742 }
743 }
744 }
745 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200746 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200747 }
Harald Welte811651e2017-08-05 15:25:06 +0200748 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
749 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
750 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
751 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200752
Harald Welte231b9412017-08-09 17:16:31 +0200753 /* template to generate a 'Prefix Information' ICMPv6 option */
754 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
755 prefixInformation := {
756 typeField := 3,
757 lengthIndicator := 8,
758 prefixLength := prefix_len,
759 reserved1 := '000000'B,
760 a_Bit := '0'B,
761 l_Bit := '0'B,
762 validLifetime := oct2int('FFFFFFFF'O),
763 preferredLifetime := oct2int('FFFFFFFF'O),
764 reserved2 := '00000000'O,
765 prefix := prefix
766 }
767 }
768
769 /* template for an ICMPv6 router solicitation */
770 template PDU_ICMPv6 ts_ICMPv6_RS := {
771 routerSolicitation := {
772 typeField := 133,
773 code := 0,
774 checksum := '0000'O,
775 reserved := '00000000'O,
776 /* TODO: do we need 'Source link-layer address' ? */
777 options := omit
778 }
779 }
780
781 /* template for an ICMPv6 router advertisement */
782 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
783 routerAdvertisement := {
784 typeField := 134,
785 code := 0,
786 checksum := '0000'O,
787 curHopLimit := ?,
788 reserved := '000000'B,
789 o_Bit := '0'B,
790 m_Bit := '0'B,
791 routerLifetime := oct2int('FFFF'O),
792 reachableTime := oct2int('FFFFFFFF'O),
793 retransTimer := oct2int('FFFFFFFF'O),
794 options := {
795 ts_ICMP6_OptPrefix(prefix, prefix_len)
796 }
797 }
798 }
799
800 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
801 neighborSolicitation := {
802 typeField := 135,
803 code := 0,
804 checksum := '0000'O,
805 reserved := '00000000'O,
806 targetAddress := target_addr,
807 /* TODO: do we need 'Source link-layer address' ? */
808 options := omit
809 }
810 }
811
812 /* derive ICMPv6 link-local address from lower 64bit of link_id */
813 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
814 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
815 prefixInformation := {
816 typeField := 3,
817 lengthIndicator := 4,
818 prefixLength := prefix_len,
819 reserved1 := ?,
820 a_Bit := ?,
821 l_Bit := ?,
822 validLifetime := ?,
823 preferredLifetime := ?,
824 reserved2 := ?,
825 prefix := prefix
826 }
827 }
828
829 /* template for receiving/matching an ICMPv6 router advertisement */
830 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
831 routerAdvertisement := {
832 typeField := 134,
833 code := 0,
834 checksum := ?,
835 curHopLimit := ?,
836 reserved := ?,
837 o_Bit := '0'B,
838 m_Bit := '0'B,
839 routerLifetime := ?,
840 reachableTime := ?,
841 retransTimer := ?,
842 options := {
843 tr_ICMP6_OptPrefix(prefix, prefix_len)
844 }
845 }
846 }
847
848 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
849 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
850 header := {
851 ver := 6,
852 trclass := 0,
853 flabel := 0,
854 plen := 0,
855 nexthead := nexthead,
856 hlim := hlim,
857 srcaddr := srcaddr,
858 dstaddr := dstaddr
859 },
860 ext_headers := omit,
861 payload := payload
862 }
863
864 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
865 return 'FE80000000000000'O & substr(link_id, 8, 8);
866 }
867
868 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
869 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
870 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
871 }
872
873 /* generate and encode ICMPv6 router solicitation */
874 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
875 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
876 var OCT16 saddr := f_ipv6_link_local(link_id);
877
878 var octetstring tmp;
879 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
880 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
881
882 return f_IPv6_enc(ip6);
883 }
884
885 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
886 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
887 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
888 return f_gen_icmpv6_router_solicitation(interface_id);
889 }
890
891 /* generate and encode ICMPv6 neighbor solicitation */
892 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
893 var octetstring tmp;
894 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
895 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
896 return f_IPv6_enc(ip6);
897 }
898
899 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
900 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
901 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
902 var OCT16 link_local := f_ipv6_link_local(interface_id);
903 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
904
905 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
906 }
907
908 /* wait for GGSN to send us an ICMPv6 router advertisement */
909 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
910 var Gtp1uUnitdata ud;
911 T_default.start;
912 alt {
913 //'6???????????3aff'O
914 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
915 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
916 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
917 if (ip6.header.ver != 6 or ip6.header.nexthead != 58 or ip6.header.hlim != 255) {
918 repeat;
919 }
920 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
921 if (not match(icmp6, tr_ICMPv6_RA(?, 64))) {
922 repeat;
923 }
924 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
925 log("RA with /64 prefix ", ctx.ip6_prefix);
926 }
927 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
928 [] GTPU.receive { setverdict(fail); }
929 [] T_default.timeout { setverdict(fail); }
930 }
931 T_default.stop;
932 }
933
Harald Welte0ef285b2017-08-13 20:06:01 +0200934 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +0200935 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200936 f_init();
Harald Welte231b9412017-08-09 17:16:31 +0200937
Harald Welteed097432017-08-13 13:28:49 +0200938 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 +0200939 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +0200940 f_pdp_ctx_del(ctx, '1'B);
941 }
942
Harald Welte0ef285b2017-08-13 20:06:01 +0200943 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +0200944 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
945 f_init();
946
Harald Welteed097432017-08-13 13:28:49 +0200947 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 +0200948 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
949 f_pdp_ctx_act(ctx);
950 f_pdp_ctx_del(ctx, '1'B);
951 }
952
Harald Welte0ef285b2017-08-13 20:06:01 +0200953 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +0200954 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
955 f_init();
956
Harald Welteed097432017-08-13 13:28:49 +0200957 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 +0200958 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
959 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200960
961 //f_send_gtpu(ctx, c_router_solicit);
962 //f_send_gtpu(ctx, c_neigh_solicit);
963
964 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
965 f_wait_rtr_adv(ctx);
966 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
967
Harald Welte811651e2017-08-05 15:25:06 +0200968 f_pdp_ctx_del(ctx, '1'B);
Harald Welte94ade362017-08-04 00:36:55 +0200969 }
970
Harald Welte0ef285b2017-08-13 20:06:01 +0200971 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +0200972 testcase TC_pdp4_act_deact() runs on GT_CT {
973 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200974 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 +0200975 f_pdp_ctx_act(ctx);
976 f_pdp_ctx_del(ctx, '1'B);
977 }
978
Harald Welte0ef285b2017-08-13 20:06:01 +0200979 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +0200980 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
981 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200982 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 +0200983 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +0200984 f_pdp_ctx_act(ctx);
Harald Welte71a36022017-12-04 18:55:58 +0100985 /* verify IPCP is at all contained */
986 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
987 setverdict(fail, "IPCP not found in PCO");
988 }
989 /* verify IPCP contains both primary and secondary DNS */
990 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
991 if (not match(ipcp, tr_IPCP_Ack_DNS)) {
992 setverdict(fail, "Primary/Secondary DNS not found in IPCP");
993 }
Harald Welteed7a1772017-08-09 20:26:20 +0200994 f_pdp_ctx_del(ctx, '1'B);
995 }
996
Harald Welte0ef285b2017-08-13 20:06:01 +0200997 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +0200998 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
999 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001000 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 +02001001 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001002 f_pdp_ctx_act(ctx);
1003 f_pdp_ctx_del(ctx, '1'B);
1004 }
1005
Harald Weltedca80052017-08-13 20:01:38 +02001006 testcase TC_echo_req_resp() runs on GT_CT {
1007 f_init();
1008 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1009 T_default.start;
1010 alt {
1011 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1012 [] GTPC.receive { repeat; };
1013 [] T_default.timeout { setverdict(fail); }
1014 }
1015 T_default.stop;
1016 }
1017
Harald Welte94ade362017-08-04 00:36:55 +02001018 control {
Harald Welteed7a1772017-08-09 20:26:20 +02001019 execute(TC_pdp4_act_deact());
1020 execute(TC_pdp4_act_deact_ipcp());
1021 execute(TC_pdp4_act_deact_pcodns());
1022
1023 execute(TC_pdp6_act_deact());
1024 execute(TC_pdp6_act_deact_pcodns());
1025 execute(TC_pdp6_act_deact_icmp6());
Harald Weltedca80052017-08-13 20:01:38 +02001026
1027 execute(TC_echo_req_resp());
Harald Welte94ade362017-08-04 00:36:55 +02001028 }
Harald Welte379d45a2017-08-03 09:55:15 +02001029}