summaryrefslogtreecommitdiffstats
path: root/library/GTP_Templates.ttcn
blob: d0a87e3d8b9b64db8e6eac445c3e239375a11f20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
module GTP_Templates {

	import from General_Types all;
	import from Osmocom_Types all;
	import from GTPC_Types all;
	import from GTPU_Types all;
	import from GTP_CodecPort all;
	import from IPCP_Types all;

	/* Table 38 of 3GPP TS 29.060 */
	type enumerated GTP_Cause {
		GTP_CAUSE_REQUEST_IMEI			(1),
		GTP_CAUSE_REQUEST_IMSI_AND_IMEI		(2),
		GTP_CAUSE_NO_IDENTITY_NEDED		(3),
		GTP_CAUSE_MS_REFUSES			(4),
		GTP_CAUSE_MS_IS_NOT_GPRS_RESPONDING	(5),
		/* reserved */
		GTP_CAUSE_REQUEST_ACCEPTED		(128)
		/* FIXME */
	};

	/* generalized GTP-C receive template */
	template PDU_GTPC tr_GTP1C_PDU(template OCT1 msg_type, template OCT4 teid, template GTPC_PDUs pdu := ?) := {
		/* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an
		 * error if this flag is set to '1'. */
		pn_bit := '0'B,
		/* Sequence number flag (S) shall be set to '1'. */
		s_bit := '1'B,
		e_bit := ?,
		spare := ?,
		/* Protocol Type flag (PT) shall be set to '1'.*/
		pt := '1'B,
		/* Version shall be set to decimal 1 ('001'). */
		version := '001'B,
		messageType := msg_type,
		lengthf := ?,
		teid := teid,
		opt_part := *,
		gtpc_pdu := pdu
	}

	/* generalized GTP-C send template */
	template PDU_GTPC ts_GTP1C_PDU(OCT1 msg_type, OCT4 teid, GTPC_PDUs pdu, uint16_t seq_nr) := {
		/* N-PDU Number flag (PN) shall be set to '0'. A GTP-C receiver shall not return an
		 * error if this flag is set to '1'. */
		pn_bit := '0'B,
		/* Sequence number flag (S) shall be set to '1'. */
		s_bit := '1'B,
		e_bit := '0'B,
		spare := '0'B,
		/* Protocol Type flag (PT) shall be set to '1'.*/
		pt := '1'B,
		/* Version shall be set to decimal 1 ('001'). */
		version := '001'B,
		messageType := msg_type,
		lengthf := 0,	/* we assume encoder overwrites this */
		teid := teid,
		opt_part := {
			sequenceNumber := int2oct(seq_nr, 2),
			npduNumber := '00'O,
			nextExtHeader := '00'O,
			gTPC_extensionHeader_List := omit
		},
		gtpc_pdu := pdu
	}

	/* recovery IE */
	template Recovery_gtpc ts_Recovery(OCT1 restart_counter) := {
		type_gtpc := '0E'O,
		restartCounter := restart_counter
	}

	template Recovery_gtpc tr_Recovery(template OCT1 restart_counter) := {
		type_gtpc := '0E'O,
		restartCounter := restart_counter
	}

	/* template matching reception of GTP-C echo-request */
	template Gtp1cUnitdata tr_GTPC_MsgType(template GtpPeer peer, template OCT1 msg_type, template OCT4 teid, template GTPC_PDUs pdus := ?) := {
		peer := peer,
		gtpc := tr_GTP1C_PDU(msg_type, teid, pdus)
	}

	/* template matching reception of GTP-C echo-request */
	template Gtp1cUnitdata tr_GTPC_PING(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoRequest, '00000000'O);

	template GTPC_PDUs tr_EchoRespPDU(template OCT1 restart_counter) := {
		echoResponse := {
			recovery := tr_Recovery(restart_counter),
			private_extension_gtpc := *
		}
	}

	/* template matching reception of GTP-C echo-response */
	template Gtp1cUnitdata tr_GTPC_PONG(template GtpPeer peer) := tr_GTPC_MsgType(peer, echoResponse, '00000000'O, tr_EchoRespPDU(?));

