Pau Espin Pedrol | 4b090c9 | 2024-02-29 19:47:07 +0100 | [diff] [blame] | 1 | /* GTPv1-U Templates in TTCN-3 |
| 2 | * (C) 2018 Harald Welte <laforge@gnumonks.org> |
| 3 | * contributions by sysmocom - s.f.m.c. GmbH |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Released under the terms of GNU General Public License, Version 2 or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 10 | */ |
| 11 | |
| 12 | module GTPv1U_Templates { |
| 13 | |
| 14 | import from General_Types all; |
| 15 | import from Osmocom_Types all; |
| 16 | import from GTPU_Types all; |
| 17 | import from GTPv1U_CodecPort all; |
| 18 | |
| 19 | template (present) PDU_GTPU tr_GTP1U_PDU(template (present) OCT1 msg_type, |
| 20 | template (present) OCT4 teid, |
| 21 | template (present) GTPU_IEs ies := ?) := { |
| 22 | pn_bit := ?, |
| 23 | s_bit := ?, |
| 24 | e_bit := ?, |
| 25 | spare := ?, |
| 26 | /* Protocol Type flag (PT) shall be set to '1' in GTP */ |
| 27 | pt := '1'B, |
| 28 | /* Version shall be set to decimal 1 ('001'). */ |
| 29 | version := '001'B, |
| 30 | messageType := msg_type, |
| 31 | lengthf := ?, |
| 32 | teid := teid, |
| 33 | opt_part := *, |
| 34 | gtpu_IEs := ies |
| 35 | } |
| 36 | |
| 37 | function f_GTPU_s_bit(template (omit) uint16_t seq) return BIT1 { |
| 38 | if (istemplatekind(seq, "omit")) { |
| 39 | return '0'B; |
| 40 | } |
| 41 | return '1'B; |
| 42 | } |
| 43 | |
| 44 | function f_GTPU_opt_part(template (omit) uint16_t seq) return template (omit) GTPU_Header_optional_part { |
| 45 | if (istemplatekind(seq, "omit")) { |
| 46 | return omit; |
| 47 | } |
| 48 | var GTPU_Header_optional_part ret := { |
| 49 | sequenceNumber := int2oct(valueof(seq), 2), |
| 50 | npduNumber := '00'O, |
| 51 | nextExtHeader := '00'O, |
| 52 | gTPU_extensionHeader_List := omit |
| 53 | }; |
| 54 | return ret; |
| 55 | } |
| 56 | |
| 57 | /* generalized GTP-U send template */ |
| 58 | template (value) PDU_GTPU ts_GTP1U_PDU(OCT1 msg_type, template (omit) uint16_t seq, OCT4 teid, GTPU_IEs ies) := { |
| 59 | /* N-PDU Number flag (PN): the GTP-U header contains a meaningful N-PDU Number field if the PN |
| 60 | * flag is set to 1. */ |
| 61 | pn_bit := '0'B, /* we assume the encoder overwrites this if an optional part is given */ |
| 62 | /* If the Sequence Number flag (S) is set to '1' the sequence number field is present and |
| 63 | * meaningful otherwise it is set to '0'. For GTP-U messages Echo Request, Echo Response, |
| 64 | * Error Indication and Supported Extension Headers Notification, the S flag shall be set to '1'. |
| 65 | * |
| 66 | * Note that the caller must ensure that these conditions hold. |
| 67 | * The caller can either pass a sequence number (we set s_bit to '1'B) when appropriate, |
| 68 | * or may omit the sequence number (we set s_bit to '0'B). */ |
| 69 | s_bit := f_GTPU_s_bit(seq), |
| 70 | /* Extension header presence */ |
| 71 | e_bit := '0'B, |
| 72 | spare := '0'B, |
| 73 | /* Protocol Type flag (PT) shall be set to '1' in GTP */ |
| 74 | pt := '1'B, |
| 75 | /* Version shall be set to decimal 1 ('001'). */ |
| 76 | version := '001'B, |
| 77 | messageType := msg_type, |
| 78 | lengthf := 0, /* we assume encoder overwrites this */ |
| 79 | teid := teid, |
| 80 | opt_part := f_GTPU_opt_part(seq), |
| 81 | gtpu_IEs := ies |
| 82 | } |
| 83 | |
| 84 | template (present) Gtp1uUnitdata tr_GTPU_MsgType(template (present) Gtp1uPeer peer, |
| 85 | template (present) OCT1 msg_type, |
| 86 | template (present) OCT4 teid) := { |
| 87 | peer := peer, |
| 88 | gtpu := tr_GTP1U_PDU(msg_type, teid) |
| 89 | } |
| 90 | |
| 91 | |
| 92 | /* template matching reception of GTP-U echo-request/response */ |
| 93 | template (present) Gtp1uUnitdata tr_GTPU_PING(template (present) Gtp1uPeer peer) := tr_GTPU_MsgType(peer, '01'O, '00000000'O); |
| 94 | template (present) Gtp1uUnitdata tr_GTPU_PONG(template (present) Gtp1uPeer peer) := tr_GTPU_MsgType(peer, '02'O, '00000000'O); |
| 95 | |
| 96 | /* template matching reception of GTP-U GPDU */ |
| 97 | template GTPU_IEs t_GPDU(template (present) octetstring data) := { |
| 98 | g_PDU_IEs := { |
| 99 | data := data |
| 100 | } |
| 101 | } |
| 102 | template (present) Gtp1uUnitdata tr_GTPU_GPDU(template (present) Gtp1uPeer peer, |
| 103 | template (present) OCT4 teid, |
| 104 | template (present) octetstring data := ?) := { |
| 105 | peer := peer, |
| 106 | gtpu := tr_GTP1U_PDU('FF'O, teid, t_GPDU(data)) |
| 107 | } |
| 108 | |
| 109 | template (present) GTPU_IEs ts_UEchoReqPDU := { |
| 110 | echoRequest_IEs := { |
| 111 | private_extension_gtpu := omit |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /* master template for sending a GTP-C echo request */ |
| 116 | template (value) Gtp1uUnitdata ts_GTPU_PING(Gtp1uPeer peer, uint16_t seq) := { |
| 117 | peer := peer, |
| 118 | gtpu := ts_GTP1U_PDU('01'O, seq, '00000000'O, valueof(ts_UEchoReqPDU)) |
| 119 | } |
| 120 | |
| 121 | template GTPU_IEs ts_UEchoRespPDU(OCT1 restart_counter) := { |
| 122 | echoResponse_IEs := { |
| 123 | recovery_gtpu := { |
| 124 | type_gtpu := '00'O, /* we assume encoder fixes? */ |
| 125 | restartCounter := restart_counter |
| 126 | }, |
| 127 | private_extension_gtpu := omit |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | /* master template for sending a GTP-U echo response */ |
| 132 | template (present) Gtp1uUnitdata ts_GTPU_PONG(Gtp1uPeer peer, uint16_t seq, OCT1 rest_ctr) := { |
| 133 | peer := peer, |
| 134 | gtpu := ts_GTP1U_PDU('02'O, seq, '00000000'O, valueof(ts_UEchoRespPDU(rest_ctr))) |
| 135 | } |
| 136 | |
| 137 | template (value) GSNAddress_gtpu ts_UGsnAddr(octetstring ip_addr) := { |
| 138 | type_gtpu := '85'O, |
| 139 | lengthf := lengthof(ip_addr), |
| 140 | gSNAddressValue := ip_addr |
| 141 | } |
| 142 | |
| 143 | template (value) TeidDataI_gtpu ts_UteidDataI(OCT4 teid) := { |
| 144 | type_gtpu := '10'O, |
| 145 | teidDataI := teid |
| 146 | } |
| 147 | |
| 148 | template (value) GTPU_IEs ts_UErrorIndication(OCT4 teid, octetstring gsn_addr) := { |
| 149 | errorIndication_IEs := { |
| 150 | teidDataI_gtpu := ts_UteidDataI(teid), |
| 151 | gSNAddress_gtpu := ts_UGsnAddr(gsn_addr), |
| 152 | private_extension_gtpu := omit |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /* master template for sending a GTP-U Error indication */ |
| 157 | template (value) Gtp1uUnitdata ts_GTPU_ErrorIndication(Gtp1uPeer peer, uint16_t seq, OCT4 teid, octetstring gsn_addr) := { |
| 158 | peer := peer, |
| 159 | gtpu := ts_GTP1U_PDU('1A'O, seq, '00000000'O, valueof(ts_UErrorIndication(teid, gsn_addr))) |
| 160 | } |
| 161 | |
| 162 | /* master template for sending a GTP-U user plane data */ |
| 163 | template (value) Gtp1uUnitdata ts_GTP1U_GPDU(Gtp1uPeer peer, template (omit) uint16_t seq, OCT4 teid, octetstring data) := { |
| 164 | peer := peer, |
| 165 | gtpu := ts_GTP1U_PDU('FF'O, seq, teid, { g_PDU_IEs := { data := data }}) |
| 166 | } |
| 167 | } |