blob: f7814db70d1d2a39cef48e4da388a34afb52dba2 [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"
Pau Espin Pedrol363ba482018-01-29 18:42:00 +010029 charstring m_ggsn_ip6_dns1 := "2001:4860:4860::8888"
30 charstring m_ggsn_ip6_dns2 := "2001:4860:4860::8844"
Harald Welteddeecbb2017-08-18 22:53:30 +020031 }
Harald Welte94ade362017-08-04 00:36:55 +020032
Harald Welte811651e2017-08-05 15:25:06 +020033 type set PdpContext {
34 hexstring imsi,
35 octetstring msisdn optional,
36 octetstring apn,
Harald Welteed7a1772017-08-09 20:26:20 +020037 ProtConfigOptions pco_req optional,
38 ProtConfigOptions pco_neg optional,
Harald Welte811651e2017-08-05 15:25:06 +020039 EndUserAddress eua,
Harald Welte231b9412017-08-09 17:16:31 +020040 OCT16 ip6_prefix optional,
Harald Welte811651e2017-08-05 15:25:06 +020041 BIT4 nsapi,
42 /* TEI (Data) local side */
43 OCT4 teid,
44 /* TEI (Control) local side */
45 OCT4 teic,
46 /* TEI (Data) remote side */
47 OCT4 teid_remote,
48 /* TEI (Control) remote side */
Harald Welte5438b9d2017-08-13 13:27:48 +020049 OCT4 teic_remote
Harald Welte811651e2017-08-05 15:25:06 +020050 }
51
Harald Welte94ade362017-08-04 00:36:55 +020052 type component GT_CT {
53 port GTPC_PT GTPC;
54 port GTPU_PT GTPU;
55
Harald Welte0be142b2017-08-13 13:28:10 +020056 var boolean g_initialized := false;
57
Harald Welte94ade362017-08-04 00:36:55 +020058 var OCT1 g_restart_ctr := '01'O;
59 /* FIXME: unify with g_bind_ip + parse from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +020060 var OCT4 g_sgsn_ip_c;
61 var OCT4 g_sgsn_ip_u;
Harald Welte94ade362017-08-04 00:36:55 +020062 /* FIXME: parse remName from config file */
Harald Welteddeecbb2017-08-18 22:53:30 +020063 var GtpPeer g_peer_c := { connId := 0, remName := m_ggsn_ip_gtpc, remPort := GTP1C_PORT };
64 var GtpPeer g_peer_u := { connId := 0, remName := m_ggsn_ip_gtpu, remPort := GTP1U_PORT };
Harald Welte94ade362017-08-04 00:36:55 +020065 timer T_default := 3.0;
Harald Welte5438b9d2017-08-13 13:27:48 +020066
67 /* next to-be-sent GTP-C sequence number */
68 var uint16_t g_c_seq_nr;
69 /* next to-be-sent GTP-U sequence number */
70 var uint16_t g_d_seq_nr;
Harald Welte94ade362017-08-04 00:36:55 +020071 }
72
73 function f_init() runs on GT_CT {
Harald Welte0be142b2017-08-13 13:28:10 +020074 if (g_initialized == true) {
75 return;
76 }
77 g_initialized := true;
78
Harald Welteddeecbb2017-08-18 22:53:30 +020079 g_sgsn_ip_c := f_inet_addr(m_bind_ip_gtpc);
80 g_sgsn_ip_u := f_inet_addr(m_bind_ip_gtpu);
81
Harald Welte94ade362017-08-04 00:36:55 +020082 var Result res;
83 map(self:GTPC, system:GTPC);
Harald Welteddeecbb2017-08-18 22:53:30 +020084 res := GTP_CodecPort_CtrlFunct.f_IPL4_listen(GTPC, m_bind_ip_gtpc, GTP1C_PORT, {udp:={}});
Harald Welte94ade362017-08-04 00:36:55 +020085 log("GTP1C ConnectionID: ", res.connId);
Harald Welte811651e2017-08-05 15:25:06 +020086 g_peer_c.connId := res.connId;
Harald Welte94ade362017-08-04 00:36:55 +020087
88 map(self:GTPU, system:GTPU);
Harald Welteddeecbb2017-08-18 22:53:30 +020089 res := GTP_CodecPort_CtrlFunct.f_GTPU_listen(GTPU, m_bind_ip_gtpu, GTP1U_PORT, {udp:={}});
Harald Welte811651e2017-08-05 15:25:06 +020090 g_peer_u.connId:= res.connId;
Harald Welte5438b9d2017-08-13 13:27:48 +020091
92 g_restart_ctr := f_rnd_octstring(1);
Harald Welte11dbc7b2017-08-13 18:57:56 +020093 g_c_seq_nr := f_rnd_int(65535);
94 g_d_seq_nr := f_rnd_int(65535);
Harald Welte94ade362017-08-04 00:36:55 +020095 }
96
97 /* generalized GTP-C receive template */
Harald Weltedca80052017-08-13 20:01:38 +020098 template PDU_GTPC tr_GTP1C_PDU(template OCT1 msg_type, template OCT4 teid, template GTPC_PDUs pdu := ?) := {
Harald Welte94ade362017-08-04 00:36:55 +020099 /* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an
100 * error if this flag is set to '1'. */
101 pn_bit := '0'B,
102 /* Sequence number flag (S) shall be set to '1'. */
103 s_bit := '1'B,
104 e_bit := ?,
105 spare := ?,
106 /* Protocol Type flag (PT) shall be set to '1'.*/
107 pt := '1'B,
108 /* Version shall be set to decimal 1 ('001'). */
109 version := '001'B,
110 messageType := msg_type,
111 lengthf := ?,
112 teid := teid,
113 opt_part := *,
Harald Weltedca80052017-08-13 20:01:38 +0200114 gtpc_pdu := pdu
Harald Welte94ade362017-08-04 00:36:55 +0200115 }
116
117 /* generalized GTP-C send template */
Harald Welte811651e2017-08-05 15:25:06 +0200118 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 +0200119 /* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an
120 * error if this flag is set to '1'. */
121 pn_bit := '0'B,
122 /* Sequence number flag (S) shall be set to '1'. */
123 s_bit := '1'B,
124 e_bit := '0'B,
125 spare := '0'B,
126 /* Protocol Type flag (PT) shall be set to '1'.*/
127 pt := '1'B,
128 /* Version shall be set to decimal 1 ('001'). */
129 version := '001'B,
130 messageType := msg_type,
131 lengthf := 0, /* we assume encoder overwrites this */
132 teid := teid,
133 opt_part := {
Harald Welte811651e2017-08-05 15:25:06 +0200134 sequenceNumber := int2oct(seq_nr, 2),
Harald Welte94ade362017-08-04 00:36:55 +0200135 npduNumber := '00'O,
136 nextExtHeader := '00'O,
137 gTPC_extensionHeader_List := omit
138 },
139 gtpc_pdu := pdu
140 }
141
142 /* recovery IE */
143 template Recovery_gtpc ts_Recovery(OCT1 restart_counter) := {
Harald Weltedca80052017-08-13 20:01:38 +0200144 type_gtpc := '0E'O,
145 restartCounter := restart_counter
146 }
147
148 template Recovery_gtpc tr_Recovery(template OCT1 restart_counter) := {
149 type_gtpc := '0E'O,
Harald Welte94ade362017-08-04 00:36:55 +0200150 restartCounter := restart_counter
151 }
152
153 /* template matching reception of GTP-C echo-request */
Harald Weltedca80052017-08-13 20:01:38 +0200154 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 +0200155 peer := peer,
Harald Weltedca80052017-08-13 20:01:38 +0200156 gtpc := tr_GTP1C_PDU(msg_type, teid, pdus)
Harald Welte94ade362017-08-04 00:36:55 +0200157 }
158
159 /* template matching reception of GTP-C echo-request */
160 template Gtp1cUnitdata tr_GTPC_PING(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoRequest, '00000000'O);
161
Harald Weltedca80052017-08-13 20:01:38 +0200162 template GTPC_PDUs tr_EchoRespPDU(template OCT1 restart_counter) := {
163 echoResponse := {
164 recovery := tr_Recovery(restart_counter),
165 private_extension_gtpc := *
166 }
167 }
168
169 /* template matching reception of GTP-C echo-response */
170 template Gtp1cUnitdata tr_GTPC_PONG(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoResponse, '00000000'O, tr_EchoRespPDU(?));
171
Harald Welte94ade362017-08-04 00:36:55 +0200172 template GTPC_PDUs ts_EchoRespPDU(OCT1 restart_counter) := {
173 echoResponse := {
Harald Weltedca80052017-08-13 20:01:38 +0200174 recovery := ts_Recovery(restart_counter),
Harald Welte94ade362017-08-04 00:36:55 +0200175 private_extension_gtpc := omit
176 }
177 }
178
179 /* master template for senidng a GTP-C echo response */
Harald Welte811651e2017-08-05 15:25:06 +0200180 template Gtp1cUnitdata ts_GTPC_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := {
Harald Welte94ade362017-08-04 00:36:55 +0200181 peer := peer,
Harald Welte811651e2017-08-05 15:25:06 +0200182 gtpc := ts_GTP1C_PDU(echoResponse, '00000000'O, valueof(ts_EchoRespPDU(rest_ctr)), seq)
Harald Welte94ade362017-08-04 00:36:55 +0200183 }
184
Harald Weltedca80052017-08-13 20:01:38 +0200185 template GTPC_PDUs ts_EchoReqPDU := {
186 echoRequest := {
187 private_extension_gtpc := omit
188 }
189 }
190
191 /* master template for sending a GTP-C echo request */
192 template Gtp1cUnitdata ts_GTPC_PING(GtpPeer peer, uint16_t seq) := {
193 peer := peer,
194 gtpc := ts_GTP1C_PDU(echoRequest, '00000000'O, valueof(ts_EchoReqPDU), seq)
195 }
196
Harald Welte94ade362017-08-04 00:36:55 +0200197 template EndUserAddress t_EuaIPv4(template OCT4 ip_addr) := {
198 type_gtpc := '80'O,
199 endUserAddress := {
200 endUserAddressIPv4 := {
201 lengthf := 2,
202 pdp_typeorg := '0001'B,
203 spare := '1111'B,
204 pdp_typenum := '21'O,
205 ipv4_address := ip_addr
206 }
207 }
208 }
209 template EndUserAddress t_EuaIPv4Dyn := t_EuaIPv4(omit);
Harald Welte99ef9a42017-08-14 21:42:03 +0200210 template EndUserAddress tr_EuaIPv4(template OCT4 ip_addr) modifies t_EuaIPv4 := {
211 endUserAddress := {
212 endUserAddressIPv4 := {
Harald Weltebb5a19e2017-09-21 22:50:41 +0800213 lengthf := 2+lengthof(ip_addr)
Harald Welte99ef9a42017-08-14 21:42:03 +0200214 }
215 }
216 }
217
Harald Welte94ade362017-08-04 00:36:55 +0200218 template EndUserAddress t_EuaIPv6(template OCT16 ip_addr) := {
219 type_gtpc := '80'O,
220 endUserAddress := {
221 endUserAddressIPv6 := {
222 lengthf := 2,
223 pdp_typeorg := '0001'B,
224 spare := '1111'B,
225 pdp_typenum := '57'O,
226 ipv6_address := ip_addr
227 }
228 }
229 }
230 template EndUserAddress t_EuaIPv6Dyn := t_EuaIPv6(omit);
Harald Welte99ef9a42017-08-14 21:42:03 +0200231 template EndUserAddress tr_EuaIPv6(template OCT16 ip_addr) modifies t_EuaIPv6 := {
232 endUserAddress := {
233 endUserAddressIPv6 := {
234 lengthf := 2+lengthof(ip_addr)
235 }
236 }
237 }
Harald Welte94ade362017-08-04 00:36:55 +0200238
239 template AccessPointName ts_APN(octetstring apn) := {
240 type_gtpc := '83'O,
241 lengthf := lengthof(apn),
242 apn_value := apn
243 }
244
245 template GSN_Address_GTPC ts_GsnAddr(octetstring ip_addr) := {
246 type_gtpc := '85'O,
247 lengthf := lengthof(ip_addr),
248 addressf := ip_addr
249 }
250
251 template MSISDN ts_Msisdn(octetstring msisdn) := {
252 type_gtpc := '86'O,
253 lengthf := lengthof(msisdn),
254 msisdn := msisdn
255 }
256
257 template QualityOfServiceProfile ts_QosDefault := {
258 type_gtpc := '87'O,
259 lengthf := 4,
260 allocRetensionPrio := '00'O,
261 qos_ProfileValue := {
262 reliabilityClass := '011'B,
263 delayClass := '001'B,
264 spare1 := '00'B,
265 precedenceClass := '010'B,
266 spare2 := '0'B,
267 peakThroughput := '1001'B,
268 meanThroughput := '11111'B,
269 spare3 := '000'B,
270 deliverErroneusSDU := omit,
271 deliveryOrder := omit,
272 trafficClass := omit,
273 maxSDUSize := omit,
274 maxBitrateUplink := omit,
275 maxBitrateDownlink := omit,
276 sduErrorRatio := omit,
277 residualBER := omit,
278 trafficHandlingPriority := omit,
279 transferDelay := omit,
280 guaranteedBitRateUplink := omit,
281 guaranteedBitRateDownlink := omit,
282 sourceStatisticsDescriptor := omit,
283 signallingIndication := omit,
284 spare4 := omit,
285 maxBitrateDownlinkExt := omit,
286 guaranteedBitRateDownlinkExt := omit,
287 maxBitrateUplinkExt := omit,
288 guaranteedBitRateUplinkExt := omit
289 }
290 }
291
292 template IMSI_gtpc ts_Imsi(hexstring digits) := {
293 type_gtpc := '02'O,
294 digits := digits,
295 padding := 'F'H
296 }
297
298 template GTPC_PDUs ts_CreatePdpPDU(hexstring imsi, OCT1 restart_ctr, OCT4 teid_data, OCT4 teid_ctrl,
299 BIT4 nsapi, EndUserAddress eua, octetstring apn,
300 octetstring sgsn_ip_sign, octetstring sgsn_ip_data,
Harald Welteed7a1772017-08-09 20:26:20 +0200301 octetstring msisdn, template ProtConfigOptions pco := omit) := {
Harald Welte94ade362017-08-04 00:36:55 +0200302 createPDPContextRequest := {
303 imsi := ts_Imsi(imsi),
304 rai := omit,
305 recovery := ts_Recovery(restart_ctr),
306 selectionMode := {
307 type_gtpc := '0F'O,
308 selectModeValue := '00'B,
309 spare := '111111'B
310 },
311 teidDataI := {
312 type_gtpc := '00'O,
313 teidDataI := teid_data
314 },
315 teidControlPlane := {
316 type_gtpc := '00'O,
317 teidControlPlane := teid_ctrl
318 },
319 nsapi := {
320 type_gtpc := '00'O,
321 nsapi := nsapi,
322 unused := '0000'B
323 },
324 linked_nsapi := omit,
325 charging_char := omit,
326 trace_ref := omit,
327 trace_type := omit,
328 endUserAddress := eua,
329 accessPointName := ts_APN(apn),
Harald Welteed7a1772017-08-09 20:26:20 +0200330 protConfigOptions := pco,
Harald Welte94ade362017-08-04 00:36:55 +0200331 sgsn_addr_signalling := ts_GsnAddr(sgsn_ip_sign),
332 sgsn_addr_traffic := ts_GsnAddr(sgsn_ip_data),
333 msisdn := ts_Msisdn(msisdn),
334 qualityOfServiceProfile := ts_QosDefault,
335 tft := omit,
336 triggerId := omit,
337 omcId := omit,
338 commonFlags := omit,
339 aPN_Restriction := omit,
340 ratType := omit,
341 userLocationInformation := omit,
342 mS_TimeZone := omit,
343 imeisv := omit,
344 camelChargingInformationContainer := omit,
345 additionalTraceInfo := omit,
346 correlationID := omit,
347 evolvedAllocationRetentionPriorityI := omit,
348 extendedCommonFlags := omit,
349 userCSGInformation := omit,
350 aPN_AMBR := omit,
351 signallingPriorityIndication := omit,
352 cN_OperatorSelectionEntity := omit,
353 private_extension_gtpc := omit
354 }
355 }
356
Harald Welte811651e2017-08-05 15:25:06 +0200357 template Gtp1cUnitdata ts_GTPC_CreatePDP(GtpPeer peer, uint16_t seq, hexstring imsi,
358 OCT1 restart_ctr, OCT4 teid_data,
Harald Welte94ade362017-08-04 00:36:55 +0200359 OCT4 teid_ctrl, BIT4 nsapi, EndUserAddress eua,
360 octetstring apn, octetstring sgsn_ip_sign,
Harald Welteed7a1772017-08-09 20:26:20 +0200361 octetstring sgsn_ip_data, octetstring msisdn,
362 template ProtConfigOptions pco := omit) := {
Harald Welte94ade362017-08-04 00:36:55 +0200363 peer := peer,
364 gtpc := ts_GTP1C_PDU(createPDPContextRequest, '00000000'O,
365 valueof(ts_CreatePdpPDU(imsi, restart_ctr, teid_data, teid_ctrl,
366 nsapi, eua, apn, sgsn_ip_sign,
Harald Welteed7a1772017-08-09 20:26:20 +0200367 sgsn_ip_data, msisdn, pco)), seq)
368 }
369
Harald Welte99ef9a42017-08-14 21:42:03 +0200370 /* PCO send base template */
Harald Welteed7a1772017-08-09 20:26:20 +0200371 template ProtConfigOptions ts_PCO := {
372 type_gtpc := '84'O,
373 lengthf := 0,
374 configProtocol := '000'B,
375 spare := '0000'B,
376 extension0 := '1'B,
377 protocols := {}
378 }
Harald Welte99ef9a42017-08-14 21:42:03 +0200379 /* PCO receive base template */
380 template ProtConfigOptions tr_PCO := {
381 type_gtpc := '84'O,
382 lengthf := ?,
383 configProtocol := '000'B,
384 spare := ?,
385 extension0 := '1'B,
386 protocols := {}
387 }
Harald Welteed7a1772017-08-09 20:26:20 +0200388
389 template ProtConfigOptions ts_PCO_IPv6_DNS modifies ts_PCO := {
390 protocols := {
391 { protocolID := '0003'O, lengthProtoID := 0, protoIDContents := ''O }
392 }
393 }
Harald Welte99ef9a42017-08-14 21:42:03 +0200394 template ProtConfigOptions tr_PCO_IPv6_DNS_resp(template OCT16 contents) modifies tr_PCO := {
395 protocols := {
Harald Welte3ab91d62017-08-25 14:46:39 +0200396 *, { protocolID := '0003'O, lengthProtoID := 16, protoIDContents := contents }, *
Harald Welte99ef9a42017-08-14 21:42:03 +0200397 }
398 }
Harald Welteed7a1772017-08-09 20:26:20 +0200399
400 template ProtConfigOptions ts_PCO_IPv4_DNS_IPCP modifies ts_PCO := {
401 protocols := {
Harald Welteab4ca942017-09-07 18:41:52 +0200402 /* dummy PAP entry to check if our parser in the GGSN can properly iterate over
403 * the list of protocols, see Change-Id Icc2e6716c33d78d3c3e000f529806228d8aa155e */
404 { protocolID := 'C023'O, lengthProtoID := 0, protoIDContents := ''O },
Harald Welteeb9184d2017-12-04 19:01:47 +0100405 { protocolID := '8021'O, lengthProtoID := 16, protoIDContents :=
406 enc_IpcpPacket(valueof(ts_IPCP_ReqDNS)) }
Harald Welteed7a1772017-08-09 20:26:20 +0200407 }
408 }
409
Harald Welte71a36022017-12-04 18:55:58 +0100410 template ProtocolElement tr_PCO_Proto(OCT2 prot_id) := {
411 protocolID := prot_id,
412 lengthProtoID := ?,
413 protoIDContents := ?
414 }
415 template ProtConfigOptions tr_PCO_Contains(OCT2 prot_id) modifies tr_PCO := {
416 protocols := { *, tr_PCO_Proto(prot_id), * }
417 }
418
Harald Welteed7a1772017-08-09 20:26:20 +0200419 template ProtConfigOptions ts_PCO_IPv4_DNS_CONT modifies ts_PCO := {
420 protocols := {
421 { protocolID := '000d'O, lengthProtoID := 0, protoIDContents := ''O }
422 }
Harald Welte94ade362017-08-04 00:36:55 +0200423 }
Harald Welte99ef9a42017-08-14 21:42:03 +0200424 template ProtConfigOptions tr_PCO_IPv4_DNS_CONT_resp(template OCT4 contents) modifies tr_PCO := {
425 protocols := {
Harald Welte3ab91d62017-08-25 14:46:39 +0200426 *, { protocolID := '000d'O, lengthProtoID := 4, protoIDContents := contents }, *
Harald Welte99ef9a42017-08-14 21:42:03 +0200427 }
428 }
429
Harald Welte71a36022017-12-04 18:55:58 +0100430 /* extract a given protocol payload from PCO */
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100431 function f_PCO_extract_proto(ProtConfigOptions pco, OCT2 protocol, integer nth_match := 1) return octetstring {
Harald Welte71a36022017-12-04 18:55:58 +0100432 var integer i;
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100433 var integer num_matches := 0;
Harald Welte71a36022017-12-04 18:55:58 +0100434 for (i := 0; i < lengthof(pco.protocols); i := i + 1) {
435 if (pco.protocols[i].protocolID == protocol) {
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100436 num_matches := num_matches + 1;
437 if (num_matches == nth_match) {
438 return pco.protocols[i].protoIDContents;
439 }
Harald Welte71a36022017-12-04 18:55:58 +0100440 }
441 }
442 setverdict(fail);
443 return ''O;
444 }
445
446 template IpcpPacket tr_IPCP(template LcpCode code, template uint8_t identifier,
447 template IpcpOptionList opts) := {
448 code := code,
449 identifier := identifier,
450 len := ?,
451 options := opts
452 }
453 template IpcpOption tr_IPCP_PrimaryDns(template OCT4 addr) := {
454 code := IPCP_OPT_PrimaryDNS,
455 len := 6,
456 data := addr
457 }
458 template IpcpOption tr_IPCP_SecondaryDns(template OCT4 addr) := {
459 code := IPCP_OPT_SecondaryDNS,
460 len := 6,
461 data := addr
462 }
Harald Welte71a36022017-12-04 18:55:58 +0100463 template IpcpPacket tr_IPCP_Ack_DNS(template uint8_t identifier := ?, template OCT4 dns1 := ?,
464 template OCT4 dns2 := ?) :=
465 tr_IPCP(LCP_Configure_Ack, identifier,
466 { *, tr_IPCP_PrimaryDns(dns1), *, tr_IPCP_SecondaryDns(dns2), * });
467
Harald Welteeb9184d2017-12-04 19:01:47 +0100468 template IpcpPacket ts_IPCP(LcpCode code, uint8_t identifier, template IpcpOptionList opts) := {
469 code := code,
470 identifier := identifier,
471 len := 0, /* overwritten */
472 options := opts
473 }
474 template IpcpPacket ts_IPCP_ReqDNS(uint8_t identifier := 0) :=
475 ts_IPCP(LCP_Configure_Request, identifier,
476 { tr_IPCP_PrimaryDns('00000000'O), tr_IPCP_SecondaryDns('00000000'O) });
Harald Welte94ade362017-08-04 00:36:55 +0200477
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200478 function f_teardown_ind_IE(in template BIT1 ind) return template TearDownInd {
Harald Welte811651e2017-08-05 15:25:06 +0200479/*
480 if (not isvalue(ind)) {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200481 return omit;
482 }
Harald Welte811651e2017-08-05 15:25:06 +0200483*/
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200484 var TearDownInd ret := {
485 type_gtpc := '13'O,
486 tdInd := valueof(ind),
487 spare:= '0000000'B
488 }
489 return ret;
490 }
491
492 template GTPC_PDUs ts_DeletePdpPDU(BIT4 nsapi, template BIT1 teardown_ind) := {
493 deletePDPContextRequest := {
494 cause := omit,
495 tearDownIndicator := f_teardown_ind_IE(teardown_ind),
496 nsapi := {
497 type_gtpc := '14'O,
498 nsapi := nsapi,
499 unused := '0000'B
500 },
501 protConfigOptions := omit,
502 userLocationInformation := omit,
503 mS_TimeZone := omit,
504 extendedCommonFlags := omit,
505 uLI_Timestamp := omit,
506 private_extension_gtpc := omit
507 }
508 }
509
Harald Welte811651e2017-08-05 15:25:06 +0200510 template Gtp1cUnitdata ts_GTPC_DeletePDP(GtpPeer peer, uint16_t seq, OCT4 teid,
511 BIT4 nsapi, template BIT1 teardown_ind) := {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200512 peer := peer,
513 gtpc := ts_GTP1C_PDU(deletePDPContextRequest, teid,
Harald Welte811651e2017-08-05 15:25:06 +0200514 valueof(ts_DeletePdpPDU(nsapi, teardown_ind)), seq)
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200515 }
516
517
Harald Welte3af89482017-08-04 16:20:23 +0200518 /* GTP-U */
519
Harald Welte231b9412017-08-09 17:16:31 +0200520 template PDU_GTPU tr_GTP1U_PDU(template OCT1 msg_type, template OCT4 teid, template GTPU_IEs ies := ?) := {
Harald Welte3af89482017-08-04 16:20:23 +0200521 pn_bit := ?,
522 s_bit := ?,
523 e_bit := ?,
524 spare := ?,
525 /* Protocol Type flag (PT) shall be set to '1' in GTP */
526 pt := '1'B,
527 /* Version shall be set to decimal 1 ('001'). */
528 version := '001'B,
529 messageType := msg_type,
530 lengthf := ?,
531 teid := teid,
532 opt_part := *,
Harald Welte231b9412017-08-09 17:16:31 +0200533 gtpu_IEs := ies
Harald Welte3af89482017-08-04 16:20:23 +0200534 }
535
536 /* generalized GTP-U send template */
Harald Welte811651e2017-08-05 15:25:06 +0200537 template PDU_GTPU ts_GTP1U_PDU(OCT1 msg_type, uint16_t seq, OCT4 teid, GTPU_IEs ies) := {
Harald Welte3af89482017-08-04 16:20:23 +0200538 /* N-PDU Number flag (PN): the GTP-U header contains a meaningful N-PDU Number field if the PN
539 * flag is set to 1. */
540 pn_bit := '0'B, /* we assume the encoder overwrites this if an optional part is given */
541 /* If the Sequence Number flag (S) is set to '1' the sequence number field is present and
542 * meaningful otherwise it is set to '0'. For GTP-U messages Echo Request, Echo Response,
543 * Error Indication and Supported Extension Headers Notification, the S flag shall be set to '1'. */
Harald Welte811651e2017-08-05 15:25:06 +0200544 s_bit := '1'B, /* we assume the encoder overwrites this if an optional part is given */
Harald Welte3af89482017-08-04 16:20:23 +0200545 /* Extension header presence */
546 e_bit := '0'B,
547 spare := '0'B,
548 /* Protocol Type flag (PT) shall be set to '1' in GTP */
549 pt := '1'B,
550 /* Version shall be set to decimal 1 ('001'). */
551 version := '001'B,
552 messageType := msg_type,
553 lengthf := 0, /* we assume encoder overwrites this */
554 teid := teid,
Harald Welte811651e2017-08-05 15:25:06 +0200555 opt_part := {
556 sequenceNumber := int2oct(seq, 2),
557 npduNumber := '00'O,
558 nextExtHeader := '00'O,
559 gTPU_extensionHeader_List := omit
560 },
Harald Welte3af89482017-08-04 16:20:23 +0200561 gtpu_IEs := ies
562 }
563
564 template Gtp1uUnitdata tr_GTPU_MsgType(template GtpPeer peer, template OCT1 msg_type, template OCT4 teid) := {
565 peer := peer,
566 gtpu := tr_GTP1U_PDU(msg_type, teid)
567 }
568
569
Harald Welte231b9412017-08-09 17:16:31 +0200570 /* template matching reception of GTP-U echo-request */
Harald Welte3af89482017-08-04 16:20:23 +0200571 template Gtp1uUnitdata tr_GTPU_PING(template GtpPeer peer) := tr_GTPU_MsgType(peer, echoRequest, '00000000'O);
572
Harald Welte231b9412017-08-09 17:16:31 +0200573 /* template matching reception of GTP-U GPDU */
574 template GTPU_IEs t_GPDU(template octetstring data) := {
575 g_PDU_IEs := {
576 data := data
577 }
578 }
579 template Gtp1uUnitdata tr_GTPU_GPDU(template GtpPeer peer, template OCT4 teid, template octetstring data := ?) := {
580 peer := peer,
581 gtpu := tr_GTP1U_PDU('FF'O, teid, t_GPDU(data))
582 }
583
Harald Welte3af89482017-08-04 16:20:23 +0200584 template GTPU_IEs ts_UEchoRespPDU(OCT1 restart_counter) := {
585 echoResponse_IEs := {
586 recovery_gtpu := {
587 type_gtpu := '00'O, /* we assume encoder fixes? */
588 restartCounter := restart_counter
589 },
590 private_extension_gtpu := omit
591 }
592 }
593
594 /* master template for sending a GTP-U echo response */
Harald Welte811651e2017-08-05 15:25:06 +0200595 template Gtp1uUnitdata ts_GTPU_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := {
Harald Welte3af89482017-08-04 16:20:23 +0200596 peer := peer,
Harald Welte811651e2017-08-05 15:25:06 +0200597 gtpu := ts_GTP1U_PDU(echoResponse, seq, '00000000'O, valueof(ts_UEchoRespPDU(rest_ctr)))
Harald Welte3af89482017-08-04 16:20:23 +0200598 }
599
Harald Welte811651e2017-08-05 15:25:06 +0200600 /* master template for sending a GTP-U user plane data */
601 template Gtp1uUnitdata ts_GTP1U_GPDU(GtpPeer peer, uint16_t seq, OCT4 teid, octetstring data) := {
602 peer := peer,
603 gtpu := ts_GTP1U_PDU('FF'O, seq, teid, { g_PDU_IEs := { data := data }})
604 }
Harald Welte3af89482017-08-04 16:20:23 +0200605
Harald Welte94ade362017-08-04 00:36:55 +0200606 /* Altstep implementing responses to any incoming echo requests */
607 altstep pingpong() runs on GT_CT {
608 var Gtp1cUnitdata ud;
Harald Welte3af89482017-08-04 16:20:23 +0200609 var Gtp1uUnitdata udu;
Harald Welte94ade362017-08-04 00:36:55 +0200610 [] GTPC.receive(tr_GTPC_PING(?)) -> value ud {
Harald Welte811651e2017-08-05 15:25:06 +0200611 var uint16_t seq := oct2int(ud.gtpc.opt_part.sequenceNumber);
612 GTPC.send(ts_GTPC_PONG(ud.peer, seq, '00'O));
Harald Welte94ade362017-08-04 00:36:55 +0200613 repeat;
614 };
Harald Welte3af89482017-08-04 16:20:23 +0200615 [] GTPU.receive(tr_GTPU_PING(?)) -> value udu {
Harald Welte811651e2017-08-05 15:25:06 +0200616 var uint16_t seq := oct2int(udu.gtpu.opt_part.sequenceNumber);
617 GTPU.send(ts_GTPU_PONG(udu.peer, seq, '00'O));
Harald Welte3af89482017-08-04 16:20:23 +0200618 };
Harald Welte94ade362017-08-04 00:36:55 +0200619 [] T_default.timeout { setverdict(fail); };
620 }
621
Harald Welte811651e2017-08-05 15:25:06 +0200622 /* 'internet' in DNS encoding */
Harald Welteed097432017-08-13 13:28:49 +0200623 const octetstring c_ApnInternet := '08696E7465726E6574'O;
624 const octetstring c_ApnInet6 := '05696E657436'O;
625 const octetstring c_ApnInet46 := '06696E65743436'O;
Harald Welte94ade362017-08-04 00:36:55 +0200626
Harald Welte811651e2017-08-05 15:25:06 +0200627 /* return random NSAPI */
628 function f_rnd_nsapi() return BIT4 {
629 return int2bit(f_rnd_int(16), 4);
630 }
631
632 /* return random TEI[DC] */
633 function f_rnd_tei() return OCT4 {
634 return int2oct(f_rnd_int(4294967296), 4);
635 }
636
637 /* define an (internal) representation of a PDP context */
638 template PdpContext t_DefinePDP(hexstring imsi, octetstring msisdn, octetstring apn,
639 EndUserAddress eua) := {
640 imsi := imsi,
641 msisdn := msisdn,
642 nsapi := f_rnd_nsapi(),
643 apn := apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200644 pco_req := omit,
Harald Welte811651e2017-08-05 15:25:06 +0200645 eua := eua,
646 teid := f_rnd_tei(),
Harald Welte5438b9d2017-08-13 13:27:48 +0200647 teic := f_rnd_tei()
Harald Welte811651e2017-08-05 15:25:06 +0200648 }
649
650 /* send GTP-C for a given context and increment sequence number */
Harald Welte41575e92017-08-13 13:49:57 +0200651 function f_send_gtpc(in template Gtp1cUnitdata data) runs on GT_CT {
Harald Welte811651e2017-08-05 15:25:06 +0200652 GTPC.send(data);
Harald Welte5438b9d2017-08-13 13:27:48 +0200653 g_c_seq_nr := g_c_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200654 }
655
656 /* send GTP-U for a given context and increment sequence number */
Harald Welte231b9412017-08-09 17:16:31 +0200657 function f_send_gtpu(inout PdpContext ctx, in octetstring data) runs on GT_CT {
Harald Welte5438b9d2017-08-13 13:27:48 +0200658 GTPU.send(ts_GTP1U_GPDU(g_peer_u, g_d_seq_nr, ctx.teid_remote, data));
659 g_d_seq_nr := g_d_seq_nr + 1;
Harald Welte811651e2017-08-05 15:25:06 +0200660 }
661
662 /* send a PDP context activation */
663 function f_pdp_ctx_act(inout PdpContext ctx) runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200664 var Gtp1cUnitdata ud;
Harald Welte94ade362017-08-04 00:36:55 +0200665 var default d;
666
667 log("sending CreatePDP");
Harald Welte41575e92017-08-13 13:49:57 +0200668 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 +0200669 ctx.teid, ctx.teic, ctx.nsapi, ctx.eua, ctx.apn,
Harald Welteed7a1772017-08-09 20:26:20 +0200670 g_sgsn_ip_c, g_sgsn_ip_u, ctx.msisdn, ctx.pco_req));
Harald Welte94ade362017-08-04 00:36:55 +0200671 T_default.start;
Harald Welte94ade362017-08-04 00:36:55 +0200672 d := activate(pingpong());
673 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200674 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, createPDPContextResponse, ctx.teic)) -> value ud {
675 var CreatePDPContextResponse cpr := ud.gtpc.gtpc_pdu.createPDPContextResponse;
676 if (cpr.cause.causevalue == '80'O) {
Harald Welte99ef9a42017-08-14 21:42:03 +0200677 /* Check if EUA type corresponds to requested type */
678 if (match(ctx.eua, t_EuaIPv4(?)) and
679 not match(cpr.endUserAddress, tr_EuaIPv4(?))){
680 setverdict(fail);
681 }
682 if (match(ctx.eua, t_EuaIPv6(?)) and
683 not match(cpr.endUserAddress, tr_EuaIPv6(?))) {
684 setverdict(fail);
685 }
686 /* Check if PCO response corresponds to request */
687 if (ispresent(ctx.pco_req)) {
688 if (match(ctx.pco_req, ts_PCO_IPv4_DNS_CONT) and
689 not match(cpr.protConfigOptions, tr_PCO_IPv4_DNS_CONT_resp(?))) {
690 log("IPv4 DNS Container requested, but missing");
691 setverdict(fail);
692 }
693 if (match(ctx.pco_req, ts_PCO_IPv6_DNS) and
694 not match(cpr.protConfigOptions, tr_PCO_IPv6_DNS_resp(?))) {
695 log("IPv6 DNS Container requested, but missing");
696 setverdict(fail);
697 }
698 }
Harald Welte811651e2017-08-05 15:25:06 +0200699 ctx.teid_remote := cpr.teidDataI.teidDataI;
700 ctx.teic_remote := cpr.teidControlPlane.teidControlPlane;
Harald Welte231b9412017-08-09 17:16:31 +0200701 ctx.eua := cpr.endUserAddress;
Harald Welteed7a1772017-08-09 20:26:20 +0200702 ctx.pco_neg := cpr.protConfigOptions;
Harald Welte94ade362017-08-04 00:36:55 +0200703 setverdict(pass);
704 } else {
705 setverdict(fail);
706 }
707 }
708 }
709 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200710 T_default.stop;
Harald Welte94ade362017-08-04 00:36:55 +0200711 }
712
Harald Welte811651e2017-08-05 15:25:06 +0200713 function f_pdp_ctx_del(PdpContext ctx, template BIT1 teardown_ind) runs on GT_CT {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200714 var Gtp1cUnitdata ud;
715 var default d;
716
Harald Welte41575e92017-08-13 13:49:57 +0200717 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 +0200718 T_default.start;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200719 d := activate(pingpong());
720 alt {
Harald Welte811651e2017-08-05 15:25:06 +0200721 [] GTPC.receive(tr_GTPC_MsgType(g_peer_c, deletePDPContextResponse, ctx.teic)) -> value ud {
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200722 if (ud.gtpc.gtpc_pdu.deletePDPContextResponse.cause.causevalue == '80'O) {
723 setverdict(pass);
724 } else {
725 setverdict(fail);
726 }
727 }
728 }
729 deactivate(d);
Harald Welte811651e2017-08-05 15:25:06 +0200730 T_default.stop;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200731 }
Harald Welte811651e2017-08-05 15:25:06 +0200732 /* IPv6 router solicitation fe80::2 -> ff02::2 from 02:88:b5:1f:25:59 */
733 const octetstring c_router_solicit := '6000000000103afffe800000000000000000000000000002ff02000000000000000000000000000285009f2b0000000001010288b51f2559'O;
734 /* IPv6 neighbor solicitation fe80::2 -> ff02::1:ff00:2 from 02:88:b5:1f:25:59 */
735 const octetstring c_neigh_solicit:= '6000000000203afffe800000000000000000000000000002ff0200000000000000000001ff00000287009f9600000000fe80000000000000000000000000000201010288b51f2559'O;
Harald Weltef1e0d5a2017-08-05 08:51:22 +0200736
Harald Welte231b9412017-08-09 17:16:31 +0200737 /* template to generate a 'Prefix Information' ICMPv6 option */
738 template OptionField ts_ICMP6_OptPrefix(OCT16 prefix, INT1 prefix_len) := {
739 prefixInformation := {
740 typeField := 3,
741 lengthIndicator := 8,
742 prefixLength := prefix_len,
743 reserved1 := '000000'B,
744 a_Bit := '0'B,
745 l_Bit := '0'B,
746 validLifetime := oct2int('FFFFFFFF'O),
747 preferredLifetime := oct2int('FFFFFFFF'O),
748 reserved2 := '00000000'O,
749 prefix := prefix
750 }
751 }
752
753 /* template for an ICMPv6 router solicitation */
754 template PDU_ICMPv6 ts_ICMPv6_RS := {
755 routerSolicitation := {
756 typeField := 133,
757 code := 0,
758 checksum := '0000'O,
759 reserved := '00000000'O,
760 /* TODO: do we need 'Source link-layer address' ? */
761 options := omit
762 }
763 }
764
765 /* template for an ICMPv6 router advertisement */
766 template PDU_ICMPv6 ts_ICMPv6_RA(OCT16 prefix, INT1 prefix_len) := {
767 routerAdvertisement := {
768 typeField := 134,
769 code := 0,
770 checksum := '0000'O,
771 curHopLimit := ?,
772 reserved := '000000'B,
773 o_Bit := '0'B,
774 m_Bit := '0'B,
775 routerLifetime := oct2int('FFFF'O),
776 reachableTime := oct2int('FFFFFFFF'O),
777 retransTimer := oct2int('FFFFFFFF'O),
778 options := {
779 ts_ICMP6_OptPrefix(prefix, prefix_len)
780 }
781 }
782 }
783
784 template PDU_ICMPv6 ts_ICMPv6_NS(OCT16 target_addr) := {
785 neighborSolicitation := {
786 typeField := 135,
787 code := 0,
788 checksum := '0000'O,
789 reserved := '00000000'O,
790 targetAddress := target_addr,
791 /* TODO: do we need 'Source link-layer address' ? */
792 options := omit
793 }
794 }
795
796 /* derive ICMPv6 link-local address from lower 64bit of link_id */
797 /* template for receiving/matching an ICMPv6 'Prefix Information' option */
798 template OptionField tr_ICMP6_OptPrefix(template OCT16 prefix, template INT1 prefix_len) := {
799 prefixInformation := {
800 typeField := 3,
801 lengthIndicator := 4,
802 prefixLength := prefix_len,
803 reserved1 := ?,
804 a_Bit := ?,
805 l_Bit := ?,
806 validLifetime := ?,
807 preferredLifetime := ?,
808 reserved2 := ?,
809 prefix := prefix
810 }
811 }
812
813 /* template for receiving/matching an ICMPv6 router advertisement */
814 template PDU_ICMPv6 tr_ICMPv6_RA(template OCT16 prefix, template INT1 prefix_len) := {
815 routerAdvertisement := {
816 typeField := 134,
817 code := 0,
818 checksum := ?,
819 curHopLimit := ?,
820 reserved := ?,
821 o_Bit := '0'B,
822 m_Bit := '0'B,
823 routerLifetime := ?,
824 reachableTime := ?,
825 retransTimer := ?,
826 options := {
827 tr_ICMP6_OptPrefix(prefix, prefix_len)
828 }
829 }
830 }
831
832 /* template to construct IPv6_packet from input arguments, ready for use in f_IPv6_enc() */
833 template IPv6_packet ts_IP6(OCT16 srcaddr, OCT16 dstaddr, LIN1 nexthead, octetstring payload, LIN1 hlim := 255) := {
834 header := {
835 ver := 6,
836 trclass := 0,
837 flabel := 0,
838 plen := 0,
839 nexthead := nexthead,
840 hlim := hlim,
841 srcaddr := srcaddr,
842 dstaddr := dstaddr
843 },
844 ext_headers := omit,
845 payload := payload
846 }
847
848 function f_ipv6_link_local(in OCT16 link_id) return OCT16 {
849 return 'FE80000000000000'O & substr(link_id, 8, 8);
850 }
851
852 /* Compute solicited-node multicast address as per RFC4291 2.7.1 */
853 function f_ipv6_sol_node_mcast(in OCT16 addr) return OCT16 {
854 return 'FF0200000000000000000001FF'O & substr(addr, 13, 3);
855 }
856
857 /* generate and encode ICMPv6 router solicitation */
858 function f_gen_icmpv6_router_solicitation(in OCT16 link_id) return octetstring {
859 const OCT16 c_ip6_all_router_mcast := 'FF020000000000000000000000000002'O;
860 var OCT16 saddr := f_ipv6_link_local(link_id);
861
862 var octetstring tmp;
863 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_RS), saddr, c_ip6_all_router_mcast);
864 var IPv6_packet ip6 := valueof(ts_IP6(saddr, c_ip6_all_router_mcast, 58, tmp));
865
866 return f_IPv6_enc(ip6);
867 }
868
869 /* create ICMPv6 router solicitation deriving link-id from PDP Context EUA */
870 function f_icmpv6_rs_for_pdp(in PdpContext ctx) return octetstring {
871 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
872 return f_gen_icmpv6_router_solicitation(interface_id);
873 }
874
875 /* generate and encode ICMPv6 neighbor solicitation */
876 function f_gen_icmpv6_neigh_solicit(in OCT16 saddr, in OCT16 daddr, in OCT16 tgt_addr) return octetstring {
877 var octetstring tmp;
878 tmp := f_enc_PDU_ICMPv6(valueof(ts_ICMPv6_NS(tgt_addr)), saddr, daddr);
879 var IPv6_packet ip6 := valueof(ts_IP6(saddr, daddr, 58, tmp));
880 return f_IPv6_enc(ip6);
881 }
882
883 /* generate and encode ICMPv6 neighbor solicitation for PDP Context */
884 function f_gen_icmpv6_neigh_solicit_for_pdp(in PdpContext ctx) return octetstring {
885 var OCT16 interface_id := ctx.eua.endUserAddress.endUserAddressIPv6.ipv6_address;
886 var OCT16 link_local := f_ipv6_link_local(interface_id);
887 var OCT16 daddr := f_ipv6_sol_node_mcast(link_local);
888
889 return f_gen_icmpv6_neigh_solicit(link_local, daddr, link_local);
890 }
891
892 /* wait for GGSN to send us an ICMPv6 router advertisement */
893 function f_wait_rtr_adv(PdpContext ctx) runs on GT_CT {
894 var Gtp1uUnitdata ud;
895 T_default.start;
896 alt {
897 //'6???????????3aff'O
898 [] GTPU.receive(tr_GTPU_GPDU(g_peer_u, ?)) -> value ud {
899 var octetstring gpdu := ud.gtpu.gtpu_IEs.g_PDU_IEs.data;
900 var IPv6_packet ip6 := f_IPv6_dec(gpdu);
901 if (ip6.header.ver != 6 or ip6.header.nexthead != 58 or ip6.header.hlim != 255) {
902 repeat;
903 }
904 var PDU_ICMPv6 icmp6 := f_dec_PDU_ICMPv6(ip6.payload);
905 if (not match(icmp6, tr_ICMPv6_RA(?, 64))) {
906 repeat;
907 }
908 ctx.ip6_prefix := icmp6.routerAdvertisement.options[0].prefixInformation.prefix;
909 log("RA with /64 prefix ", ctx.ip6_prefix);
910 }
911 [] GTPU.receive(tr_GTPU_GPDU(?, ?)) { repeat; }
912 [] GTPU.receive { setverdict(fail); }
913 [] T_default.timeout { setverdict(fail); }
914 }
915 T_default.stop;
916 }
917
Harald Welte0ef285b2017-08-13 20:06:01 +0200918 /* Test IPv6 context activation for dynamic IPv6 EUA without request of IPv6 DNS */
Harald Welteed7a1772017-08-09 20:26:20 +0200919 testcase TC_pdp6_act_deact() runs on GT_CT {
Harald Welte94ade362017-08-04 00:36:55 +0200920 f_init();
Harald Welte231b9412017-08-09 17:16:31 +0200921
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 Welte811651e2017-08-05 15:25:06 +0200923 f_pdp_ctx_act(ctx);
Harald Welteed7a1772017-08-09 20:26:20 +0200924 f_pdp_ctx_del(ctx, '1'B);
925 }
926
Harald Welte0ef285b2017-08-13 20:06:01 +0200927 /* Test IPv6 context activation for dynamic IPv6 EUA wirh request of IPv6 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +0200928 testcase TC_pdp6_act_deact_pcodns() runs on GT_CT {
929 f_init();
930
Harald Welteed097432017-08-13 13:28:49 +0200931 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 +0200932 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
933 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +0100934
935 /* verify PCO contains both primary and secondary DNS */
936 var OCT4 ggsn_ip6_dns1 := f_inet6_addr(m_ggsn_ip6_dns1);
937 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 1), ggsn_ip6_dns1)) {
938 setverdict(fail, "Primary DNS IPv6 PCO option not found");
939 }
940
941 var OCT4 ggsn_ip6_dns2 := f_inet6_addr(m_ggsn_ip6_dns2);
942 if (not match(f_PCO_extract_proto(ctx.pco_neg, '0003'O, 2), ggsn_ip6_dns2)) {
943 setverdict(fail, "Secondary DNS IPv6 PCO option not found");
944 }
945
Harald Welteed7a1772017-08-09 20:26:20 +0200946 f_pdp_ctx_del(ctx, '1'B);
947 }
948
Harald Welte0ef285b2017-08-13 20:06:01 +0200949 /* Test PDP context activation for dynamic IPv6 EUA with IPv6 DNS in PCO and router solicitation/advertisement */
Harald Welteed7a1772017-08-09 20:26:20 +0200950 testcase TC_pdp6_act_deact_icmp6() runs on GT_CT {
951 f_init();
952
Harald Welteed097432017-08-13 13:28:49 +0200953 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 +0200954 ctx.pco_req := valueof(ts_PCO_IPv6_DNS);
955 f_pdp_ctx_act(ctx);
Harald Welte231b9412017-08-09 17:16:31 +0200956
957 //f_send_gtpu(ctx, c_router_solicit);
958 //f_send_gtpu(ctx, c_neigh_solicit);
959
960 f_send_gtpu(ctx, f_icmpv6_rs_for_pdp(ctx));
961 f_wait_rtr_adv(ctx);
962 f_send_gtpu(ctx, f_gen_icmpv6_neigh_solicit_for_pdp(ctx));
963
Harald Welte811651e2017-08-05 15:25:06 +0200964 f_pdp_ctx_del(ctx, '1'B);
Harald Welte94ade362017-08-04 00:36:55 +0200965 }
966
Harald Welte0ef285b2017-08-13 20:06:01 +0200967 /* Test PDP context activation for dynamic IPv4 EUA without DNS request */
Harald Welteed7a1772017-08-09 20:26:20 +0200968 testcase TC_pdp4_act_deact() runs on GT_CT {
969 f_init();
Harald Welteed097432017-08-13 13:28:49 +0200970 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 +0200971 f_pdp_ctx_act(ctx);
972 f_pdp_ctx_del(ctx, '1'B);
973 }
974
Harald Welte0ef285b2017-08-13 20:06:01 +0200975 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in IPCP */
Harald Welteed7a1772017-08-09 20:26:20 +0200976 testcase TC_pdp4_act_deact_ipcp() runs on GT_CT {
977 f_init();
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100978 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
979 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
Harald Welteed097432017-08-13 13:28:49 +0200980 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 +0200981 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_IPCP);
Harald Welteed7a1772017-08-09 20:26:20 +0200982 f_pdp_ctx_act(ctx);
Harald Welte71a36022017-12-04 18:55:58 +0100983 /* verify IPCP is at all contained */
984 if (not match(ctx.pco_neg, tr_PCO_Contains('8021'O))) {
985 setverdict(fail, "IPCP not found in PCO");
986 }
987 /* verify IPCP contains both primary and secondary DNS */
988 var IpcpPacket ipcp := dec_IpcpPacket(f_PCO_extract_proto(ctx.pco_neg, '8021'O));
Pau Espin Pedrolf69a4382018-01-29 13:09:00 +0100989 if (not match(ipcp, tr_IPCP_Ack_DNS(0, ggsn_ip4_dns1, ggsn_ip4_dns2))) {
990 if (not match(ipcp, tr_IPCP_Ack_DNS(0))) {
991 setverdict(fail, "Primary/Secondary DNS PCO IPCP option not found");
992 } else {
993 setverdict(fail, "Primary/Secondary DNS PCO IPCP option found but not matching expected values");
994 }
Harald Welte71a36022017-12-04 18:55:58 +0100995 }
Harald Welteed7a1772017-08-09 20:26:20 +0200996 f_pdp_ctx_del(ctx, '1'B);
997 }
998
Harald Welte0ef285b2017-08-13 20:06:01 +0200999 /* Test PDP context activation for dynamic IPv4 EUA with IPv4 DNS in PCO */
Harald Welteed7a1772017-08-09 20:26:20 +02001000 testcase TC_pdp4_act_deact_pcodns() runs on GT_CT {
1001 f_init();
Harald Welteed097432017-08-13 13:28:49 +02001002 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 +02001003 ctx.pco_req := valueof(ts_PCO_IPv4_DNS_CONT);
Harald Welteed7a1772017-08-09 20:26:20 +02001004 f_pdp_ctx_act(ctx);
Pau Espin Pedrol363ba482018-01-29 18:42:00 +01001005
1006 /* verify PCO contains both primary and secondary DNS */
1007 var OCT4 ggsn_ip4_dns1 := f_inet_addr(m_ggsn_ip4_dns1);
1008 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 1), ggsn_ip4_dns1)) {
1009 setverdict(fail, "Primary DNS IPv4 PCO option not found");
1010 }
1011
1012 var OCT4 ggsn_ip4_dns2 := f_inet_addr(m_ggsn_ip4_dns2);
1013 if (not match(f_PCO_extract_proto(ctx.pco_neg, '000d'O, 2), ggsn_ip4_dns2)) {
1014 setverdict(fail, "Secondary DNS IPv4 PCO option not found");
1015 }
1016
Harald Welteed7a1772017-08-09 20:26:20 +02001017 f_pdp_ctx_del(ctx, '1'B);
1018 }
1019
Harald Weltedca80052017-08-13 20:01:38 +02001020 testcase TC_echo_req_resp() runs on GT_CT {
1021 f_init();
1022 f_send_gtpc(ts_GTPC_PING(g_peer_c, g_c_seq_nr));
1023 T_default.start;
1024 alt {
1025 [] GTPC.receive(tr_GTPC_PONG(g_peer_c)) { setverdict(pass); };
1026 [] GTPC.receive { repeat; };
1027 [] T_default.timeout { setverdict(fail); }
1028 }
1029 T_default.stop;
1030 }
1031
Harald Welte94ade362017-08-04 00:36:55 +02001032 control {
Harald Welteed7a1772017-08-09 20:26:20 +02001033 execute(TC_pdp4_act_deact());
1034 execute(TC_pdp4_act_deact_ipcp());
1035 execute(TC_pdp4_act_deact_pcodns());
1036
1037 execute(TC_pdp6_act_deact());
1038 execute(TC_pdp6_act_deact_pcodns());
1039 execute(TC_pdp6_act_deact_icmp6());
Harald Weltedca80052017-08-13 20:01:38 +02001040
1041 execute(TC_echo_req_resp());
Harald Welte94ade362017-08-04 00:36:55 +02001042 }
Harald Welte379d45a2017-08-03 09:55:15 +02001043}