	template GTPC_PDUs ts_EchoRespPDU(OCT1 restart_counter) := {
		echoResponse := {
			recovery := ts_Recovery(restart_counter),
			private_extension_gtpc := omit
		}
	}

	/* master template for senidng a GTP-C echo response */
	template Gtp1cUnitdata ts_GTPC_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := {
		peer := peer,
		gtpc := ts_GTP1C_PDU(echoResponse, '00000000'O, valueof(ts_EchoRespPDU(rest_ctr)), seq)
	}

	template GTPC_PDUs ts_EchoReqPDU := {
		echoRequest := {
			private_extension_gtpc := omit
		}
	}

	/* master template for sending a GTP-C echo request */
	template Gtp1cUnitdata ts_GTPC_PING(GtpPeer peer, uint16_t seq) := {
		peer := peer,
		gtpc := ts_GTP1C_PDU(echoRequest, '00000000'O, valueof(ts_EchoReqPDU), seq)
	}

	template EndUserAddress t_EuaIPv4(template OCT4 ip_addr) := {
		type_gtpc := '80'O,
		endUserAddress := {
			endUserAddressIPv4 := {
				lengthf := 2,
				pdp_typeorg := '0001'B,
				spare := '1111'B,
				pdp_typenum := '21'O,
				ipv4_address := ip_addr
			}
		}
	}
	template EndUserAddress t_EuaIPv4Dyn := t_EuaIPv4(omit);
	template EndUserAddress tr_EuaIPv4(template OCT4 ip_addr) modifies t_EuaIPv4 := {
		endUserAddress := {
			endUserAddressIPv4 := {
				lengthf := 2+lengthof(ip_addr)
			}
		}
	}

	template EndUserAddress t_EuaIPv6(template OCT16 ip_addr) := {
		type_gtpc := '80'O,
		endUserAddress := {
			endUserAddressIPv6 := {
				lengthf := 2,
				pdp_typeorg := '0001'B,
				spare := '1111'B,
				pdp_typenum := '57'O,
				ipv6_address := ip_addr
			}
		}
	}
	template EndUserAddress t_EuaIPv6Dyn := t_EuaIPv6(omit);
	template EndUserAddress tr_EuaIPv6(template OCT16 ip_addr) modifies t_EuaIPv6 := {
		endUserAddress := {
			endUserAddressIPv6 := {
				lengthf := 2+lengthof(ip_addr)
			}
		}
	}

	template AccessPointName ts_APN(octetstring apn) := {
		type_gtpc := '83'O,
		lengthf := lengthof(apn),
		apn_value := apn
	}

	template GSN_Address_GTPC ts_GsnAddr(octetstring ip_addr) := {
		type_gtpc := '85'O,
		lengthf := lengthof(ip_addr),
		addressf := ip_addr
	}

	template MSISDN ts_Msisdn(octetstring msisdn) := {
		type_gtpc := '86'O,
		lengthf := lengthof(msisdn),
		msisdn := msisdn
	}

	template QualityOfServiceProfile ts_QosDefault := {
		type_gtpc := '87'O,
		lengthf := 4,
		allocRetensionPrio := '00'O,
		qos_ProfileValue := {
			reliabilityClass := '011'B,
			delayClass := '001'B,
			spare1 := '00'B,
			precedenceClass := '010'B,
			spare2 := '0'B,
			peakThroughput := '1001'B,
			meanThroughput := '11111'B,
			spare3 := '000'B,
			deliverErroneusSDU := omit,
			deliveryOrder := omit,
			trafficClass := omit,
			maxSDUSize := omit,
			maxBitrateUplink := omit,
			maxBitrateDownlink := omit,
			sduErrorRatio := omit,
			residualBER := omit,
			trafficHandlingPriority := omit,
			transferDelay := omit,
			guaranteedBitRateUplink := omit,
			guaranteedBitRateDownlink := omit,
			sourceStatisticsDescriptor := omit,
			signallingIndication := omit,
			spare4 := omit,
			maxBitrateDownlinkExt := omit,
			guaranteedBitRateDownlinkExt := omit,
			maxBitrateUplinkExt := omit,
			guaranteedBitRateUplinkExt := omit
		}
	}

