blob: 06d9dcf601e29d5c8a5d360a55e31e11abe01362 [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";
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +010026
27 charstring m_ggsn_ip4_dns1 := "192.168.100.1"
28 charstring m_ggsn_ip4_dns2 := "8.8.8.8"
Harald Welteddeecbb2017-08-18 22:53:30 +020029 }
Harald Welte94ade362017-08-04 00:36:55 +020030
Harald Welte811651e2017-08-05 15:25:06 +020031 type set PdpContext {
32 hexstring imsi,
33 octetstring msisdn optional,
34 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020035 ProtConfigOptions pco_req optional,
36 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020037 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020038 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020039 BIT4 nsapi,
40 /* TEI (Data) local side */
41 OCT4 teid,
42 /* TEI (Control) local side */
43 OCT4 teic,
44 /* TEI (Data) remote side */
45 OCT4 teid_remote,
46 /* TEI (Control) remote side */
Harald Welte5438b9d2017-08-13 13:27:48 +020047 OCT4 teic_remote
Harald Welte811651e2017-08-05 15:25:06 +020048 }
49
Harald Welte94ade362017-08-04 00:36:55 +020050 type component GT_CT {
51 port GTPC_PT GTPC;
52 port GTPU_PT GTPU;
53
Harald Welte0be142b2017-08-13 13:28:10 +020054 var boolean g_initialized := false;
55
Harald Welte94ade362017-08-04 00:36:55 +020056 var OCT1 g_restart_ctr := '01'O;
57 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +020058 var OCT4 g_sgsn_ip_c;
59 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +020060 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +020061 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
62 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +020063 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +020064
65 /* next to-be-sent GTP-C sequence number */
66 var uint16_t g_c_seq_nr;
67 /* next to-be-sent GTP-U sequence number */
68 var uint16_t g_d_seq_nr;
Harald Welte94ade362017-08-04 00:36:55 +020069 }
70
71 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +020072 if (g_initialized == true) {
73 return;
74 }
75 g_initialized := true;
76
Harald Welteddeecbb2017-08-18 22:53:30 +020077 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
78 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
79
Harald Welte94ade362017-08-04 00:36:55 +020080 var Result res;
81 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +020082 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +020083 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +020084 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +020085
86 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +020087 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +020088 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +020089
90 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +020091 g_c_seq_nr := f_rnd_int(65535);
92 g_d_seq_nr := f_rnd_int(65535);
Harald Welte94ade362017-08-04 00:36:55 +020093 }
94
95 /* generalized GTP-C receive template */
Harald Weltedca80052017-08-13 20:01:38 +020096 template PDU_GTPC tr_GTP1C_PDU(template OCT1 msg_type, template OCT4 teid, template GTPC_PDUs pdu := ?) := {
Harald Welte94ade362017-08-04 00:36:55 +020097 /* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an
98 * error if this flag is set to '1'. */
99 pn_bit := '0'B,
100 /* Sequence number flag (S) shall be set to '1'. */
101 s_bit := '1'B,
102 e_bit := ?,
103 spare := ?,
104 /* Protocol Type flag (PT) shall be set to '1'.*/
105 pt := '1'B,
106 /* Version shall be set to decimal 1 ('001'). */
107 version := '001'B,
108 messageType := msg_type,
109 lengthf := ?,
110 teid := teid,
111 opt_part := *,
Harald Weltedca80052017-08-13 20:01:38 +0200112 gtpc_pdu := pdu
Harald Welte94ade362017-08-04 00:36:55 +0200113 }
114
115 /* generalized GTP-C send template */
Harald Welte811651e2017-08-05 15:25:06 +0200116 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 +0200117 /* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an
118 * error if this flag is set to '1'. */
119 pn_bit := '0'B,
120 /* Sequence number flag (S) shall be set to '1'. */
121 s_bit := '1'B,
122 e_bit := '0'B,
123 spare := '0'B,
124 /* Protocol Type flag (PT) shall be set to '1'.*/
125 pt := '1'B,
126 /* Version shall be set to decimal 1 ('001'). */
127 version := '001'B,
128 messageType := msg_type,
129 lengthf := 0, /* we assume encoder overwrites this */
130 teid := teid,
131 opt_part := {
Harald Welte811651e2017-08-05 15:25:06 +0200132 sequenceNumber := int2oct(seq_nr, 2),
Harald Welte94ade362017-08-04 00:36:55 +0200133 npduNumber := '00'O,
134 nextExtHeader := '00'O,
135 gTPC_extensionHeader_List := omit
136 },
137 gtpc_pdu := pdu
138 }
139
140 /* recovery IE */
141 template Recovery_gtpc ts_Recovery(OCT1 restart_counter) := {
Harald Weltedca80052017-08-13 20:01:38 +0200142 type_gtpc := '0E'O,
143 restartCounter := restart_counter
144 }
145
146 template Recovery_gtpc tr_Recovery(template OCT1 restart_counter) := {
147 type_gtpc := '0E'O,
Harald Welte94ade362017-08-04 00:36:55 +0200148 restartCounter := restart_counter
149 }
150
151 /* template matching reception of GTP-C echo-request */
Harald Weltedca80052017-08-13 20:01:38 +0200152 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 +0200153 peer := peer,
Harald Weltedca80052017-08-13 20:01:38 +0200154 gtpc := tr_GTP1C_PDU(msg_type, teid, pdus)
Harald Welte94ade362017-08-04 00:36:55 +0200155 }
156
157 /* template matching reception of GTP-C echo-request */
158 template Gtp1cUnitdata tr_GTPC_PING(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoRequest, '00000000'O);
159
Harald Weltedca80052017-08-13 20:01:38 +0200160 template GTPC_PDUs tr_EchoRespPDU(template OCT1 restart_counter) := {
161 echoResponse := {
162 recovery := tr_Recovery(restart_counter),
163 private_extension_gtpc := *
164 }
165 }
166
167 /* template matching reception of GTP-C echo-response */
168 template Gtp1cUnitdata tr_GTPC_PONG(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoResponse, '00000000'O, tr_EchoRespPDU(?));
169
Harald Welte94ade362017-08-04 00:36:55 +0200170 template GTPC_PDUs ts_EchoRespPDU(OCT1 restart_counter) := {
171 echoResponse := {
Harald Weltedca80052017-08-13 20:01:38 +0200172 recovery := ts_Recovery(restart_counter),
Harald Welte94ade362017-08-04 00:36:55 +0200173 private_extension_gtpc := omit
174 }
175 }
176
177 /* master template for senidng a GTP-C echo response */
Harald Welte811651e2017-08-05 15:25:06 +0200178 template Gtp1cUnitdata ts_GTPC_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := {
Harald Welte94ade362017-08-04 00:36:55 +0200179 peer := peer,
Harald Welte811651e2017-08-05 15:25:06 +0200180 gtpc := ts_GTP1C_PDU(echoResponse, '00000000'O, valueof(ts_EchoRespPDU(rest_ctr)), seq)
Harald Welte94ade362017-08-04 00:36:55 +0200181 }
182
Harald Weltedca80052017-08-13 20:01:38 +0200183 template GTPC_PDUs ts_EchoReqPDU := {
184 echoRequest := {
185 private_extension_gtpc := omit
186 }
187 }
188
189 /* master template for sending a GTP-C echo request */
190 template Gtp1cUnitdata ts_GTPC_PING(GtpPeer peer, uint16_t seq) := {
191 peer := peer,
192 gtpc := ts_GTP1C_PDU(echoRequest, '00000000'O, valueof(ts_EchoReqPDU), seq)
193 }
194
Harald Welte94ade362017-08-04 00:36:55 +0200195 template EndUserAddress t_EuaIPv4(template OCT4 ip_addr) := {
196 type_gtpc := '80'O,
197 endUserAddress := {
198 endUserAddressIPv4 := {
199 lengthf := 2,
200 pdp_typeorg := '0001'B,
201 spare := '1111'B,
202 pdp_typenum := '21'O,
203 ipv4_address := ip_addr
204 }
205 }
206 }
207 template EndUserAddress t_EuaIPv4Dyn := t_EuaIPv4(omit);
Harald Welte99ef9a42017-08-14 21:42:03 +0200208 template EndUserAddress tr_EuaIPv4(template OCT4 ip_addr) modifies t_EuaIPv4 := {
209 endUserAddress := {
210 endUserAddressIPv4 := {
Harald Weltebb5a19e2017-09-21 22:50:41 +0800211 lengthf := 2+lengthof(ip_addr)
Harald Welte99ef9a42017-08-14 21:42:03 +0200212 }
213 }
214 }
215
Harald Welte94ade362017-08-04 00:36:55 +0200216 template EndUserAddress t_EuaIPv6(template OCT16 ip_addr) := {
217 type_gtpc := '80'O,
218 endUserAddress := {
219 endUserAddressIPv6 := {
220 lengthf := 2,
221 pdp_typeorg := '0001'B,
222 spare := '1111'B,
223 pdp_typenum := '57'O,
224 ipv6_address := ip_addr
225 }
226 }
227 }
228 template EndUserAddress t_EuaIPv6Dyn := t_EuaIPv6(omit);
Harald Welte99ef9a42017-08-14 21:42:03 +0200229 template EndUserAddress tr_EuaIPv6(template OCT16 ip_addr) modifies t_EuaIPv6 := {
230 endUserAddress := {
231 endUserAddressIPv6 := {
232 lengthf := 2+lengthof(ip_addr)
233 }
234 }
235 }
Harald Welte94ade362017-08-04 00:36:55 +0200236
237 template AccessPointName ts_APN(octetstring apn) := {
238 type_gtpc := '83'O,
239 lengthf := lengthof(apn),
240 apn_value := apn
241 }
242
243 template GSN_Address_GTPC ts_GsnAddr(octetstring ip_addr) := {
244 type_gtpc := '85'O,
245 lengthf := lengthof(ip_addr),
246 addressf := ip_addr
247 }
248
249 template MSISDN ts_Msisdn(octetstring msisdn) := {
250 type_gtpc := '86'O,
251 lengthf := lengthof(msisdn),
252 msisdn := msisdn
253 }
254
255 template QualityOfServiceProfile ts_QosDefault := {
256 type_gtpc := '87'O,
257 lengthf := 4,
258 allocRetensionPrio := '00'O,
259 qos_ProfileValue := {
260 reliabilityClass := '011'B,
261 delayClass := '001'B,
262 spare1 := '00'B,
263 precedenceClass := '010'B,
264 spare2 := '0'B,
265 peakThroughput := '1001'B,
266 meanThroughput := '11111'B,
267 spare3 := '000'B,
268 deliverErroneusSDU := omit,
269 deliveryOrder := omit,
270 trafficClass := omit,
271 maxSDUSize := omit,
272 maxBitrateUplink := omit,
273 maxBitrateDownlink := omit,
274 sduErrorRatio := omit,
275 residualBER := omit,
276 trafficHandlingPriority := omit,
277 transferDelay := omit,
278 guaranteedBitRateUplink := omit,
279 guaranteedBitRateDownlink := omit,
280 sourceStatisticsDescriptor := omit,
281 signallingIndication := omit,
282 spare4 := omit,
283 maxBitrateDownlinkExt := omit,
284 guaranteedBitRateDownlinkExt := omit,
285 maxBitrateUplinkExt := omit,
286 guaranteedBitRateUplinkExt := omit
287 }
288 }
289
290 template IMSI_gtpc ts_Imsi(hexstring digits) := {
291 type_gtpc := '02'O,
292 digits := digits,
293 padding := 'F'H
294 }
295
296 template GTPC_PDUs ts_CreatePdpPDU(hexstring imsi, OCT1 restart_ctr, OCT4 teid_data, OCT4 teid_ctrl,
297 BIT4 nsapi, EndUserAddress eua, octetstring apn,
298 octetstring sgsn_ip_sign, octetstring sgsn_ip_data,
Harald Welteed7a1772017-08-09 20:26:20 +0200299 octetstring msisdn, template ProtConfigOptions pco := omit) := {
Harald Welte94ade362017-08-04 00:36:55 +0200300 createPDPContextRequest := {
301 imsi := ts_Imsi(imsi),
302 rai := omit,
303 recovery := ts_Recovery(restart_ctr),
304 selectionMode := {
305 type_gtpc := '0F'O,
306 selectModeValue := '00'B,
307 spare := '111111'B
308 },
309 teidDataI := {
310 type_gtpc := '00'O,
311 teidDataI := teid_data
312 },
313 teidControlPlane := {
314 type_gtpc := '00'O,
315 teidControlPlane := teid_ctrl
316 },
317 nsapi := {
318 type_gtpc := '00'O,
319 nsapi := nsapi,
320 unused := '0000'B
321 },
322 linked_nsapi := omit,
323 charging_char := omit,
324 trace_ref := omit,
325 trace_type := omit,
326 endUserAddress := eua,
327 accessPointName := ts_APN(apn),
Harald Welteed7a1772017-08-09 20:26:20 +0200328 protConfigOptions := pco,
Harald Welte94ade362017-08-04 00:36:55 +0200329 sgsn_addr_signalling := ts_GsnAddr(sgsn_ip_sign),
330 sgsn_addr_traffic := ts_GsnAddr(sgsn_ip_data),
331 msisdn := ts_Msisdn(msisdn),
332 qualityOfServiceProfile := ts_QosDefault,
333 tft := omit,
334 triggerId := omit,
335 omcId := omit,
336 commonFlags := omit,
337 aPN_Restriction := omit,
338 ratType := omit,
339 userLocationInformation := omit,
340 mS_TimeZone := omit,
341 imeisv := omit,
342 camelChargingInformationContainer := omit,
343 additionalTraceInfo := omit,
344 correlationID := omit,
345 evolvedAllocationRetentionPriorityI := omit,
346 extendedCommonFlags := omit,
347 userCSGInformation := omit,
348 aPN_AMBR := omit,
349 signallingPriorityIndication := omit,
350 cN_OperatorSelectionEntity := omit,
351 private_extension_gtpc := omit
352 }
353 }
354
Harald Welte811651e2017-08-05 15:25:06 +0200355 template Gtp1cUnitdata ts_GTPC_CreatePDP(GtpPeer peer, uint16_t seq, hexstring imsi,
356 OCT1 restart_ctr, OCT4 teid_data,
Harald Welte94ade362017-08-04 00:36:55 +0200357 OCT4 teid_ctrl, BIT4 nsapi, EndUserAddress eua,
358 octetstring apn, octetstring sgsn_ip_sign,
Harald Welteed7a1772017-08-09 20:26:20 +0200359 octetstring sgsn_ip_data, octetstring msisdn,
360 template ProtConfigOptions pco := omit) := {
Harald Welte94ade362017-08-04 00:36:55 +0200361 peer := peer,
362 gtpc := ts_GTP1C_PDU(createPDPContextRequest, '00000000'O,
363 valueof(ts_CreatePdpPDU(imsi, restart_ctr, teid_data, teid_ctrl,
364 nsapi, eua, apn, sgsn_ip_sign,
Harald Welteed7a1772017-08-09 20:26:20 +0200365 sgsn_ip_data, msisdn, pco)), seq)
366 }
367
Harald Welte99ef9a42017-08-14 21:42:03 +0200368 /* PCO send base template */
Harald Welteed7a1772017-08-09 20:26:20 +0200369 template ProtConfigOptions ts_PCO := {
370 type_gtpc := '84'O,
371 lengthf := 0,
372 configProtocol := '000'B,
373 spare := '0000'B,
374 extension0 := '1'B,
375 protocols := {}
376 }
Harald Welte99ef9a42017-08-14 21:42:03 +0200377 /* PCO receive base template */
378 template ProtConfigOptions tr_PCO := {
379 type_gtpc := '84'O,
380 lengthf := ?,
381 configProtocol := '000'B,
382 spare := ?,
383 extension0 := '1'B,
384 protocols := {}
385 }
Harald Welteed7a1772017-08-09 20:26:20 +0200386
387 template ProtConfigOptions ts_PCO_IPv6_DNS modifies ts_PCO := {
388 protocols := {
389 { protocolID := '0003'O, lengthProtoID := 0, protoIDContents := ''O }
390 }
391 }
Harald Welte99ef9a42017-08-14 21:42:03 +0200392 template ProtConfigOptions tr_PCO_IPv6_DNS_resp(template OCT16 contents) modifies tr_PCO := {
393 protocols := {
Harald Welte3ab91d62017-08-25 14:46:39 +0200394 *, { protocolID := '0003'O, lengthProtoID := 16, protoIDContents := contents }, *
Harald Welte99ef9a42017-08-14 21:42:03 +0200395 }
396 }
Harald Welteed7a1772017-08-09 20:26:20 +0200397
398 template ProtConfigOptions ts_PCO_IPv4_DNS_IPCP modifies ts_PCO := {
399 protocols := {
Harald Welteab4ca942017-09-07 18:41:52 +0200400 /* dummy PAP entry to check if our parser in the GGSN can properly iterate over
401 * the list of protocols, see Change-Id Icc2e6716c33d78d3c3e000f529806228d8aa155e */
402 { protocolID := 'C023'O, lengthProtoID := 0, protoIDContents := ''O },
Harald Welteeb9184d2017-12-04 19:01:47 +0100403 { protocolID := '8021'O, lengthProtoID := 16, protoIDContents :=
404 enc_IpcpPacket(valueof(ts_IPCP_ReqDNS)) }
Harald Welteed7a1772017-08-09 20:26:20 +0200405 }
406 }
407
Harald Welte71a36022017-12-04 18:55:58 +0100408 template ProtocolElement tr_PCO_Proto(OCT2 prot_id) := {
409 protocolID := prot_id,
410 lengthProtoID := ?,
411 protoIDContents := ?
412 }
413 template ProtConfigOptions tr_PCO_Contains(OCT2 prot_id) modifies tr_PCO := {
414 protocols := { *, tr_PCO_Proto(prot_id), * }
415 }
416
Harald Welteed7a1772017-08-09 20:26:20 +0200417 template ProtConfigOptions ts_PCO_IPv4_DNS_CONT modifies ts_PCO := {
418 protocols := {
419 { protocolID := '000d'O, lengthProtoID := 0, protoIDContents := ''O }
420 }
Harald Welte94ade362017-08-04 00:36:55 +0200421 }
Harald Welte99ef9a42017-08-14 21:42:03 +0200422 template ProtConfigOptions tr_PCO_IPv4_DNS_CONT_resp(template OCT4 contents) modifies tr_PCO := {
423 protocols := {
Harald Welte3ab91d62017-08-25 14:46:39 +0200424 *, { protocolID := '000d'O, lengthProtoID := 4, protoIDContents := contents }, *
Harald Welte99ef9a42017-08-14 21:42:03 +0200425 }
426 }
427
Harald Welte71a36022017-12-04 18:55:58 +0100428 /* extract a given protocol payload from PCO */
429 function f_PCO_extract_proto(ProtConfigOptions pco, OCT2 protocol) return octetstring {
430 var integer i;
431 for (i := 0; i < lengthof(pco.protocols); i := i + 1) {
432 if (pco.protocols[i].protocolID == protocol) {
433 return pco.protocols[i].protoIDContents;
434 }
435 }
436 setverdict(fail);
437 return ''O;
438 }
439
440 template IpcpPacket tr_IPCP(template LcpCode code, template uint8_t identifier,
441 template IpcpOptionList opts) := {
442 code := code,
443 identifier := identifier,
444 len := ?,
445 options := opts
446 }
447 template IpcpOption tr_IPCP_PrimaryDns(template OCT4 addr) := {
448 code := IPCP_OPT_PrimaryDNS,
449 len := 6,
450 data := addr
451 }
452 template IpcpOption tr_IPCP_SecondaryDns(template OCT4 addr) := {
453 code := IPCP_OPT_SecondaryDNS,
454 len := 6,
455 data := addr
456 }
Harald Welte71a36022017-12-04 18:55:58 +0100457 template IpcpPacket tr_IPCP_Ack_DNS(template uint8_t identifier := ?, template OCT4 dns1 := ?,
458 template OCT4 dns2 := ?) :=
459 tr_IPCP(LCP_Configure_Ack, identifier,
460 { *, tr_IPCP_PrimaryDns(dns1), *, tr_IPCP_SecondaryDns(dns2), * });
461
Harald Welteeb9184d2017-12-04 19:01:47 +0100462 template IpcpPacket ts_IPCP(LcpCode code, uint8_t identifier, template IpcpOptionList opts) := {
463 code := code,
464 identifier := identifier,
465 len := 0, /* overwritten */
466 options := opts
467 }
468 template IpcpPacket ts_IPCP_ReqDNS(uint8_t identifier := 0) :=
469 ts_IPCP(LCP_Configure_Request, identifier,
470 { tr_IPCP_PrimaryDns('00000000'O), tr_IPCP_SecondaryDns('00000000'O) });
Harald Welte94ade362017-08-04 00:36:55 +0200471
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200472 function f_teardown_ind_IE(in template BIT1 ind) return template TearDownInd {
Harald Welte811651e2017-08-05 15:25:06 +0200473/*
474 if (not isvalue(ind)) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200475 return omit;
476 }
Harald Welte811651e2017-08-05 15:25:06 +0200477*/
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200478 var TearDownInd ret := {
479 type_gtpc := '13'O,
480 tdInd := valueof(ind),
481 spare:= '0000000'B
482 }
483 return ret;
484 }
485
486 template GTPC_PDUs ts_DeletePdpPDU(BIT4 nsapi, template BIT1 teardown_ind) := {
487 deletePDPContextRequest := {
488 cause := omit,
489 tearDownIndicator := f_teardown_ind_IE(teardown_ind),
490 nsapi := {
491 type_gtpc := '14'O,
492 nsapi := nsapi,
493 unused := '0000'B
494 },
495 protConfigOptions := omit,
496 userLocationInformation := omit,
497 mS_TimeZone := omit,
498 extendedCommonFlags := omit,
499 uLI_Timestamp := omit,
500 private_extension_gtpc := omit
501 }
502 }
503
Harald Welte811651e2017-08-05 15:25:06 +0200504 template Gtp1cUnitdata ts_GTPC_DeletePDP(GtpPeer peer, uint16_t seq, OCT4 teid,
505 BIT4 nsapi, template BIT1 teardown_ind) := {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200506 peer := peer,
507 gtpc := ts_GTP1C_PDU(deletePDPContextRequest, teid,
Harald Welte811651e2017-08-05 15:25:06 +0200508 valueof(ts_DeletePdpPDU(nsapi, teardown_ind)), seq)
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200509 }
510
511
Harald Welte3af89482017-08-04 16:20:23 +0200512 /* GTP-U */
513
Harald Welte231b9412017-08-09 17:16:31 +0200514 template PDU_GTPU tr_GTP1U_PDU(template OCT1 msg_type, template OCT4 teid, template GTPU_IEs ies := ?) := {
Harald Welte3af89482017-08-04 16:20:23 +0200515 pn_bit := ?,
516 s_bit := ?,
517 e_bit := ?,
518 spare := ?,
519 /* Protocol Type flag (PT) shall be set to '1' in GTP */
520 pt := '1'B,
521 /* Version shall be set to decimal 1 ('001'). */
522 version := '001'B,
523 messageType := msg_type,
524 lengthf := ?,
525 teid := teid,
526 opt_part := *,
Harald Welte231b9412017-08-09 17:16:31 +0200527 gtpu_IEs := ies
Harald Welte3af89482017-08-04 16:20:23 +0200528 }
529
530 /* generalized GTP-U send template */
Harald Welte811651e2017-08-05 15:25:06 +0200531 template PDU_GTPU ts_GTP1U_PDU(OCT1 msg_type, uint16_t seq, OCT4 teid, GTPU_IEs ies) := {
Harald Welte3af89482017-08-04 16:20:23 +0200532 /* N-PDU Number flag (PN): the GTP-U header contains a meaningful N-PDU Number field if the PN
533 * flag is set to 1. */
534 pn_bit := '0'B, /* we assume the encoder overwrites this if an optional part is given */
535 /* If the Sequence Number flag (S) is set to '1' the sequence number field is present and
536 * meaningful otherwise it is set to '0'. For GTP-U messages Echo Request, Echo Response,
537 * Error Indication and Supported Extension Headers Notification, the S flag shall be set to '1'. */
Harald Welte811651e2017-08-05 15:25:06 +0200538 s_bit := '1'B, /* we assume the encoder overwrites this if an optional part is given */
Harald Welte3af89482017-08-04 16:20:23 +0200539 /* Extension header presence */
540 e_bit := '0'B,
541 spare := '0'B,
542 /* Protocol Type flag (PT) shall be set to '1' in GTP */
543 pt := '1'B,
544 /* Version shall be set to decimal 1 ('001'). */
545 version := '001'B,
546 messageType := msg_type,
547 lengthf := 0, /* we assume encoder overwrites this */
548 teid := teid,
Harald Welte811651e2017-08-05 15:25:06 +0200549 opt_part := {
550 sequenceNumber := int2oct(seq, 2),
551 npduNumber := '00'O,
552 nextExtHeader := '00'O,
553 gTPU_extensionHeader_List := omit
554 },
Harald Welte3af89482017-08-04 16:20:23 +0200555 gtpu_IEs := ies
556 }
557
558 template Gtp1uUnitdata tr_GTPU_MsgType(template GtpPeer peer, template OCT1 msg_type, template OCT4 teid) := {
559 peer := peer,
560 gtpu := tr_GTP1U_PDU(msg_type, teid)
561 }
562
563
Harald Welte231b9412017-08-09 17:16:31 +0200564 /* template matching reception of GTP-U echo-request */
Harald Welte3af89482017-08-04 16:20:23 +0200565 template Gtp1uUnitdata tr_GTPU_PING(template GtpPeer peer) := tr_GTPU_MsgType(peer, echoRequest, '00000000'O);
566
Harald Welte231b9412017-08-09 17:16:31 +0200567 /* template matching reception of GTP-U GPDU */
568 template GTPU_IEs t_GPDU(template octetstring data) := {
569 g_PDU_IEs := {
570 data := data
571 }
572 }
573 template Gtp1uUnitdata tr_GTPU_GPDU(template GtpPeer peer, template OCT4 teid, template octetstring data := ?) := {
574 peer := peer,
575 gtpu := tr_GTP1U_PDU('FF'O, teid, t_GPDU(data))
576 }
577
Harald Welte3af89482017-08-04 16:20:23 +0200578 template GTPU_IEs ts_UEchoRespPDU(OCT1 restart_counter) := {
579 echoResponse_IEs := {
580 recovery_gtpu := {
581 type_gtpu := '00'O, /* we assume encoder fixes? */
582 restartCounter := restart_counter
583 },
584 private_extension_gtpu := omit
585 }
586 }
587
588 /* master template for sending a GTP-U echo response */
Harald Welte811651e2017-08-05 15:25:06 +0200589 template Gtp1uUnitdata ts_GTPU_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := {
Harald Welte3af89482017-08-04 16:20:23 +0200590 peer := peer,
Harald Welte811651e2017-08-05 15:25:06 +0200591 gtpu := ts_GTP1U_PDU(echoResponse, seq, '00000000'O, valueof(ts_UEchoRespPDU(rest_ctr)))
Harald Welte3af89482017-08-04 16:20:23 +0200592 }
593
Harald Welte811651e2017-08-05 15:25:06 +0200594 /* master template for sending a GTP-U user plane data */
595 template Gtp1uUnitdata ts_GTP1U_GPDU(GtpPeer peer, uint16_t seq, OCT4 teid, octetstring data) := {
596 peer := peer,
597 gtpu := ts_GTP1U_PDU('FF'O, seq, teid, { g_PDU_IEs := { data := data }})
598 }
Harald Welte3af89482017-08-04 16:20:23 +0200599
Harald Welte94ade362017-08-04 00:36:55 +0200600 /* Altstep implementing responses to any incoming echo requests */
601 altstep pingpong() runs on GT_CT {
602 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200603 var Gtp1uUnitdata udu;
Harald Welte94ade362017-08-04 00:36:55 +0200604 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200605 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
606 GTPC.send(ts_GTPC_PONG(ud.peer, seq, '00'O));
Harald Welte94ade362017-08-04 00:36:55 +0200607 repeat;
608 };
Harald Welte3af89482017-08-04 16:20:23 +0200609 [] GTPU.receive(tr_GTPU_PING(?)) -> value udu {
Harald Welte811651e2017-08-05 15:25:06 +0200610 var uint16_t seq := oct2int(udu.gtpu.opt_part.sequenceNumber);
611 GTPU.send(ts_GTPU_PONG(udu.peer, seq, '00'O));
Harald Welte3af89482017-08-04 16:20:23 +0200612 };
Harald Welte94ade362017-08-04 00:36:55 +0200613 [] T_default.timeout { setverdict(fail); };
614 }
615
Harald Welte811651e2017-08-05 15:25:06 +0200616 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200617 const octetstring c_ApnInternet := '08696E7465726E6574'O;
618 const octetstring c_ApnInet6 := '05696E657436'O;
619 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200620
Harald Welte811651e2017-08-05 15:25:06 +0200621 /* return random NSAPI */
622 function f_rnd_nsapi() return BIT4 {
623 return int2bit(f_rnd_int(16), 4);
624 }
625
626 /* return random TEI[DC] */
627 function f_rnd_tei() return OCT4 {
628 return int2oct(f_rnd_int(4294967296), 4);
629 }
630
631 /* define an (internal) representation of a PDP context */
632 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
633 EndUserAddress eua) := {
634 imsi := imsi,
635 msisdn := msisdn,
636 nsapi := f_rnd_nsapi(),
637 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200638 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200639 eua := eua,
640 teid := f_rnd_tei(),
Harald Welte5438b9d2017-08-13 13:27:48 +0200641 teic := f_rnd_tei()
Harald Welte811651e2017-08-05 15:25:06 +0200642 }
643
644 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200645 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200646 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200647 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200648 }
649
650 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200651 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte5438b9d2017-08-13 13:27:48 +0200652 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
653 g_d_seq_nr := g_d_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200654 }
655
656 /* send a PDP context activation */
657 function f_pdp_ctx_act(inout PdpContext ctx) runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200658 var Gtp1cUnitdata ud;
Harald Welte94ade362017-08-04 00:36:55 +0200659 var default d;
660
661 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200662 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 +0200663 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200664 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req));
Harald Welte94ade362017-08-04 00:36:55 +0200665 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200666 d := activate(pingpong());
667 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200668 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
669 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
670 if (cpr.cause.causevalue == '80'O) {
Harald Welte99ef9a42017-08-14 21:42:03 +0200671 /* Check if EUA type corresponds to requested type */
672 if (match(ctx.eua, t_EuaIPv4(?)) and
673 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
674 setverdict(fail);
675 }
676 if (match(ctx.eua, t_EuaIPv6(?)) and
677 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
678 setverdict(fail);
679 }
680 /* Check if PCO response corresponds to request */
681 if (ispresent(ctx.pco_req)) {
682 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
683 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
684 log("IPv4 DNS Container requested, but missing");
685 setverdict(fail);
686 }
687 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
688 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
689 log("IPv6 DNS Container requested, but missing");
690 setverdict(fail);
691 }
692 }
Harald Welte811651e2017-08-05 15:25:06 +0200693 ctx.teid_remote := cpr.teidDataI.teidDataI;
694 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
Harald Welte231b9412017-08-09 17:16:31 +0200695 ctx.eua := cpr.endUserAddress;
Harald Welteed7a1772017-08-09 20:26:20 +0200696 ctx.pco_neg := cpr.protConfigOptions;
Harald Welte94ade362017-08-04 00:36:55 +0200697 setverdict(pass);
698 } else {
699 setverdict(fail);
700 }
701 }
702 }
703 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200704 T_default.stop;
Harald Welte94ade362017-08-04 00:36:55 +0200705 }
706
Harald Welte811651e2017-08-05 15:25:06 +0200707 function f_pdp_ctx_del(PdpContext ctx, template BIT1 teardown_ind) runs on GT_CT {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200708 var Gtp1cUnitdata ud;
709 var default d;
710
Harald Welte41575e92017-08-13 13:49:57 +0200711 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 +0200712 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200713 d := activate(pingpong());
714 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200715 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ctx.teic)) -> value ud {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200716 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == '80'O) {
717 setverdict(pass);
718 } else {
719 setverdict(fail);
720 }
721 }
722 }
723 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200724 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200725 }
Harald Welte811651e2017-08-05 15:25:06 +0200726 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
727 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
728 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
729 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200730
Harald Welte231b9412017-08-09 17:16:31 +0200731 /* template to generate a 'Prefix Information' ICMPv6 option */
732 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
733 prefixInformation := {
734 typeField := 3,
735 lengthIndicator := 8,
736 prefixLength := prefix_len,
737 reserved1 := '000000'B,
738 a_Bit := '0'B,
739 l_Bit := '0'B,
740 validLifetime := oct2int('FFFFFFFF'O),
741 preferredLifetime := oct2int('FFFFFFFF'O),
742 reserved2 := '00000000'O,
743 prefix := prefix
744 }
745 }
746
747 /* template for an ICMPv6 router solicitation */
748 template PDU_ICMPv6 ts_ICMPv6_RS := {
749 routerSolicitation := {
750 typeField := 133,
751 code := 0,
752 checksum := '0000'O,
753 reserved := '00000000'O,
754 /* TODO: do we need 'Source link-layer address' ? */
755 options := omit
756 }
757 }
758
759 /* template for an ICMPv6 router advertisement */
760 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
761 routerAdvertisement := {
762 typeField := 134,
763 code := 0,
764 checksum := '0000'O,
765 curHopLimit := ?,
766 reserved := '000000'B,
767 o_Bit := '0'B,
768 m_Bit := '0'B,
769 routerLifetime := oct2int('FFFF'O),
770 reachableTime := oct2int('FFFFFFFF'O),
771 retransTimer := oct2int('FFFFFFFF'O),
772 options := {
773 ts_ICMP6_OptPrefix(prefix, prefix_len)
774 }
775 }
776 }
777
778 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
779 neighborSolicitation := {
780 typeField := 135,
781 code := 0,
782 checksum := '0000'O,
783 reserved := '00000000'O,
784 targetAddress := target_addr,
785 /* TODO: do we need 'Source link-layer address' ? */
786 options := omit
787 }
788 }
789
790 /* derive ICMPv6 link-local address from lower 64bit of link_id */
791 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
792 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
793 prefixInformation := {
794 typeField := 3,
795 lengthIndicator := 4,
796 prefixLength := prefix_len,
797 reserved1 := ?,
798 a_Bit := ?,
799 l_Bit := ?,
800 validLifetime := ?,
801 preferredLifetime := ?,
802 reserved2 := ?,
803 prefix := prefix
804 }
805 }
806
807 /* template for receiving/matching an ICMPv6 router advertisement */
808 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
809 routerAdvertisement := {
810 typeField := 134,
811 code := 0,
812 checksum := ?,
813 curHopLimit := ?,
814 reserved := ?,
815 o_Bit := '0'B,
816 m_Bit := '0'B,
817 routerLifetime := ?,
818 reachableTime := ?,
819 retransTimer := ?,
820 options := {
821 tr_ICMP6_OptPrefix(prefix, prefix_len)
822 }
823 }
824 }
825
826 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
827 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
828 header := {
829 ver := 6,
830 trclass := 0,
831 flabel := 0,
832 plen := 0,
833 nexthead := nexthead,
834 hlim := hlim,
835 srcaddr := srcaddr,
836 dstaddr := dstaddr
837 },
838 ext_headers := omit,
839 payload := payload
840 }
841
842 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
843 return 'FE80000000000000'O & substr(link_id, 8, 8);
844 }
845
846 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
847 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
848 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
849 }
850
851 /* generate and encode ICMPv6 router solicitation */
852 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
853 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
854 var OCT16 saddr := f_ipv6_link_local(link_id);
855
856 var octetstring tmp;
857 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
858 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
859
860 return f_IPv6_enc(ip6);
861 }
862
863 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
864 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
865 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
866 return f_gen_icmpv6_router_solicitation(interface_id);
867 }
868
869 /* generate and encode ICMPv6 neighbor solicitation */
870 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
871 var octetstring tmp;
872 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
873 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
874 return f_IPv6_enc(ip6);
875 }
876
877 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
878 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
879 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
880 var OCT16 link_local := f_ipv6_link_local(interface_id);
881 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
882
883 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
884 }
885
886 /* wait for GGSN to send us an ICMPv6 router advertisement */
887 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
888 var Gtp1uUnitdata ud;
889 T_default.start;
890 alt {
891 //'6???????????3aff'O
892 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
893 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
894 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
895 if (ip6.header.ver != 6 or ip6.header.nexthead != 58 or ip6.header.hlim != 255) {
896 repeat;
897 }
898 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
899 if (not match(icmp6, tr_ICMPv6_RA(?, 64))) {
900 repeat;
901 }
902 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
903 log("RA with /64 prefix ", ctx.ip6_prefix);
904 }
905 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
906 [] GTPU.receive { setverdict(fail); }
907 [] T_default.timeout { setverdict(fail); }
908 }
909 T_default.stop;
910 }
911
Harald Welte0ef285b2017-08-13 20:06:01 +0200912 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +0200913 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200914 f_init();
Harald Welte231b9412017-08-09 17:16:31 +0200915
Harald Welteed097432017-08-13 13:28:49 +0200916 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 +0200917 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +0200918 f_pdp_ctx_del(ctx, '1'B);
919 }
920
Harald Welte0ef285b2017-08-13 20:06:01 +0200921 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +0200922 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
923 f_init();
924
Harald Welteed097432017-08-13 13:28:49 +0200925 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 +0200926 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
927 f_pdp_ctx_act(ctx);
928 f_pdp_ctx_del(ctx, '1'B);
929 }
930
Harald Welte0ef285b2017-08-13 20:06:01 +0200931 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +0200932 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
933 f_init();
934
Harald Welteed097432017-08-13 13:28:49 +0200935 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 +0200936 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
937 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200938
939 //f_send_gtpu(ctx, c_router_solicit);
940 //f_send_gtpu(ctx, c_neigh_solicit);
941
942 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
943 f_wait_rtr_adv(ctx);
944 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
945
Harald Welte811651e2017-08-05 15:25:06 +0200946 f_pdp_ctx_del(ctx, '1'B);
Harald Welte94ade362017-08-04 00:36:55 +0200947 }
948
Harald Welte0ef285b2017-08-13 20:06:01 +0200949 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +0200950 testcase TC_pdp4_act_deact() runs on GT_CT {
951 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200952 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 +0200953 f_pdp_ctx_act(ctx);
954 f_pdp_ctx_del(ctx, '1'B);
955 }
956
Harald Welte0ef285b2017-08-13 20:06:01 +0200957 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +0200958 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
959 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100960 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
961 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +0200962 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 +0200963 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +0200964 f_pdp_ctx_act(ctx);
Harald Welte71a36022017-12-04 18:55:58 +0100965 /* verify IPCP is at all contained */
966 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
967 setverdict(fail, "IPCP not found in PCO");
968 }
969 /* verify IPCP contains both primary and secondary DNS */
970 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100971 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
972 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
973 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
974 } else {
975 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
976 }
Harald Welte71a36022017-12-04 18:55:58 +0100977 }
Harald Welteed7a1772017-08-09 20:26:20 +0200978 f_pdp_ctx_del(ctx, '1'B);
979 }
980
Harald Welte0ef285b2017-08-13 20:06:01 +0200981 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +0200982 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
983 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200984 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 +0200985 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +0200986 f_pdp_ctx_act(ctx);
987 f_pdp_ctx_del(ctx, '1'B);
988 }
989
Harald Weltedca80052017-08-13 20:01:38 +0200990 testcase TC_echo_req_resp() runs on GT_CT {
991 f_init();
992 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
993 T_default.start;
994 alt {
995 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
996 [] GTPC.receive { repeat; };
997 [] T_default.timeout { setverdict(fail); }
998 }
999 T_default.stop;
1000 }
1001
Harald Welte94ade362017-08-04 00:36:55 +02001002 control {
Harald Welteed7a1772017-08-09 20:26:20 +02001003 execute(TC_pdp4_act_deact());
1004 execute(TC_pdp4_act_deact_ipcp());
1005 execute(TC_pdp4_act_deact_pcodns());
1006
1007 execute(TC_pdp6_act_deact());
1008 execute(TC_pdp6_act_deact_pcodns());
1009 execute(TC_pdp6_act_deact_icmp6());
Harald Weltedca80052017-08-13 20:01:38 +02001010
1011 execute(TC_echo_req_resp());
Harald Welte94ade362017-08-04 00:36:55 +02001012 }
Harald Welte379d45a2017-08-03 09:55:15 +02001013}