blob: 23e7054526387bcbcd30aeeb7eae2b43cadf3a37 [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 Welteeb9184d2017-12-04 19:01:47 +0100400 { protocolID := '8021'O, lengthProtoID := 16, protoIDContents :=
401 enc_IpcpPacket(valueof(ts_IPCP_ReqDNS)) }
Harald Welteed7a1772017-08-09 20:26:20 +0200402 }
403 }
404
Harald Welte71a36022017-12-04 18:55:58 +0100405 template ProtocolElement tr_PCO_Proto(OCT2 prot_id) := {
406 protocolID := prot_id,
407 lengthProtoID := ?,
408 protoIDContents := ?
409 }
410 template ProtConfigOptions tr_PCO_Contains(OCT2 prot_id) modifies tr_PCO := {
411 protocols := { *, tr_PCO_Proto(prot_id), * }
412 }
413
Harald Welteed7a1772017-08-09 20:26:20 +0200414 template ProtConfigOptions ts_PCO_IPv4_DNS_CONT modifies ts_PCO := {
415 protocols := {
416 { protocolID := '000d'O, lengthProtoID := 0, protoIDContents := ''O }
417 }
Harald Welte94ade362017-08-04 00:36:55 +0200418 }
Harald Welte99ef9a42017-08-14 21:42:03 +0200419 template ProtConfigOptions tr_PCO_IPv4_DNS_CONT_resp(template OCT4 contents) modifies tr_PCO := {
420 protocols := {
Harald Welte3ab91d62017-08-25 14:46:39 +0200421 *, { protocolID := '000d'O, lengthProtoID := 4, protoIDContents := contents }, *
Harald Welte99ef9a42017-08-14 21:42:03 +0200422 }
423 }
424
Harald Welte71a36022017-12-04 18:55:58 +0100425 /* extract a given protocol payload from PCO */
426 function f_PCO_extract_proto(ProtConfigOptions pco, OCT2 protocol) return octetstring {
427 var integer i;
428 for (i := 0; i < lengthof(pco.protocols); i := i + 1) {
429 if (pco.protocols[i].protocolID == protocol) {
430 return pco.protocols[i].protoIDContents;
431 }
432 }
433 setverdict(fail);
434 return ''O;
435 }
436
437 template IpcpPacket tr_IPCP(template LcpCode code, template uint8_t identifier,
438 template IpcpOptionList opts) := {
439 code := code,
440 identifier := identifier,
441 len := ?,
442 options := opts
443 }
444 template IpcpOption tr_IPCP_PrimaryDns(template OCT4 addr) := {
445 code := IPCP_OPT_PrimaryDNS,
446 len := 6,
447 data := addr
448 }
449 template IpcpOption tr_IPCP_SecondaryDns(template OCT4 addr) := {
450 code := IPCP_OPT_SecondaryDNS,
451 len := 6,
452 data := addr
453 }
Harald Welte71a36022017-12-04 18:55:58 +0100454 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 Welteeb9184d2017-12-04 19:01:47 +0100459 template IpcpPacket ts_IPCP(LcpCode code, uint8_t identifier, template IpcpOptionList opts) := {
460 code := code,
461 identifier := identifier,
462 len := 0, /* overwritten */
463 options := opts
464 }
465 template IpcpPacket ts_IPCP_ReqDNS(uint8_t identifier := 0) :=
466 ts_IPCP(LCP_Configure_Request, identifier,
467 { tr_IPCP_PrimaryDns('00000000'O), tr_IPCP_SecondaryDns('00000000'O) });
Harald Welte94ade362017-08-04 00:36:55 +0200468
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200469 function f_teardown_ind_IE(in template BIT1 ind) return template TearDownInd {
Harald Welte811651e2017-08-05 15:25:06 +0200470/*
471 if (not isvalue(ind)) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200472 return omit;
473 }
Harald Welte811651e2017-08-05 15:25:06 +0200474*/
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200475 var TearDownInd ret := {
476 type_gtpc := '13'O,
477 tdInd := valueof(ind),
478 spare:= '0000000'B
479 }
480 return ret;
481 }
482
483 template GTPC_PDUs ts_DeletePdpPDU(BIT4 nsapi, template BIT1 teardown_ind) := {
484 deletePDPContextRequest := {
485 cause := omit,
486 tearDownIndicator := f_teardown_ind_IE(teardown_ind),
487 nsapi := {
488 type_gtpc := '14'O,
489 nsapi := nsapi,
490 unused := '0000'B
491 },
492 protConfigOptions := omit,
493 userLocationInformation := omit,
494 mS_TimeZone := omit,
495 extendedCommonFlags := omit,
496 uLI_Timestamp := omit,
497 private_extension_gtpc := omit
498 }
499 }
500
Harald Welte811651e2017-08-05 15:25:06 +0200501 template Gtp1cUnitdata ts_GTPC_DeletePDP(GtpPeer peer, uint16_t seq, OCT4 teid,
502 BIT4 nsapi, template BIT1 teardown_ind) := {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200503 peer := peer,
504 gtpc := ts_GTP1C_PDU(deletePDPContextRequest, teid,
Harald Welte811651e2017-08-05 15:25:06 +0200505 valueof(ts_DeletePdpPDU(nsapi, teardown_ind)), seq)
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200506 }
507
508
Harald Welte3af89482017-08-04 16:20:23 +0200509 /* GTP-U */
510
Harald Welte231b9412017-08-09 17:16:31 +0200511 template PDU_GTPU tr_GTP1U_PDU(template OCT1 msg_type, template OCT4 teid, template GTPU_IEs ies := ?) := {
Harald Welte3af89482017-08-04 16:20:23 +0200512 pn_bit := ?,
513 s_bit := ?,
514 e_bit := ?,
515 spare := ?,
516 /* Protocol Type flag (PT) shall be set to '1' in GTP */
517 pt := '1'B,
518 /* Version shall be set to decimal 1 ('001'). */
519 version := '001'B,
520 messageType := msg_type,
521 lengthf := ?,
522 teid := teid,
523 opt_part := *,
Harald Welte231b9412017-08-09 17:16:31 +0200524 gtpu_IEs := ies
Harald Welte3af89482017-08-04 16:20:23 +0200525 }
526
527 /* generalized GTP-U send template */
Harald Welte811651e2017-08-05 15:25:06 +0200528 template PDU_GTPU ts_GTP1U_PDU(OCT1 msg_type, uint16_t seq, OCT4 teid, GTPU_IEs ies) := {
Harald Welte3af89482017-08-04 16:20:23 +0200529 /* N-PDU Number flag (PN): the GTP-U header contains a meaningful N-PDU Number field if the PN
530 * flag is set to 1. */
531 pn_bit := '0'B, /* we assume the encoder overwrites this if an optional part is given */
532 /* If the Sequence Number flag (S) is set to '1' the sequence number field is present and
533 * meaningful otherwise it is set to '0'. For GTP-U messages Echo Request, Echo Response,
534 * Error Indication and Supported Extension Headers Notification, the S flag shall be set to '1'. */
Harald Welte811651e2017-08-05 15:25:06 +0200535 s_bit := '1'B, /* we assume the encoder overwrites this if an optional part is given */
Harald Welte3af89482017-08-04 16:20:23 +0200536 /* Extension header presence */
537 e_bit := '0'B,
538 spare := '0'B,
539 /* Protocol Type flag (PT) shall be set to '1' in GTP */
540 pt := '1'B,
541 /* Version shall be set to decimal 1 ('001'). */
542 version := '001'B,
543 messageType := msg_type,
544 lengthf := 0, /* we assume encoder overwrites this */
545 teid := teid,
Harald Welte811651e2017-08-05 15:25:06 +0200546 opt_part := {
547 sequenceNumber := int2oct(seq, 2),
548 npduNumber := '00'O,
549 nextExtHeader := '00'O,
550 gTPU_extensionHeader_List := omit
551 },
Harald Welte3af89482017-08-04 16:20:23 +0200552 gtpu_IEs := ies
553 }
554
555 template Gtp1uUnitdata tr_GTPU_MsgType(template GtpPeer peer, template OCT1 msg_type, template OCT4 teid) := {
556 peer := peer,
557 gtpu := tr_GTP1U_PDU(msg_type, teid)
558 }
559
560
Harald Welte231b9412017-08-09 17:16:31 +0200561 /* template matching reception of GTP-U echo-request */
Harald Welte3af89482017-08-04 16:20:23 +0200562 template Gtp1uUnitdata tr_GTPU_PING(template GtpPeer peer) := tr_GTPU_MsgType(peer, echoRequest, '00000000'O);
563
Harald Welte231b9412017-08-09 17:16:31 +0200564 /* template matching reception of GTP-U GPDU */
565 template GTPU_IEs t_GPDU(template octetstring data) := {
566 g_PDU_IEs := {
567 data := data
568 }
569 }
570 template Gtp1uUnitdata tr_GTPU_GPDU(template GtpPeer peer, template OCT4 teid, template octetstring data := ?) := {
571 peer := peer,
572 gtpu := tr_GTP1U_PDU('FF'O, teid, t_GPDU(data))
573 }
574
Harald Welte3af89482017-08-04 16:20:23 +0200575 template GTPU_IEs ts_UEchoRespPDU(OCT1 restart_counter) := {
576 echoResponse_IEs := {
577 recovery_gtpu := {
578 type_gtpu := '00'O, /* we assume encoder fixes? */
579 restartCounter := restart_counter
580 },
581 private_extension_gtpu := omit
582 }
583 }
584
585 /* master template for sending a GTP-U echo response */
Harald Welte811651e2017-08-05 15:25:06 +0200586 template Gtp1uUnitdata ts_GTPU_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := {
Harald Welte3af89482017-08-04 16:20:23 +0200587 peer := peer,
Harald Welte811651e2017-08-05 15:25:06 +0200588 gtpu := ts_GTP1U_PDU(echoResponse, seq, '00000000'O, valueof(ts_UEchoRespPDU(rest_ctr)))
Harald Welte3af89482017-08-04 16:20:23 +0200589 }
590
Harald Welte811651e2017-08-05 15:25:06 +0200591 /* master template for sending a GTP-U user plane data */
592 template Gtp1uUnitdata ts_GTP1U_GPDU(GtpPeer peer, uint16_t seq, OCT4 teid, octetstring data) := {
593 peer := peer,
594 gtpu := ts_GTP1U_PDU('FF'O, seq, teid, { g_PDU_IEs := { data := data }})
595 }
Harald Welte3af89482017-08-04 16:20:23 +0200596
Harald Welte94ade362017-08-04 00:36:55 +0200597 /* Altstep implementing responses to any incoming echo requests */
598 altstep pingpong() runs on GT_CT {
599 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200600 var Gtp1uUnitdata udu;
Harald Welte94ade362017-08-04 00:36:55 +0200601 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200602 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
603 GTPC.send(ts_GTPC_PONG(ud.peer, seq, '00'O));
Harald Welte94ade362017-08-04 00:36:55 +0200604 repeat;
605 };
Harald Welte3af89482017-08-04 16:20:23 +0200606 [] GTPU.receive(tr_GTPU_PING(?)) -> value udu {
Harald Welte811651e2017-08-05 15:25:06 +0200607 var uint16_t seq := oct2int(udu.gtpu.opt_part.sequenceNumber);
608 GTPU.send(ts_GTPU_PONG(udu.peer, seq, '00'O));
Harald Welte3af89482017-08-04 16:20:23 +0200609 };
Harald Welte94ade362017-08-04 00:36:55 +0200610 [] T_default.timeout { setverdict(fail); };
611 }
612
Harald Welte811651e2017-08-05 15:25:06 +0200613 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200614 const octetstring c_ApnInternet := '08696E7465726E6574'O;
615 const octetstring c_ApnInet6 := '05696E657436'O;
616 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200617
Harald Welte811651e2017-08-05 15:25:06 +0200618 /* return random NSAPI */
619 function f_rnd_nsapi() return BIT4 {
620 return int2bit(f_rnd_int(16), 4);
621 }
622
623 /* return random TEI[DC] */
624 function f_rnd_tei() return OCT4 {
625 return int2oct(f_rnd_int(4294967296), 4);
626 }
627
628 /* define an (internal) representation of a PDP context */
629 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
630 EndUserAddress eua) := {
631 imsi := imsi,
632 msisdn := msisdn,
633 nsapi := f_rnd_nsapi(),
634 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200635 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200636 eua := eua,
637 teid := f_rnd_tei(),
Harald Welte5438b9d2017-08-13 13:27:48 +0200638 teic := f_rnd_tei()
Harald Welte811651e2017-08-05 15:25:06 +0200639 }
640
641 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200642 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200643 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200644 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200645 }
646
647 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200648 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte5438b9d2017-08-13 13:27:48 +0200649 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
650 g_d_seq_nr := g_d_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200651 }
652
653 /* send a PDP context activation */
654 function f_pdp_ctx_act(inout PdpContext ctx) runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200655 var Gtp1cUnitdata ud;
Harald Welte94ade362017-08-04 00:36:55 +0200656 var default d;
657
658 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200659 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 +0200660 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200661 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req));
Harald Welte94ade362017-08-04 00:36:55 +0200662 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200663 d := activate(pingpong());
664 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200665 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
666 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
667 if (cpr.cause.causevalue == '80'O) {
Harald Welte99ef9a42017-08-14 21:42:03 +0200668 /* Check if EUA type corresponds to requested type */
669 if (match(ctx.eua, t_EuaIPv4(?)) and
670 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
671 setverdict(fail);
672 }
673 if (match(ctx.eua, t_EuaIPv6(?)) and
674 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
675 setverdict(fail);
676 }
677 /* Check if PCO response corresponds to request */
678 if (ispresent(ctx.pco_req)) {
679 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
680 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
681 log("IPv4 DNS Container requested, but missing");
682 setverdict(fail);
683 }
684 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
685 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
686 log("IPv6 DNS Container requested, but missing");
687 setverdict(fail);
688 }
689 }
Harald Welte811651e2017-08-05 15:25:06 +0200690 ctx.teid_remote := cpr.teidDataI.teidDataI;
691 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
Harald Welte231b9412017-08-09 17:16:31 +0200692 ctx.eua := cpr.endUserAddress;
Harald Welteed7a1772017-08-09 20:26:20 +0200693 ctx.pco_neg := cpr.protConfigOptions;
Harald Welte94ade362017-08-04 00:36:55 +0200694 setverdict(pass);
695 } else {
696 setverdict(fail);
697 }
698 }
699 }
700 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200701 T_default.stop;
Harald Welte94ade362017-08-04 00:36:55 +0200702 }
703
Harald Welte811651e2017-08-05 15:25:06 +0200704 function f_pdp_ctx_del(PdpContext ctx, template BIT1 teardown_ind) runs on GT_CT {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200705 var Gtp1cUnitdata ud;
706 var default d;
707
Harald Welte41575e92017-08-13 13:49:57 +0200708 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 +0200709 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200710 d := activate(pingpong());
711 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200712 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ctx.teic)) -> value ud {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200713 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == '80'O) {
714 setverdict(pass);
715 } else {
716 setverdict(fail);
717 }
718 }
719 }
720 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200721 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200722 }
Harald Welte811651e2017-08-05 15:25:06 +0200723 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
724 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
725 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
726 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200727
Harald Welte231b9412017-08-09 17:16:31 +0200728 /* template to generate a 'Prefix Information' ICMPv6 option */
729 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
730 prefixInformation := {
731 typeField := 3,
732 lengthIndicator := 8,
733 prefixLength := prefix_len,
734 reserved1 := '000000'B,
735 a_Bit := '0'B,
736 l_Bit := '0'B,
737 validLifetime := oct2int('FFFFFFFF'O),
738 preferredLifetime := oct2int('FFFFFFFF'O),
739 reserved2 := '00000000'O,
740 prefix := prefix
741 }
742 }
743
744 /* template for an ICMPv6 router solicitation */
745 template PDU_ICMPv6 ts_ICMPv6_RS := {
746 routerSolicitation := {
747 typeField := 133,
748 code := 0,
749 checksum := '0000'O,
750 reserved := '00000000'O,
751 /* TODO: do we need 'Source link-layer address' ? */
752 options := omit
753 }
754 }
755
756 /* template for an ICMPv6 router advertisement */
757 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
758 routerAdvertisement := {
759 typeField := 134,
760 code := 0,
761 checksum := '0000'O,
762 curHopLimit := ?,
763 reserved := '000000'B,
764 o_Bit := '0'B,
765 m_Bit := '0'B,
766 routerLifetime := oct2int('FFFF'O),
767 reachableTime := oct2int('FFFFFFFF'O),
768 retransTimer := oct2int('FFFFFFFF'O),
769 options := {
770 ts_ICMP6_OptPrefix(prefix, prefix_len)
771 }
772 }
773 }
774
775 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
776 neighborSolicitation := {
777 typeField := 135,
778 code := 0,
779 checksum := '0000'O,
780 reserved := '00000000'O,
781 targetAddress := target_addr,
782 /* TODO: do we need 'Source link-layer address' ? */
783 options := omit
784 }
785 }
786
787 /* derive ICMPv6 link-local address from lower 64bit of link_id */
788 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
789 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
790 prefixInformation := {
791 typeField := 3,
792 lengthIndicator := 4,
793 prefixLength := prefix_len,
794 reserved1 := ?,
795 a_Bit := ?,
796 l_Bit := ?,
797 validLifetime := ?,
798 preferredLifetime := ?,
799 reserved2 := ?,
800 prefix := prefix
801 }
802 }
803
804 /* template for receiving/matching an ICMPv6 router advertisement */
805 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
806 routerAdvertisement := {
807 typeField := 134,
808 code := 0,
809 checksum := ?,
810 curHopLimit := ?,
811 reserved := ?,
812 o_Bit := '0'B,
813 m_Bit := '0'B,
814 routerLifetime := ?,
815 reachableTime := ?,
816 retransTimer := ?,
817 options := {
818 tr_ICMP6_OptPrefix(prefix, prefix_len)
819 }
820 }
821 }
822
823 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
824 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
825 header := {
826 ver := 6,
827 trclass := 0,
828 flabel := 0,
829 plen := 0,
830 nexthead := nexthead,
831 hlim := hlim,
832 srcaddr := srcaddr,
833 dstaddr := dstaddr
834 },
835 ext_headers := omit,
836 payload := payload
837 }
838
839 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
840 return 'FE80000000000000'O & substr(link_id, 8, 8);
841 }
842
843 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
844 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
845 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
846 }
847
848 /* generate and encode ICMPv6 router solicitation */
849 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
850 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
851 var OCT16 saddr := f_ipv6_link_local(link_id);
852
853 var octetstring tmp;
854 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
855 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
856
857 return f_IPv6_enc(ip6);
858 }
859
860 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
861 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
862 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
863 return f_gen_icmpv6_router_solicitation(interface_id);
864 }
865
866 /* generate and encode ICMPv6 neighbor solicitation */
867 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
868 var octetstring tmp;
869 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
870 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
871 return f_IPv6_enc(ip6);
872 }
873
874 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
875 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
876 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
877 var OCT16 link_local := f_ipv6_link_local(interface_id);
878 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
879
880 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
881 }
882
883 /* wait for GGSN to send us an ICMPv6 router advertisement */
884 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
885 var Gtp1uUnitdata ud;
886 T_default.start;
887 alt {
888 //'6???????????3aff'O
889 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
890 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
891 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
892 if (ip6.header.ver != 6 or ip6.header.nexthead != 58 or ip6.header.hlim != 255) {
893 repeat;
894 }
895 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
896 if (not match(icmp6, tr_ICMPv6_RA(?, 64))) {
897 repeat;
898 }
899 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
900 log("RA with /64 prefix ", ctx.ip6_prefix);
901 }
902 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
903 [] GTPU.receive { setverdict(fail); }
904 [] T_default.timeout { setverdict(fail); }
905 }
906 T_default.stop;
907 }
908
Harald Welte0ef285b2017-08-13 20:06:01 +0200909 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +0200910 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200911 f_init();
Harald Welte231b9412017-08-09 17:16:31 +0200912
Harald Welteed097432017-08-13 13:28:49 +0200913 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 +0200914 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +0200915 f_pdp_ctx_del(ctx, '1'B);
916 }
917
Harald Welte0ef285b2017-08-13 20:06:01 +0200918 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +0200919 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
920 f_init();
921
Harald Welteed097432017-08-13 13:28:49 +0200922 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 +0200923 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
924 f_pdp_ctx_act(ctx);
925 f_pdp_ctx_del(ctx, '1'B);
926 }
927
Harald Welte0ef285b2017-08-13 20:06:01 +0200928 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +0200929 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
930 f_init();
931
Harald Welteed097432017-08-13 13:28:49 +0200932 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 +0200933 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
934 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200935
936 //f_send_gtpu(ctx, c_router_solicit);
937 //f_send_gtpu(ctx, c_neigh_solicit);
938
939 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
940 f_wait_rtr_adv(ctx);
941 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
942
Harald Welte811651e2017-08-05 15:25:06 +0200943 f_pdp_ctx_del(ctx, '1'B);
Harald Welte94ade362017-08-04 00:36:55 +0200944 }
945
Harald Welte0ef285b2017-08-13 20:06:01 +0200946 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +0200947 testcase TC_pdp4_act_deact() runs on GT_CT {
948 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200949 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 +0200950 f_pdp_ctx_act(ctx);
951 f_pdp_ctx_del(ctx, '1'B);
952 }
953
Harald Welte0ef285b2017-08-13 20:06:01 +0200954 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +0200955 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
956 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200957 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 +0200958 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +0200959 f_pdp_ctx_act(ctx);
Harald Welte71a36022017-12-04 18:55:58 +0100960 /* verify IPCP is at all contained */
961 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
962 setverdict(fail, "IPCP not found in PCO");
963 }
964 /* verify IPCP contains both primary and secondary DNS */
965 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Harald Weltee7096c12017-12-04 19:40:44 +0100966 if (not match(ipcp, tr_IPCP_Ack_DNS(0, 'C0A86401'O, '08080808'O))) {
Harald Welte71a36022017-12-04 18:55:58 +0100967 setverdict(fail, "Primary/Secondary DNS not found in IPCP");
968 }
Harald Welteed7a1772017-08-09 20:26:20 +0200969 f_pdp_ctx_del(ctx, '1'B);
970 }
971
Harald Welte0ef285b2017-08-13 20:06:01 +0200972 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +0200973 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
974 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200975 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 +0200976 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +0200977 f_pdp_ctx_act(ctx);
978 f_pdp_ctx_del(ctx, '1'B);
979 }
980
Harald Weltedca80052017-08-13 20:01:38 +0200981 testcase TC_echo_req_resp() runs on GT_CT {
982 f_init();
983 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
984 T_default.start;
985 alt {
986 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
987 [] GTPC.receive { repeat; };
988 [] T_default.timeout { setverdict(fail); }
989 }
990 T_default.stop;
991 }
992
Harald Welte94ade362017-08-04 00:36:55 +0200993 control {
Harald Welteed7a1772017-08-09 20:26:20 +0200994 execute(TC_pdp4_act_deact());
995 execute(TC_pdp4_act_deact_ipcp());
996 execute(TC_pdp4_act_deact_pcodns());
997
998 execute(TC_pdp6_act_deact());
999 execute(TC_pdp6_act_deact_pcodns());
1000 execute(TC_pdp6_act_deact_icmp6());
Harald Weltedca80052017-08-13 20:01:38 +02001001
1002 execute(TC_echo_req_resp());
Harald Welte94ade362017-08-04 00:36:55 +02001003 }
Harald Welte379d45a2017-08-03 09:55:15 +02001004}