	template IMSI_gtpc ts_Imsi(hexstring digits) := {
		type_gtpc := '02'O,
		digits := digits,
		padding := 'F'H
	}

	template GTPC_PDUs ts_CreatePdpPDU(hexstring imsi, OCT1 restart_ctr, OCT4 teid_data, OCT4 teid_ctrl,
					   BIT4 nsapi, EndUserAddress eua, octetstring apn,
					   octetstring sgsn_ip_sign, octetstring sgsn_ip_data,
					   octetstring msisdn, template ProtConfigOptions pco := omit) := {
		createPDPContextRequest := {
			imsi := ts_Imsi(imsi),
			rai := omit,
			recovery := ts_Recovery(restart_ctr),
			selectionMode := {
				type_gtpc := '0F'O,
				selectModeValue := '00'B,
				spare := '111111'B
			},
			teidDataI := {
				type_gtpc := '00'O,
				teidDataI := teid_data
			},
			teidControlPlane := {
				type_gtpc := '00'O,
				teidControlPlane := teid_ctrl
			},
			nsapi := {
				type_gtpc := '00'O,
				nsapi := nsapi,
				unused := '0000'B
			},
			linked_nsapi := omit,
			charging_char := omit,
			trace_ref := omit,
			trace_type := omit,
			endUserAddress := eua,
			accessPointName := ts_APN(apn),
			protConfigOptions := pco,
			sgsn_addr_signalling := ts_GsnAddr(sgsn_ip_sign),
			sgsn_addr_traffic := ts_GsnAddr(sgsn_ip_data),
			msisdn := ts_Msisdn(msisdn),
			qualityOfServiceProfile := ts_QosDefault,
			tft := omit,
			triggerId := omit,
			omcId := omit,
			commonFlags := omit,
			aPN_Restriction := omit,
			ratType := omit,
			userLocationInformation := omit,
			mS_TimeZone := omit,
			imeisv := omit,
			camelChargingInformationContainer := omit,
			additionalTraceInfo := omit,
			correlationID := omit,
			evolvedAllocationRetentionPriorityI := omit,
			extendedCommonFlags := omit,
			userCSGInformation := omit,
			aPN_AMBR := omit,
			signallingPriorityIndication := omit,
			cN_OperatorSelectionEntity := omit,
			private_extension_gtpc := omit
		}
	}

	template Gtp1cUnitdata ts_GTPC_CreatePDP(GtpPeer peer, uint16_t seq, hexstring imsi,
						 OCT1 restart_ctr, OCT4 teid_data,
						 OCT4 teid_ctrl, BIT4 nsapi, EndUserAddress eua,
						 octetstring apn, octetstring sgsn_ip_sign,
						 octetstring sgsn_ip_data, octetstring msisdn,
						 template ProtConfigOptions pco := omit) := {
		peer := peer,
		gtpc := ts_GTP1C_PDU(createPDPContextRequest, '00000000'O,
					valueof(ts_CreatePdpPDU(imsi, restart_ctr, teid_data, teid_ctrl,
								nsapi, eua, apn, sgsn_ip_sign,
								sgsn_ip_data, msisdn, pco)), seq)
	}


	template NSAPI_GTPC ts_NSAPI(BIT4 nsapi) := {
		type_gtpc := '14'O,
		nsapi := nsapi,
		unused := '0000'B
	}

	template ReorderingRequired ts_ReorderReq(boolean req := false) := {
		type_gtpc := '08'O,
		reordreq := bool2bit(req),
		spare := '0000000'B
	}

	template GTPC_PDUs ts_CreatePdpRespPDU(OCT1 cause, OCT4 teid_data, OCT4 teid_ctrl, BIT4 nsapi,
						octetstring ggsn_ip_sign, octetstring ggsn_ip_data,
						OCT4 chg_id, template EndUserAddress eua := omit,
						template Recovery_gtpc recovery := omit,
						template ProtConfigOptions pco := omit) := {
		createPDPContextResponse := {
			cause := { '00'O, cause },
			reorderingRequired := ts_ReorderReq(false),
			recovery := recovery,
			teidDataI := {
				type_gtpc := '00'O,
				teidDataI := teid_data
			},
			teidControlPlane := {
				type_gtpc := '00'O,
				teidControlPlane := teid_ctrl
			},
			nsapi := ts_NSAPI(nsapi),
			chargingID := {
				type_gtpc := '7F'O,
				chargingID := chg_id
			},
			endUserAddress := eua,
			protConfigOptions := pco,
			ggsn_addr_controlPlane := ts_GsnAddr(ggsn_ip_sign),
			ggsn_addr_traffic := ts_GsnAddr(ggsn_ip_data),
			alt_ggsn_addr_controlPane := omit,
			alt_ggsn_addr_traffic := omit,
			qualityOfServiceProfile := ts_QosDefault,
			commonFlags := omit,
			aPN_Restriction := omit,
			mS_InfoChangeReportingAction := omit,
			bearerControlMode := omit,
			evolvedAllocationRetentionPriorityI := omit,
			extendedCommonFlag := omit,
			csg_information_reporting_action := omit,
			aPN_AMBR := omit,
			gGSN_BackOffTime := omit,
			private_extension_gtpc := omit
		}
	}

	template Gtp1cUnitdata ts_GTPC_CreatePdpResp(GtpPeer peer, uint16_t seq, OCT4 teid,
						 OCT1 cause,
						 OCT4 teid_ctrl, OCT4 teid_data,
						 BIT4 nsapi, octetstring ggsn_ip_sign,
						 octetstring ggsn_ip_data, OCT4 chg_id,
						 template EndUserAddress eua := omit,
						 template Recovery_gtpc recovery := omit,
						 template ProtConfigOptions pco := omit) := {
		peer := peer,
		gtpc := ts_GTP1C_PDU(createPDPContextResponse, teid,
					valueof(ts_CreatePdpRespPDU(cause, teid_data, teid_ctrl, nsapi,
								ggsn_ip_sign, ggsn_ip_data, chg_id,
								eua, recovery, pco)), seq)
	}

	/* PCO send base template */
	template ProtConfigOptions ts_PCO := {
		type_gtpc := '84'O,
		lengthf := 0,
		configProtocol := '000'B,
		spare := '0000'B,
		extension0 := '1'B,
		protocols := {}
	}
	/* PCO receive base template */
	template ProtConfigOptions tr_PCO := {
		type_gtpc := '84'O,
		lengthf := ?,
		configProtocol := '000'B,
		spare := ?,
		extension0 := '1'B,
		protocols := {}
	}

	template ProtConfigOptions ts_PCO_IPv6_DNS modifies ts_PCO := {
		protocols := {
			{ protocolID := '0003'O, lengthProtoID := 0, protoIDContents := ''O }
		}
	}
	template ProtConfigOptions tr_PCO_IPv6_DNS_resp(template OCT16 contents) modifies tr_PCO := {
		protocols := {
			*, { protocolID := '0003'O, lengthProtoID := 16, protoIDContents := contents }, *
		}
	}

	template ProtConfigOptions ts_PCO_IPv4_DNS_IPCP modifies ts_PCO := {
		protocols := {
			/* dummy PAP entry to check if our parser in the GGSN can properly iterate over
			 * the list of protocols, see Change-Id Icc2e6716c33d78d3c3e000f529806228d8aa155e */
			{ protocolID := 'C023'O, lengthProtoID := 0, protoIDContents := ''O },
			{ protocolID := '8021'O, lengthProtoID := 16, protoIDContents :=
								enc_IpcpPacket(valueof(ts_IPCP_ReqDNS)) }
		}
	}

	template ProtConfigOptions ts_PCO_IPv4_PRI_DNS_IPCP modifies ts_PCO := {
		protocols := {
			/* dummy PAP entry to check if our parser can cope with a single primary DNS entry
			 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
			{ protocolID := 'C023'O, lengthProtoID := 0, protoIDContents := ''O },
			{ protocolID := '8021'O, lengthProtoID := 16, protoIDContents :=
								enc_IpcpPacket(valueof(ts_IPCP_ReqDNS_Primary)) }
		}
	}
	template ProtConfigOptions ts_PCO_IPv4_SEC_DNS_IPCP modifies ts_PCO := {
		protocols := {
			/* dummy PAP entry to check if our parser can cope with a single secondary DNS entry
			 * see Change-Id Icffde89f9bc5d8fcadf6e2dd6c0b4de03440edd5 and OS#3288 */
			{ protocolID := 'C023'O, lengthProtoID := 0, protoIDContents := ''O },
			{ protocolID := '8021'O, lengthProtoID := 16, protoIDContents :=
								enc_IpcpPacket(valueof(ts_IPCP_ReqDNS_Secondary)) }
		}
	}
	template ProtConfigOptions ts_PCO_IPv4_SEPARATE_DNS_IPCP modifies ts_PCO := {
		protocols := {
			/* dummy PAP entry to check if our parser can cope with a primary and secondary DNS
			 * in separate IPCP containers OS#3381 */
			{ protocolID := 'C023'O, lengthProtoID := 0, protoIDContents := ''O },
			{ protocolID := '8021'O, lengthProtoID := 16, protoIDContents :=
								enc_IpcpPacket(valueof(ts_IPCP_ReqDNS_Primary)) },
			{ protocolID := '8021'O, lengthProtoID := 16, protoIDContents :=
								enc_IpcpPacket(valueof(ts_IPCP_ReqDNS_Secondary)) }
		}
	}

	template ProtocolElement tr_PCO_Proto(OCT2 prot_id) := {
		protocolID := prot_id,
		lengthProtoID := ?,
		protoIDContents := ?
	}
	template ProtConfigOptions tr_PCO_Contains(OCT2 prot_id) modifies tr_PCO := {
		protocols := { *, tr_PCO_Proto(prot_id), * }
	}

	template ProtConfigOptions ts_PCO_IPv4_DNS_CONT modifies ts_PCO := {
		protocols := {
			{ protocolID := '000d'O, lengthProtoID := 0, protoIDContents := ''O }
		}
	}
	template ProtConfigOptions tr_PCO_IPv4_DNS_CONT_resp(template OCT4 contents) modifies tr_PCO := {
		protocols := {
			*, { protocolID := '000d'O, lengthProtoID := 4, protoIDContents := contents }, *
		}
	}

	/* extract a given protocol payload from PCO */
	function f_PCO_extract_proto(ProtConfigOptions pco, OCT2 protocol, integer nth_match := 1) return octetstring {
		var integer i;
		var integer num_matches := 0;
		for (i := 0; i < lengthof(pco.protocols); i := i + 1) {
			if (pco.protocols[i].protocolID == protocol) {
				num_matches := num_matches + 1;
				if (num_matches == nth_match) {
					return pco.protocols[i].protoIDContents;
				}
			}
		}
		setverdict(fail);
		return ''O;
	}

	template IpcpPacket tr_IPCP(template LcpCode code, template uint8_t identifier,
				    template IpcpOptionList opts) := {
		code := code,
		identifier := identifier,
		len := ?,
		options := opts
	}
	template IpcpOption tr_IPCP_PrimaryDns(template OCT4 addr) := {
		code := IPCP_OPT_PrimaryDNS,
		len := 6,
		data := addr
	}
	template IpcpOption tr_IPCP_SecondaryDns(template OCT4 addr) := {
		code := IPCP_OPT_SecondaryDNS,
		len := 6,
		data := addr
	}
	template IpcpPacket tr_IPCP_Ack_DNS(template uint8_t identifier := ?, template OCT4 dns1 := ?,
					    template OCT4 dns2 := ?) :=
		tr_IPCP(LCP_Configure_Ack, identifier,
				{ *, tr_IPCP_PrimaryDns(dns1), *, tr_IPCP_SecondaryDns(dns2), * });

	template IpcpPacket ts_IPCP(LcpCode code, uint8_t identifier, template IpcpOptionList opts) := {
		code := code,
		identifier := identifier,
		len := 0,	/* overwritten */
		options := opts
	}
	template IpcpPacket ts_IPCP_ReqDNS(uint8_t identifier := 0) :=
		ts_IPCP(LCP_Configure_Request, identifier,
			{ tr_IPCP_PrimaryDns('00000000'O), tr_IPCP_SecondaryDns('00000000'O) });

	template IpcpPacket ts_IPCP_ReqDNS_Primary(uint8_t identifier := 0) :=
		ts_IPCP(LCP_Configure_Request, identifier,
			{ tr_IPCP_PrimaryDns('00000000'O) });
	template IpcpPacket ts_IPCP_ReqDNS_Secondary(uint8_t identifier := 0) :=
		ts_IPCP(LCP_Configure_Request, identifier,
			{ tr_IPCP_SecondaryDns('00000000'O) });

	function f_teardown_ind_IE(in template (omit) BIT1 ind) return template (omit) TearDownInd {
		if (istemplatekind(ind, "omit")) {
			return omit;
		}
		var TearDownInd ret := {
			type_gtpc := '13'O,
			tdInd := valueof(ind),
			spare:= '0000000'B
		}
		return ret;
	}

	template GTPC_PDUs ts_DeletePdpPDU(BIT4 nsapi, template (omit) BIT1 teardown_ind) := {
		deletePDPContextRequest := {
			cause := omit,
			tearDownIndicator := f_teardown_ind_IE(teardown_ind),
			nsapi := {
				type_gtpc := '14'O,
				nsapi := nsapi,
				unused := '0000'B
			},
			protConfigOptions := omit,
			userLocationInformation := omit,
			mS_TimeZone := omit,
			extendedCommonFlags := omit,
			uLI_Timestamp := omit,
			private_extension_gtpc := omit
		}
	}

	template Gtp1cUnitdata ts_GTPC_DeletePDP(GtpPeer peer, uint16_t seq, OCT4 teid,
						 BIT4 nsapi, template (omit) BIT1 teardown_ind) := {
		peer := peer,
		gtpc := ts_GTP1C_PDU(deletePDPContextRequest, teid,
					valueof(ts_DeletePdpPDU(nsapi, teardown_ind)), seq)
	}

	template GTPC_PDUs ts_DeletePdpRespPDU(OCT1 cause,
						template ProtConfigOptions pco := omit) := {
		deletePDPContextResponse := {
			cause := { '00'O, cause },
			protConfigOptions := pco,
			userLocationInformation := omit,
			mS_TimeZone := omit,
			uLI_Timestamp := omit,
			private_extension_gtpc := omit
		}
	}

	template Gtp1cUnitdata ts_GTPC_DeletePdpResp(GtpPeer peer, uint16_t seq, OCT4 teid,
						OCT1 cause,
						template ProtConfigOptions pco := omit) := {
		peer := peer,
		gtpc := ts_GTP1C_PDU(deletePDPContextResponse, teid,
					valueof(ts_DeletePdpRespPDU(cause, pco)), seq)
	}



	/* GTP-U */

	template PDU_GTPU tr_GTP1U_PDU(template OCT1 msg_type, template OCT4 teid, template GTPU_IEs ies := ?) := {
		pn_bit := ?,
		s_bit := ?,
		e_bit := ?,
		spare := ?,
		/* Protocol Type flag (PT) shall be set to '1' in GTP */
		pt := '1'B,
		/* Version shall be set to decimal 1 ('001'). */
		version := '001'B,
		messageType := msg_type,
		lengthf := ?,
		teid := teid,
		opt_part := *,
		gtpu_IEs := ies
	}

	function f_GTPU_s_bit(template (omit) uint16_t seq) return BIT1 {
		if (istemplatekind(seq, "omit")) {
			return '0'B;
		}
		return '1'B;
	}

	function f_GTPU_opt_part(template (omit) uint16_t seq) return template (omit) GTPU_Header_optional_part {
		if (istemplatekind(seq, "omit")) {
			return omit;
		}
		var GTPU_Header_optional_part ret := {
			sequenceNumber := int2oct(valueof(seq), 2),
			npduNumber := '00'O,
			nextExtHeader := '00'O,
			gTPU_extensionHeader_List := omit
		};
		return ret;
	}

	/* generalized GTP-U send template */
	template PDU_GTPU ts_GTP1U_PDU(OCT1 msg_type, template (omit) uint16_t seq, OCT4 teid, GTPU_IEs ies) := {
		/* N-PDU Number flag (PN): the GTP-U header contains a meaningful N-PDU Number field if the PN
		 * flag is set to 1. */
		pn_bit := '0'B,	/* we assume the encoder overwrites this if an optional part is given */
		/* If the Sequence Number flag (S) is set to '1' the sequence number field is present and
		 * meaningful otherwise it is set to '0'. For GTP-U messages Echo Request, Echo Response,
		 * Error Indication and Supported Extension Headers Notification, the S flag shall be set to '1'.
		 *
		 * Note that the caller must ensure that these conditions hold.
		 * The caller can either pass a sequence number (we set s_bit to '1'B) when appropriate,
		 * or may omit the sequence number (we set s_bit to '0'B). */
		s_bit := f_GTPU_s_bit(seq),
		/* Extension header presence */
		e_bit := '0'B,
		spare := '0'B,
		/* Protocol Type flag (PT) shall be set to '1' in GTP */
		pt := '1'B,
		/* Version shall be set to decimal 1 ('001'). */
		version := '001'B,
		messageType := msg_type,
		lengthf := 0,	/* we assume encoder overwrites this */
		teid := teid,
		opt_part := f_GTPU_opt_part(seq),
		gtpu_IEs := ies
	}

	template Gtp1uUnitdata tr_GTPU_MsgType(template GtpPeer peer, template OCT1 msg_type, template OCT4 teid) := {
		peer := peer,
		gtpu := tr_GTP1U_PDU(msg_type, teid)
	}


	/* template matching reception of GTP-U echo-request */
	template Gtp1uUnitdata tr_GTPU_PING(template GtpPeer peer) := tr_GTPU_MsgType(peer, echoRequest, '00000000'O);

	/* template matching reception of GTP-U GPDU */
	template GTPU_IEs t_GPDU(template octetstring data) := {
		g_PDU_IEs := {
			data := data
		}
	}
	template Gtp1uUnitdata tr_GTPU_GPDU(template GtpPeer peer, template OCT4 teid, template octetstring data := ?) := {
		peer := peer,
		gtpu := tr_GTP1U_PDU('FF'O, teid, t_GPDU(data))
	}

	template GTPU_IEs ts_UEchoRespPDU(OCT1 restart_counter) := {
		echoResponse_IEs := {
			recovery_gtpu := {
				type_gtpu := '00'O, /* we assume encoder fixes? */
				restartCounter := restart_counter
			},
			private_extension_gtpu := omit
		}
	}

	/* master template for sending a GTP-U echo response */
	template Gtp1uUnitdata ts_GTPU_PONG(GtpPeer peer, uint16_t seq, OCT1 rest_ctr) := {
		peer := peer,
		gtpu := ts_GTP1U_PDU(echoResponse, seq, '00000000'O, valueof(ts_UEchoRespPDU(rest_ctr)))
	}

	template GSNAddress_gtpu ts_UGsnAddr(octetstring ip_addr) := {
		type_gtpu := '85'O,
		lengthf := lengthof(ip_addr),
		gSNAddressValue := ip_addr
	}

	template TeidDataI_gtpu ts_UteidDataI(OCT4 teid) := {
		type_gtpu := '10'O,
		teidDataI := teid
	}

	template GTPU_IEs ts_UErrorIndication(OCT4 teid, octetstring gsn_addr) := {
		errorIndication_IEs := {
			teidDataI_gtpu := ts_UteidDataI(teid),
			gSNAddress_gtpu := ts_UGsnAddr(gsn_addr),
			private_extension_gtpu := omit
		}
	}

	/* master template for sending a GTP-U Error indication */
	template Gtp1uUnitdata ts_GTPU_ErrorIndication(GtpPeer peer, uint16_t seq, OCT4 teid, octetstring gsn_addr) := {
		peer := peer,
		gtpu := ts_GTP1U_PDU('1A'O, seq, '00000000'O, valueof(ts_UErrorIndication(teid, gsn_addr)))
	}

	/* master template for sending a GTP-U user plane data */
	template Gtp1uUnitdata ts_GTP1U_GPDU(GtpPeer peer, template (omit) uint16_t seq, OCT4 teid, octetstring data) := {
		peer := peer,
		gtpu := ts_GTP1U_PDU('FF'O, seq, teid, { g_PDU_IEs := { data := data }})
	}
}