Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 1 | /* MME (Mobility Management Engine) test suite in TTCN-3 |
| 2 | * (C) 2019 Harald Welte <laforge@gnumonks.org> |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Released under the terms of GNU General Public License, Version 2 or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 9 | */ |
| 10 | |
| 11 | module MME_Tests { |
| 12 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 13 | import from General_Types all; |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 14 | import from Native_Functions all; |
| 15 | import from IPL4asp_Types all; |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 16 | import from Misc_Helpers all; |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 17 | import from S1AP_Types all; |
| 18 | import from S1AP_Templates all; |
| 19 | import from S1AP_Emulation all; |
| 20 | import from S1AP_PDU_Descriptions all; |
| 21 | import from S1AP_IEs all; |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 22 | import from S1AP_PDU_Contents all; |
| 23 | import from S1AP_Constants all; |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 24 | |
| 25 | import from NAS_EPS_Types all; |
| 26 | import from NAS_Templates all; |
| 27 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 28 | import from DIAMETER_Types all; |
| 29 | import from DIAMETER_Templates all; |
Pau Espin Pedrol | 117a94f | 2023-12-21 16:10:12 +0100 | [diff] [blame] | 30 | import from DIAMETER_ts29_272_Templates all; |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 31 | import from DIAMETER_Emulation all; |
| 32 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 33 | import from SGsAP_Types all; |
| 34 | import from SGsAP_Templates all; |
| 35 | import from SGsAP_Emulation all; |
| 36 | |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 37 | import from GTP_Emulation all; |
| 38 | import from GTP_Templates all; |
| 39 | import from GTP_CodecPort all; |
| 40 | import from GTPC_Types all; |
| 41 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 42 | import from LTE_CryptoFunctions all; |
| 43 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 44 | import from L3_Templates all; |
| 45 | import from DNS_Helpers all; |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 46 | import from Osmocom_Types all; |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 47 | import from Osmocom_Gb_Types all; |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 48 | |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 49 | import from GTPv2_Types all; |
| 50 | import from GTPv2_Templates all; |
| 51 | import from GTPv2_Emulation all; |
| 52 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 53 | friend module MME_Tests_SGsAP; |
| 54 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 55 | /* (maximum) number of emulated eNBs */ |
| 56 | const integer NUM_ENB := 3; |
| 57 | |
| 58 | /* (maximum) number of emulated UEs */ |
| 59 | const integer NUM_UE := 3; |
| 60 | |
| 61 | /* parameters of emulated ENB */ |
| 62 | type record EnbParams { |
| 63 | Global_ENB_ID global_enb_id, |
| 64 | integer cell_identity, |
| 65 | SupportedTAs supported_tas |
| 66 | } |
| 67 | |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 68 | type record BearerConfig { |
| 69 | /* EPS Bearer ID */ |
| 70 | uint4_t ebi optional, |
| 71 | /* TEI (Data) local side, S11 (SGW) */ |
| 72 | OCT4 s11_teid_local optional, |
| 73 | /* TEI (Data) remote side, S11 (SGW) */ |
| 74 | OCT4 s11_teid_remote optional, |
| 75 | /* TEI (Data) local side, S5c (PGW) */ |
| 76 | OCT4 s5c_teid_local optional, |
| 77 | /* TEI (Data) remote side, S5c (PGW) */ |
| 78 | OCT4 s5c_teid_remote optional |
| 79 | }; |
| 80 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 81 | /* parameters of emulated UE */ |
| 82 | type record UeParams { |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 83 | hexstring imsi, |
| 84 | charstring ue_ip, |
Pau Espin Pedrol | 408e0ae | 2023-12-15 18:56:31 +0100 | [diff] [blame] | 85 | NAS_EPS_Types.GUTI guti optional, |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 86 | |
| 87 | /* TEI (Control) local side, S11 (SGW) */ |
| 88 | OCT4 s11_teic_local, |
| 89 | /* TEI (Control) remote side, S11 (SGW) */ |
| 90 | OCT4 s11_teic_remote optional, |
| 91 | /* TEI (Control) local side, S5c (PGW) */ |
| 92 | OCT4 s5c_teic_local, |
| 93 | /* TEI (Control) remote side, S5c (PGW) */ |
| 94 | OCT4 s5c_teic_remote optional, |
| 95 | |
| 96 | BearerConfig bearer optional |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 97 | } |
| 98 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 99 | type component MTC_CT { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 100 | /* S1 intreface of emulated ENBs */ |
| 101 | var EnbParams g_enb_pars[NUM_ENB]; |
| 102 | var S1AP_Emulation_CT vc_S1AP[NUM_ENB]; |
| 103 | port S1AP_PT S1AP_UNIT[NUM_ENB]; |
| 104 | port S1APEM_PROC_PT S1AP_PROC[NUM_ENB]; |
| 105 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 106 | /* S6a/S6d interface of emulated HSS */ |
| 107 | var DIAMETER_Emulation_CT vc_DIAMETER; |
| 108 | port DIAMETER_PT DIAMETER_UNIT; |
| 109 | port DIAMETEREM_PROC_PT DIAMETER_PROC; |
| 110 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 111 | /* SGs interface of emulated MSC/VLR */ |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 112 | var SGsAP_Emulation_CT vc_SGsAP; |
| 113 | port SGsAP_PT SGsAP_UNIT; |
| 114 | port SGsAPEM_PROC_PT SGsAP_PROC; |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 115 | |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 116 | /* Gn interface (GTPv1C) of emulated SGSN (Rel. 7) */ |
| 117 | var GTP_Emulation_CT vc_GTP; |
| 118 | |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 119 | /* S11 interface (GTPv2C) of emulated SGW-C */ |
| 120 | var GTPv2_Emulation_CT vc_GTP2; |
| 121 | port GTP2EM_PT TEID0; |
| 122 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 123 | var UeParams g_ue_pars[NUM_UE]; |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 124 | } |
| 125 | |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 126 | /* Encode an S1AP Global-ENB-ID into an octetstring */ |
| 127 | private function enc_S1AP_Global_ENB_ID(Global_ENB_ID global_enb_id) return octetstring { |
| 128 | |
| 129 | /* Due to the limitations of libfftranscode, we can not define encoders (or decoders) for individual |
| 130 | * information elements (in S1AP_Types.cc). Unfortuantely Global-ENB-ID also appears in BSSGP in its |
| 131 | * encoded form. (see also: GTP-C 3GPP TS 48.018, section 11.3.70). To encode a given Global-ENB-ID |
| 132 | * we craft a full S1AP PDU and encode it. Then we can cut out the encoded Global-ENB-ID from the |
| 133 | * generated octetstring. */ |
| 134 | |
| 135 | var SupportedTAs supported_tas_dummy := {{ |
| 136 | tAC := '0000'O, |
| 137 | broadcastPLMNs := { '00f000'O }, |
| 138 | iE_Extensions := omit |
| 139 | }}; |
| 140 | var octetstring encoded; |
| 141 | var integer global_enb_id_len; |
| 142 | |
| 143 | if (ispresent(global_enb_id.eNB_ID.macroENB_ID)) { |
| 144 | global_enb_id_len := 8; |
| 145 | } else { |
| 146 | /* All other ENB ID types fit into 8 byte (homeENB_ID, short_macroENB_ID, long_macroENB_ID) */ |
| 147 | global_enb_id_len := 9; |
| 148 | } |
| 149 | |
| 150 | encoded := enc_S1AP_PDU(valueof(ts_S1AP_SetupReq(global_enb_id, supported_tas_dummy, v32))); |
| 151 | |
| 152 | return substr(encoded, 11, global_enb_id_len); |
| 153 | } |
| 154 | |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 155 | type component ConnHdlr extends S1AP_ConnHdlr, SGsAP_ConnHdlr, DIAMETER_ConnHdlr, GTP_ConnHdlr, GTP2_ConnHdlr { |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 156 | var ConnHdlrPars g_pars; |
| 157 | timer g_Tguard := 30.0; |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 158 | |
Pau Espin Pedrol | cc9b804 | 2023-09-21 17:45:11 +0200 | [diff] [blame] | 159 | var GtpPeer g_gn_iface_peer := { connId := 1, remName := mp_gn_remote_ip, remPort := mp_gn_remote_port }; |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | type record ConnHdlrPars { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 163 | /* copied over from MTC_CT on start of component */ |
| 164 | EnbParams enb_pars[NUM_ENB], |
| 165 | /* copied over from MTC_CT on start of component */ |
| 166 | UeParams ue_pars, |
| 167 | /* currently used MME (index into enb_pars, S1AP, ...) */ |
| 168 | integer mme_idx |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | modulepar { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 172 | /* S1 interface */ |
| 173 | charstring mp_mme_ip := "127.0.0.1"; |
| 174 | integer mp_mme_s1ap_port := 36412; |
| 175 | charstring mp_s1_local_ip := "127.0.0.1"; |
| 176 | integer mp_s1_local_port := 50000; |
| 177 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 178 | /* S6 interface */ |
| 179 | charstring mp_s6_local_ip := "127.0.0.4"; |
| 180 | integer mp_s6_local_port := 3868; |
Pau Espin Pedrol | 35c0cc2 | 2023-12-21 19:23:48 +0100 | [diff] [blame] | 181 | charstring mp_s6_diam_realm := "localdomain"; |
| 182 | charstring mp_s6_local_diam_host := "hss.localdomain"; |
| 183 | charstring mp_s6_remote_diam_host := "mme.localdomain"; |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 184 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 185 | /* SGs interface */ |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 186 | charstring mp_sgs_local_ip := "127.0.0.1"; |
| 187 | integer mp_sgs_local_port := 29118; |
| 188 | charstring mp_vlr_name := "vlr.example.net"; |
| 189 | charstring mp_mme_name := "mmec01.mmegi0001.mme.epc.mnc070.mcc901.3gppnetwork.org"; |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 190 | |
| 191 | /* Gn interface (GTPv1C) */ |
| 192 | charstring mp_gn_local_ip := "127.0.0.22"; |
| 193 | integer mp_gn_local_port := 2123; |
| 194 | charstring mp_gn_remote_ip := "127.0.0.2"; |
Pau Espin Pedrol | 1162585 | 2023-12-22 14:20:42 +0100 | [diff] [blame] | 195 | /* RAI+CI served from emulated peer SGSN: */ |
Pau Espin Pedrol | cc9b804 | 2023-09-21 17:45:11 +0200 | [diff] [blame] | 196 | integer mp_gn_remote_port := 2123; |
Pau Espin Pedrol | 1162585 | 2023-12-22 14:20:42 +0100 | [diff] [blame] | 197 | hexstring mp_gn_local_mcc := '262'H; |
| 198 | hexstring mp_gn_local_mnc := 'f42'H; |
Pau Espin Pedrol | 209d0a4 | 2023-12-22 14:22:40 +0100 | [diff] [blame] | 199 | uint16_t mp_gn_local_lac := 39594; |
Pau Espin Pedrol | 1162585 | 2023-12-22 14:20:42 +0100 | [diff] [blame] | 200 | uint8_t mp_gn_local_rac := 187; |
| 201 | uint16_t mp_gn_local_ci := 1223; |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 202 | |
| 203 | /* S11 interface (GTPv2C, interface between MME and SGW) */ |
| 204 | charstring mp_s11_local_ip := "127.0.0.3"; |
| 205 | integer mp_s11_local_port := 2123; |
| 206 | charstring mp_s11_remote_ip := "127.0.0.2"; |
| 207 | integer mp_s11_remote_port := 2123; |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 208 | |
| 209 | /* PGW information announced by SGWC. MME never really interacts with these. */ |
| 210 | charstring mp_s5c_pgw_ip := "1.2.3.4"; |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /* send incoming unit data messages (like reset) to global SGsAP_UNIT port */ |
| 214 | friend function ForwardUnitdataCallback(PDU_SGsAP msg) |
| 215 | runs on SGsAP_Emulation_CT return template PDU_SGsAP { |
| 216 | SGsAP_UNIT.send(msg); |
| 217 | return omit; |
| 218 | } |
| 219 | |
| 220 | friend function f_init_sgsap(charstring id) runs on MTC_CT { |
| 221 | id := id & "-SGsAP"; |
| 222 | var SGsAPOps ops := { |
| 223 | create_cb := refers(SGsAP_Emulation.ExpectedCreateCallback), |
| 224 | unitdata_cb := refers(ForwardUnitdataCallback) |
| 225 | } |
| 226 | var SGsAP_conn_parameters pars := { |
| 227 | remote_ip := "", |
| 228 | remote_sctp_port := -1, |
| 229 | local_ip := mp_sgs_local_ip, |
| 230 | local_sctp_port := mp_sgs_local_port |
| 231 | } |
| 232 | |
| 233 | vc_SGsAP := SGsAP_Emulation_CT.create(id); |
| 234 | map(vc_SGsAP:SGsAP, system:SGsAP_CODEC_PT); |
| 235 | connect(vc_SGsAP:SGsAP_PROC, self:SGsAP_PROC); |
| 236 | connect(vc_SGsAP:SGsAP_UNIT, self:SGsAP_UNIT); |
| 237 | vc_SGsAP.start(SGsAP_Emulation.main(ops, pars, id)); |
| 238 | } |
| 239 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 240 | /* send incoming unit data messages (like reset) to global S1AP_UNIT port */ |
| 241 | friend function S1apForwardUnitdataCallback(S1AP_PDU msg) |
| 242 | runs on S1AP_Emulation_CT return template S1AP_PDU { |
| 243 | S1AP_UNIT.send(msg); |
| 244 | return omit; |
| 245 | } |
| 246 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 247 | friend function f_init_one_enb(charstring id, integer num := 0) runs on MTC_CT { |
| 248 | id := id & "-S1AP" & int2str(num); |
| 249 | var S1APOps ops := { |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 250 | create_cb := refers(S1AP_Emulation.ExpectedCreateCallback), |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 251 | unitdata_cb := refers(S1apForwardUnitdataCallback) |
| 252 | } |
| 253 | var S1AP_conn_parameters pars := { |
| 254 | remote_ip := mp_mme_ip, |
| 255 | remote_sctp_port := mp_mme_s1ap_port, |
| 256 | local_ip := mp_s1_local_ip, |
| 257 | local_sctp_port := mp_s1_local_port + num, |
| 258 | role := NAS_ROLE_UE |
| 259 | } |
| 260 | var PLMNidentity plmn_id := '00f110'O; |
| 261 | var EnbParams enb_pars := { |
| 262 | global_enb_id := { |
| 263 | pLMNidentity := plmn_id, |
| 264 | eNB_ID := { |
| 265 | macroENB_ID := int2bit(num, 20) |
| 266 | }, |
| 267 | iE_Extensions := omit |
| 268 | }, |
| 269 | cell_identity := num, |
| 270 | supported_tas := { |
| 271 | { |
| 272 | tAC := int2oct(12345, 2), |
| 273 | broadcastPLMNs := { plmn_id }, |
| 274 | iE_Extensions := omit |
| 275 | } |
| 276 | } |
| 277 | }; |
| 278 | |
| 279 | g_enb_pars[num] := enb_pars; |
| 280 | vc_S1AP[num] := S1AP_Emulation_CT.create(id); |
| 281 | map(vc_S1AP[num]:S1AP, system:S1AP_CODEC_PT); |
| 282 | connect(vc_S1AP[num]:S1AP_PROC, self:S1AP_PROC[num]); |
| 283 | connect(vc_S1AP[num]:S1AP_UNIT, self:S1AP_UNIT[num]); |
| 284 | vc_S1AP[num].start(S1AP_Emulation.main(ops, pars, id)); |
| 285 | S1AP_UNIT[num].receive(S1APEM_Event:{up_down:=S1APEM_EVENT_UP}); |
| 286 | } |
| 287 | friend function f_init_one_ue(inout UeParams uep, integer imsi_suffix) { |
| 288 | uep := { |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 289 | imsi := f_gen_imsi(imsi_suffix), |
| 290 | ue_ip := "192.168.123.50", |
Pau Espin Pedrol | 408e0ae | 2023-12-15 18:56:31 +0100 | [diff] [blame] | 291 | guti := omit, |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 292 | s11_teic_local := '00000000'O, |
| 293 | s11_teic_remote := omit, |
| 294 | s5c_teic_local := '00000000'O, |
| 295 | s5c_teic_remote := omit, |
| 296 | bearer := { |
| 297 | ebi := omit, |
| 298 | s11_teid_local := omit, |
| 299 | s11_teid_remote := omit, |
| 300 | s5c_teid_local := omit, |
| 301 | s5c_teid_remote := omit |
| 302 | } |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | friend function f_init_s1ap(charstring id, integer imsi_suffix) runs on MTC_CT { |
| 306 | var integer i; |
| 307 | for (i := 0; i < NUM_ENB; i := i+1) { |
| 308 | f_init_one_enb(id, i); |
| 309 | } |
| 310 | for (i := 0; i < NUM_UE; i := i+1) { |
| 311 | f_init_one_ue(g_ue_pars[i], i*1000 + imsi_suffix); |
| 312 | } |
| 313 | } |
| 314 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 315 | friend function DiameterForwardUnitdataCallback(PDU_DIAMETER msg) |
| 316 | runs on DIAMETER_Emulation_CT return template PDU_DIAMETER { |
| 317 | DIAMETER_UNIT.send(msg); |
| 318 | return omit; |
| 319 | } |
| 320 | |
| 321 | friend function f_init_diameter(charstring id) runs on MTC_CT { |
| 322 | var DIAMETEROps ops := { |
| 323 | create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback), |
Vadim Yanitskiy | b46f01e | 2021-12-06 03:23:13 +0300 | [diff] [blame] | 324 | unitdata_cb := refers(DiameterForwardUnitdataCallback), |
| 325 | raw := false /* handler mode (IMSI based routing) */ |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 326 | }; |
| 327 | var DIAMETER_conn_parameters pars := { |
| 328 | remote_ip := mp_mme_ip, |
| 329 | remote_sctp_port := -1, |
| 330 | local_ip := mp_s6_local_ip, |
Harald Welte | 61f73d5 | 2020-04-26 21:41:12 +0200 | [diff] [blame] | 331 | local_sctp_port := mp_s6_local_port, |
| 332 | origin_host := "hss.localdomain", |
| 333 | origin_realm := "localdomain", |
Pau Espin Pedrol | 33b4749 | 2022-03-08 17:43:01 +0100 | [diff] [blame] | 334 | auth_app_id := omit, |
Harald Welte | 61f73d5 | 2020-04-26 21:41:12 +0200 | [diff] [blame] | 335 | vendor_app_id := c_DIAMETER_3GPP_S6_AID |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 336 | }; |
| 337 | vc_DIAMETER := DIAMETER_Emulation_CT.create(id); |
| 338 | map(vc_DIAMETER:DIAMETER, system:DIAMETER_CODEC_PT); |
| 339 | connect(vc_DIAMETER:DIAMETER_UNIT, self:DIAMETER_UNIT); |
| 340 | connect(vc_DIAMETER:DIAMETER_PROC, self:DIAMETER_PROC); |
| 341 | vc_DIAMETER.start(DIAMETER_Emulation.main(ops, pars, id)); |
Harald Welte | d01b5d0 | 2020-04-26 22:05:53 +0200 | [diff] [blame] | 342 | |
| 343 | f_diameter_wait_capability(DIAMETER_UNIT); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 344 | } |
| 345 | |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 346 | friend function f_init_gtp(charstring id) runs on MTC_CT { |
| 347 | id := id & "-GTP"; |
| 348 | |
| 349 | var GtpEmulationCfg gtp_cfg := { |
| 350 | gtpc_bind_ip := mp_gn_local_ip, |
| 351 | gtpc_bind_port := mp_gn_local_port, |
| 352 | gtpu_bind_ip := omit, |
| 353 | gtpu_bind_port := omit, |
| 354 | sgsn_role := true |
| 355 | }; |
| 356 | |
| 357 | vc_GTP := GTP_Emulation_CT.create(id); |
| 358 | vc_GTP.start(GTP_Emulation.main(gtp_cfg)); |
| 359 | } |
| 360 | |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 361 | friend function f_init_gtpv2_s11(charstring id) runs on MTC_CT { |
| 362 | id := id & "-GTPV2"; |
| 363 | |
| 364 | var Gtp2EmulationCfg cfg := { |
| 365 | gtpc_bind_ip := mp_s11_local_ip, |
| 366 | gtpc_bind_port := mp_s11_local_port, |
| 367 | gtpc_remote_ip := mp_s11_remote_ip, |
| 368 | gtpc_remote_port := mp_s11_remote_port, |
| 369 | sgw_role := true, |
| 370 | use_gtpu_daemon := false |
| 371 | }; |
| 372 | |
| 373 | vc_GTP2 := GTPv2_Emulation_CT.create(id); |
| 374 | map(vc_GTP2:GTP2C, system:GTP2C); |
| 375 | connect(vc_GTP2:TEID0, self:TEID0); |
| 376 | vc_GTP2.start(GTPv2_Emulation.main(cfg)); |
| 377 | } |
| 378 | |
| 379 | friend template (value) S1AP_IEs.TAI ts_enb_S1AP_TAI(EnbParams enb) := { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 380 | pLMNidentity := enb.global_enb_id.pLMNidentity, |
| 381 | tAC := enb.supported_tas[0].tAC, |
| 382 | iE_Extensions := omit |
| 383 | } |
| 384 | |
| 385 | friend template (value) EUTRAN_CGI ts_enb_S1AP_CGI(EnbParams enb) := { |
| 386 | pLMNidentity := enb.global_enb_id.pLMNidentity, |
| 387 | cell_ID := int2bit(enb.cell_identity, 28), |
| 388 | iE_Extensions := omit |
| 389 | } |
| 390 | |
| 391 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 392 | /* generate parameters for a connection handler */ |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 393 | friend function f_init_pars(integer ue_idx := 0) |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 394 | runs on MTC_CT return ConnHdlrPars { |
| 395 | var ConnHdlrPars pars := { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 396 | enb_pars := g_enb_pars, |
| 397 | ue_pars := g_ue_pars[ue_idx], |
| 398 | mme_idx := 0 |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 399 | }; |
| 400 | return pars; |
| 401 | } |
| 402 | |
| 403 | type function void_fn(ConnHdlrPars pars) runs on ConnHdlr; |
| 404 | |
| 405 | /* start a connection handler with given parameters */ |
| 406 | friend function f_start_handler_with_pars(void_fn fn, ConnHdlrPars pars, integer s1ap_idx := 0) |
| 407 | runs on MTC_CT return ConnHdlr { |
| 408 | var ConnHdlr vc_conn; |
| 409 | var charstring id := testcasename() & int2str(s1ap_idx); |
| 410 | |
| 411 | vc_conn := ConnHdlr.create(id); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 412 | /* S1AP part */ |
| 413 | connect(vc_conn:S1AP, vc_S1AP[s1ap_idx]:S1AP_CLIENT); |
| 414 | connect(vc_conn:S1AP_PROC, vc_S1AP[s1ap_idx]:S1AP_PROC); |
| 415 | if (isbound(vc_SGsAP)) { |
| 416 | /* SGsAP part */ |
| 417 | connect(vc_conn:SGsAP, vc_SGsAP:SGsAP_CLIENT); |
| 418 | connect(vc_conn:SGsAP_PROC, vc_SGsAP:SGsAP_PROC); |
| 419 | } |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 420 | if (isbound(vc_DIAMETER)) { |
| 421 | connect(vc_conn:DIAMETER, vc_DIAMETER:DIAMETER_CLIENT); |
| 422 | connect(vc_conn:DIAMETER_PROC, vc_DIAMETER:DIAMETER_PROC); |
| 423 | } |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 424 | if (isbound(vc_GTP)) { |
| 425 | connect(vc_conn:GTP, vc_GTP:CLIENT); |
| 426 | connect(vc_conn:GTP_PROC, vc_GTP:CLIENT_PROC); |
| 427 | } |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 428 | if (isbound(vc_GTP2)) { |
| 429 | connect(vc_conn:GTP2, vc_GTP2:CLIENT); |
| 430 | connect(vc_conn:GTP2_PROC, vc_GTP2:CLIENT_PROC); |
| 431 | } |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 432 | |
| 433 | /* We cannot use vc_conn.start(f_init_handler(fn, id, pars)); as we cannot have |
| 434 | * a stand-alone 'derefers()' call, see https://www.eclipse.org/forums/index.php/t/1091364/ */ |
| 435 | vc_conn.start(derefers(fn)(pars)); |
| 436 | return vc_conn; |
| 437 | } |
| 438 | |
| 439 | /* altstep for the global guard timer */ |
| 440 | private altstep as_Tguard()runs on ConnHdlr { |
| 441 | [] g_Tguard.timeout { |
| 442 | setverdict(fail, "Tguard timeout"); |
| 443 | mtc.stop; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | friend function f_init_handler(ConnHdlrPars pars, float t_guard := 30.0) runs on ConnHdlr { |
| 448 | /* make parameters available via component variable */ |
| 449 | g_pars := pars; |
| 450 | /* start guard timre and activate it as default */ |
| 451 | g_Tguard.start(t_guard); |
| 452 | activate(as_Tguard()); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 453 | if (DIAMETER_PROC.checkstate("Connected")) { |
Pau Espin Pedrol | db017f4 | 2023-08-25 19:22:25 +0200 | [diff] [blame] | 454 | f_diameter_expect_imsi(g_pars.ue_pars.imsi); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 455 | } |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 456 | if (SGsAP_PROC.checkstate("Connected")) { |
| 457 | /* Route all SGsAP mesages for our IMSIto us */ |
| 458 | f_create_sgsap_expect(pars.ue_pars.imsi); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | |
| 463 | |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 464 | friend function f_s1ap_setup(integer idx := 0, template S1AP_IEs.Cause cause := omit) runs on MTC_CT { |
| 465 | var template (present) S1AP_IEs.Cause exp_cause; |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 466 | var boolean exp_fail := false; |
| 467 | timer T := 5.0; |
| 468 | if (not istemplatekind(cause, "omit")) { |
| 469 | exp_fail := true; |
| 470 | exp_cause := cause; |
| 471 | } |
| 472 | |
| 473 | S1AP_UNIT[idx].send(ts_S1AP_SetupReq(g_enb_pars[idx].global_enb_id, |
| 474 | g_enb_pars[idx].supported_tas, v32)); |
| 475 | T.start; |
| 476 | alt { |
| 477 | [exp_fail] S1AP_UNIT[idx].receive(tr_S1AP_SetupFail(exp_cause)) { |
| 478 | setverdict(pass); |
| 479 | } |
| 480 | [not exp_fail] S1AP_UNIT[idx].receive(tr_S1AP_SetupResp) { |
| 481 | setverdict(pass); |
| 482 | } |
| 483 | [] S1AP_UNIT[idx].receive { |
| 484 | setverdict(fail, "Received unexpected S1AP"); |
| 485 | } |
| 486 | [] T.timeout { |
| 487 | setverdict(fail, "Timeout waiting for S1AP Setup result"); |
| 488 | } |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /* Unsuccessful S1 Setup procedure to MME (wrong PLMN) */ |
| 493 | testcase TC_s1ap_setup_wrong_plmn() runs on MTC_CT { |
| 494 | var charstring id := testcasename(); |
| 495 | f_init_s1ap(id, 1); |
| 496 | g_enb_pars[0].global_enb_id.pLMNidentity := '62F224'O; |
| 497 | f_s1ap_setup(0, {misc:=unknown_PLMN}); |
| 498 | } |
| 499 | |
| 500 | /* Unsuccessful S1 Setup procedure to MME (wrong PLMN) */ |
| 501 | testcase TC_s1ap_setup_wrong_tac() runs on MTC_CT { |
| 502 | var charstring id := testcasename(); |
| 503 | f_init_s1ap(id, 2); |
| 504 | g_enb_pars[0].supported_tas[0].broadcastPLMNs[0] := '62F224'O; |
| 505 | f_s1ap_setup(0, {misc:=unknown_PLMN}); |
| 506 | } |
| 507 | |
| 508 | /* Successful S1 Setup procedure to MME */ |
| 509 | testcase TC_s1ap_setup() runs on MTC_CT { |
| 510 | var charstring id := testcasename(); |
| 511 | f_init_s1ap(id, 3); |
| 512 | f_s1ap_setup(0); |
| 513 | } |
| 514 | |
| 515 | private const EPS_QualityOfServiceV c_NAS_defaultQoS := { |
| 516 | qCI := '00'O, |
| 517 | maxBitRateUplink := omit, |
| 518 | maxBitRateDownlink := omit, |
| 519 | guaranteedBitRateUplink := omit, |
| 520 | guaranteedBitRateDownlink := omit, |
| 521 | maxBitRateUplinkExt := omit, |
| 522 | maxBitRateDownlinkExt := omit, |
| 523 | guaranteedBitRateUplinkExt := omit, |
| 524 | guaranteedBitRateDownlinkExt := omit, |
| 525 | maxBitRateUplinkExt2 := omit, |
| 526 | maxBitRateDownlinkExt2 := omit, |
| 527 | guaranteedBitRateUplinkExt2 := omit, |
| 528 | guaranteedBitRateDownlinkExt2 := omit |
| 529 | }; |
| 530 | |
| 531 | private const UENetworkCapabilityV c_NAS_defaultUeNetCap := { |
| 532 | eEA := '10000000'B, |
| 533 | eIA := '11000000'B, |
| 534 | uEA := omit, |
| 535 | uIA := omit, |
| 536 | uCS2 := omit, |
| 537 | nF := omit, |
| 538 | vCC := omit, |
| 539 | lCS := omit, |
| 540 | lPP := omit, |
| 541 | aCC_CSFB := omit, |
| 542 | h245_ASH := omit, |
| 543 | proSe := omit, |
| 544 | proSe_dd := omit, |
| 545 | proSe_dc := omit, |
| 546 | proSe_relay := omit, |
| 547 | cP_CIoT := omit, |
| 548 | uP_CIoT := omit, |
| 549 | s1_Udata := omit, |
| 550 | eRwoPDN := omit, |
| 551 | hC_CP_CIoT := omit, |
| 552 | ePCO := omit, |
| 553 | multipleDRB := omit, |
| 554 | v2XPC5 := omit, |
| 555 | restrictEC := omit, |
| 556 | cPbackoff := omit, |
| 557 | dCNR := omit, |
| 558 | n1Mode := omit, |
| 559 | sGC := omit, |
| 560 | spare1 := omit, |
| 561 | spare := omit |
| 562 | }; |
| 563 | |
| 564 | private const octetstring c_NAS_defaultAPN := '00'O; |
| 565 | |
| 566 | private altstep as_s1ap_handle_auth() runs on ConnHdlr { |
| 567 | var PDU_NAS_EPS rx_nas; |
| 568 | [] S1AP.receive(tr_NAS_AuthReq) -> value rx_nas { |
| 569 | /* static XRES result as we fixed the HSS RAND value and always have the following |
| 570 | RAND: 20080c3818183b522614162c07601d0d |
| 571 | AUTN: f11b89a2a8be00001f9c526f3d75d44c |
| 572 | IK: 11329aae8e8d2941bb226b2061137c58 |
| 573 | CK: 740d62df9803eebde5120acf358433d0 |
| 574 | RES: 6a91970e838fd079 |
| 575 | SRES: e91e4777 |
| 576 | Kc: 3b0f999e42198874 |
| 577 | SQN: 32 |
| 578 | IND: 0 |
| 579 | */ |
| 580 | /* KASME: 95AFAD9A0D29AFAA079A9451DF7161D7EE4CBF2AF9387F766D058BB6B44B905D */ |
| 581 | const OCT16 ck := '740d62df9803eebde5120acf358433d0'O; |
| 582 | const OCT16 ik := '11329aae8e8d2941bb226b2061137c58'O; |
| 583 | const OCT16 autn := 'f11b89a2a8be00001f9c526f3d75d44c'O; |
| 584 | const OCT8 res := '6a91970e838fd079'O; |
| 585 | const OCT3 plmn_id := '00F110'O; |
| 586 | const OCT6 sqn := '000000000020'O; |
| 587 | const OCT6 ak := substr(autn, 0, 6) xor4b sqn; |
| 588 | var octetstring kasme := f_kdf_kasme(ck, ik, plmn_id, sqn, ak); |
| 589 | var S1APEM_Config cfg := { |
| 590 | set_nas_keys := { |
| 591 | k_nas_int := f_kdf_nas_int(1, kasme), |
| 592 | k_nas_enc := f_kdf_nas_enc(1, kasme) |
| 593 | } |
| 594 | }; |
| 595 | S1AP.send(cfg); |
| 596 | S1AP.send(ts_NAS_AuthResp(res)); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | private altstep as_s1ap_handle_sec_mode() runs on ConnHdlr { |
| 601 | var PDU_NAS_EPS rx_nas; |
| 602 | var NAS_SecurityAlgorithmsV alg := { |
| 603 | typeOfIntegrityProtection := '001'B, |
| 604 | spare1 := '0'B, |
| 605 | typeOfCiphering := '000'B, |
| 606 | spare2 := '0'B |
| 607 | }; |
| 608 | var NAS_KeySetIdentifierV kset_id := { |
| 609 | identifier := '000'B, |
| 610 | tSC := '0'B |
| 611 | }; |
| 612 | [] S1AP.receive(tr_NAS_SecModeCmd(alg, kset_id, ?)) { |
| 613 | S1AP.send(ts_NAS_SecModeCmpl); |
| 614 | } |
| 615 | } |
| 616 | |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 617 | |
| 618 | private altstep as_s1ap_handle_IntialCtxSetupReq() runs on ConnHdlr { |
| 619 | var S1AP_PDU rx_msg; |
| 620 | var PDU_NAS_EPS rx_nas; |
| 621 | [] S1AP.receive(tr_S1AP_IntialCtxSetupReq) -> value rx_msg { |
| 622 | var template (omit) MME_UE_S1AP_ID mme_ue_id := f_S1AP_get_MME_UE_S1AP_ID(rx_msg); |
| 623 | var template (omit) ENB_UE_S1AP_ID enb_ue_id := f_S1AP_get_ENB_UE_S1AP_ID(rx_msg); |
| 624 | var template (value) E_RABSetupItemCtxtSURes rab_setup_it; |
| 625 | var template (value) E_RABSetupListCtxtSURes rab_setup_items; |
| 626 | var octetstring esm_enc; |
| 627 | var template (value) PDU_NAS_EPS nas; |
Pau Espin Pedrol | 408e0ae | 2023-12-15 18:56:31 +0100 | [diff] [blame] | 628 | var EPS_MobileIdentityTLV mi_tlv; |
| 629 | |
| 630 | S1AP.receive(tr_NAS_AttachAccept()) -> value rx_nas; |
| 631 | mi_tlv := rx_nas.ePS_messages.ePS_MobilityManagement.pDU_NAS_EPS_AttachAccept.gUTI; |
| 632 | if (mi_tlv.ePS_MobileIdentity.ePS_MobileIdentity.typeOfIdentity != '110'B) { |
| 633 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Rx GUTI of unexpected MI type: ", mi_tlv)); |
| 634 | } |
| 635 | g_pars.ue_pars.guti := mi_tlv.ePS_MobileIdentity.ePS_MobileIdentity.oddEvenInd_identity.guti |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 636 | |
| 637 | rab_setup_it := ts_S1AP_RABSetupItemCtxtSURes(rab_id := 5, |
| 638 | tla := oct2bit(f_inet_addr(mp_mme_ip)), |
| 639 | gtp_teid := '00000002'O); |
| 640 | rab_setup_items := ts_S1AP_RABSetupListCtxtSURes(rab_setup_it); |
| 641 | S1AP.send(ts_S1AP_InitialCtxSetupResp(valueof(mme_ue_id), valueof(enb_ue_id), rab_setup_items)); |
| 642 | |
| 643 | nas := ts_NAS_ActDefEpsBearCtxAck(int2bit(g_pars.ue_pars.bearer.ebi, 4), '00000000'B, omit); |
| 644 | esm_enc := enc_PDU_NAS_EPS(valueof(nas)); |
| 645 | S1AP.send(ts_NAS_AttachComplete(esm_enc)); |
Pau Espin Pedrol | 278f543 | 2023-12-21 19:21:28 +0100 | [diff] [blame] | 646 | |
| 647 | /* Optional from the network: */ |
| 648 | S1AP.receive(tr_NAS_EMMInformation); |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 649 | } |
| 650 | [] S1AP.receive(PDU_NAS_EPS:?) -> value rx_nas { |
| 651 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Rx Unexpected NAS PDU msg: ", rx_nas)); |
| 652 | } |
| 653 | } |
| 654 | |
Pau Espin Pedrol | 35c0cc2 | 2023-12-21 19:23:48 +0100 | [diff] [blame] | 655 | private altstep as_s1ap_handle_UeContextReleaseCmd(template S1AP_IEs.Cause cause := ?) runs on ConnHdlr { |
| 656 | var S1AP_PDU rx_msg; |
| 657 | var PDU_NAS_EPS rx_nas; |
| 658 | [] S1AP.receive(tr_S1AP_UeContextReleaseCmd(?, cause)) -> value rx_msg { |
| 659 | var template MME_UE_S1AP_ID mme_ue_id; |
| 660 | var template ENB_UE_S1AP_ID enb_ue_id; |
| 661 | if (not ispresent(rx_msg.initiatingMessage.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.uE_S1AP_ID_pair)) { |
| 662 | /* TODO: The UE CONTEXT RELEASE COMMAND (see also: 3GPP TS 36.413, section 9.1.4.6), may identify the |
| 663 | * context by either an uE_S1AP_ID_pair (MME_UE_S1AP_ID and ENB_UE_S1AP_ID) or an MME_UE_S1AP_ID alone. |
| 664 | * The latter case is not implemented here yet. */ |
| 665 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("complete implementation of UeContextReleaseCmd handling")); |
| 666 | return; |
| 667 | } |
| 668 | |
| 669 | mme_ue_id := rx_msg.initiatingMessage.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.uE_S1AP_ID_pair.mME_UE_S1AP_ID; |
| 670 | enb_ue_id := rx_msg.initiatingMessage.value_.uEContextReleaseCommand.protocolIEs[0].value_.uE_S1AP_IDs.uE_S1AP_ID_pair.eNB_UE_S1AP_ID; |
| 671 | |
| 672 | S1AP.send(ts_S1AP_UeContextReleaseCompl(mme_ue_id, enb_ue_id)); |
| 673 | } |
| 674 | [] S1AP.receive(PDU_NAS_EPS:?) -> value rx_nas { |
| 675 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Rx Unexpected NAS PDU msg: ", rx_nas)); |
| 676 | } |
| 677 | } |
| 678 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 679 | /* Exepect AuthInfoReq (AIR) from HSS; respond with AuthInforAnswer (AIA) */ |
| 680 | private altstep as_DIA_AuthInfo() runs on ConnHdlr { |
| 681 | var PDU_DIAMETER rx_dia; |
| 682 | [] DIAMETER.receive(tr_DIA_AIR(g_pars.ue_pars.imsi)) -> value rx_dia { |
| 683 | var template (omit) AVP avp; |
| 684 | var octetstring sess_id; |
| 685 | var octetstring vplmn_id; |
| 686 | var hexstring imsi; |
| 687 | var template (value) AVP_list auth_info_content; |
| 688 | |
| 689 | /* retrieve input data */ |
| 690 | imsi := valueof(f_DIAMETER_get_imsi(rx_dia)); |
| 691 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id); |
| 692 | sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id); |
| 693 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_AAA_3GPP_Visited_PLMN_Id); |
| 694 | vplmn_id := valueof(avp.avp_data.avp_AAA_3GPP_Visited_PLMN_Id); |
| 695 | |
| 696 | /* compute tuple */ |
| 697 | auth_info_content := { ts_AVP_EutranVec(1, '20080c3818183b522614162c07601d0d'O, '6a91970e838fd079'O, 'f11b89a2a8be00001f9c526f3d75d44c'O, '95AFAD9A0D29AFAA079A9451DF7161D7EE4CBF2AF9387F766D058BB6B44B905D'O) }; |
| 698 | |
Vadim Yanitskiy | 2dba494 | 2021-12-11 15:46:30 +0300 | [diff] [blame] | 699 | DIAMETER.send(ts_DIA_AIA(auth_info_content, sess_id, |
| 700 | hbh_id := rx_dia.hop_by_hop_id, |
| 701 | ete_id := rx_dia.end_to_end_id)); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 702 | } |
| 703 | } |
| 704 | |
| 705 | /* Expect UpdateLocationReq (ULR); respond with UpdateLocationAnswer (ULA) */ |
| 706 | private altstep as_DIA_UpdLoc() runs on ConnHdlr { |
| 707 | var PDU_DIAMETER rx_dia; |
| 708 | [] DIAMETER.receive(tr_DIA_ULR(g_pars.ue_pars.imsi)) -> value rx_dia { |
| 709 | var template (omit) AVP avp; |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 710 | var hexstring imsi; |
| 711 | var template (value) AVP_list sub_data; |
| 712 | |
| 713 | /* retrieve input data */ |
| 714 | imsi := valueof(f_DIAMETER_get_imsi(rx_dia)); |
| 715 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 716 | |
| 717 | sub_data := { |
| 718 | ts_AVP_3GPP_SubscriberStatus(SERVICE_GRANTED), |
| 719 | ts_AVP_3GPP_SubscrRauTauTmr(30), |
| 720 | ts_AVP_3GPP_AMBR(1000, 2000), |
| 721 | ts_AVP_3GPP_ApnConfigProfile({ |
| 722 | ts_AVP_3GPP_ContextId(1), |
| 723 | ts_AVP_3GPP_AllApnConfigsIncl, |
| 724 | ts_AVP_3GPP_ApnConfig(1, IPv4, "*") |
| 725 | }) |
| 726 | }; |
| 727 | |
Vadim Yanitskiy | 0e8f516 | 2021-12-15 05:00:32 +0300 | [diff] [blame] | 728 | DIAMETER.send(ts_DIA_ULA(sub_data, avp.avp_data.avp_BASE_NONE_Session_Id, |
| 729 | hbh_id := rx_dia.hop_by_hop_id, |
| 730 | ete_id := rx_dia.end_to_end_id)); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 731 | } |
| 732 | } |
| 733 | |
Pau Espin Pedrol | 35c0cc2 | 2023-12-21 19:23:48 +0100 | [diff] [blame] | 734 | private function f_DIA_CancelLocation(integer idx := 0, template S1AP_IEs.Cause cause := omit) runs on ConnHdlr { |
| 735 | |
| 736 | var UINT32 hbh_id := f_rnd_octstring(4); |
| 737 | var UINT32 ete_id := f_rnd_octstring(4); |
| 738 | var PDU_DIAMETER rx_dia; |
| 739 | |
| 740 | /* Unlike CLR, CLA contains no IMSI. Register ete_id in DIAMETER_Emulation, |
| 741 | * so AIA is forwarded back to us in DIAMETER port instead of MTC_CT.DIAMETER_UNIT. |
| 742 | */ |
| 743 | f_diameter_expect_eteid(ete_id); |
| 744 | |
| 745 | DIAMETER.send(ts_DIA_CLR(g_pars.ue_pars.imsi, SGSN_UPDATE_PROCEDURE, |
| 746 | orig_host := mp_s6_local_diam_host, |
| 747 | orig_realm := mp_s6_diam_realm, |
| 748 | dest_host := mp_s6_remote_diam_host, |
| 749 | dest_realm := mp_s6_diam_realm, |
| 750 | hbh_id := hbh_id, |
| 751 | ete_id := ete_id)); |
| 752 | |
| 753 | alt { |
| 754 | [] DIAMETER.receive(tr_DIA_CLA) -> value rx_dia {} |
| 755 | [] DIAMETER.receive(PDU_DIAMETER:?) -> value rx_dia { |
| 756 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("Unexpected Diameter S6b msg rx: ", rx_dia)); |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 761 | private altstep as_GTP2C_CreateSession_success() runs on ConnHdlr { |
| 762 | var PDU_GTPCv2 rx_msg; |
| 763 | var BearerContextIEs rx_bctx_ies; |
| 764 | var template (value) FullyQualifiedTEID s11_fteid_c_ie, s11_fteid_u_ie, s5c_fteid_c_ie, s5c_fteid_u_ie; |
| 765 | var template (value) PDN_AddressAllocation paa; |
| 766 | var template (value) BearerContextIEs bctx_ies; |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 767 | |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 768 | [] GTP2.receive(tr_GTP2C_CreateSessionReq(g_pars.ue_pars.imsi)) -> value rx_msg { |
| 769 | /* Parse TEIC and Bearer EBI and TEID and store it in g_pars */ |
| 770 | g_pars.ue_pars.s11_teic_remote := rx_msg.gtpcv2_pdu.createSessionRequest.fullyQualifiedTEID[0].tEID_GRE_Key; |
| 771 | g_pars.ue_pars.s5c_teic_remote := rx_msg.gtpcv2_pdu.createSessionRequest.fullyQualifiedTEID[1].tEID_GRE_Key; |
| 772 | |
| 773 | rx_bctx_ies := rx_msg.gtpcv2_pdu.createSessionRequest.bearerContextGrouped[0].bearerContextIEs; |
| 774 | g_pars.ue_pars.bearer.ebi := rx_bctx_ies.ePS_Bearer_ID.ePS_Bearer_ID_Value; |
| 775 | |
| 776 | /* allocate + register TEID-C on local side */ |
| 777 | g_pars.ue_pars.s11_teic_local := f_gtp2_allocate_teid(); |
| 778 | g_pars.ue_pars.bearer.s11_teid_local := g_pars.ue_pars.s11_teic_local; |
| 779 | g_pars.ue_pars.s5c_teic_local := f_gtp2_allocate_teid(); |
| 780 | g_pars.ue_pars.bearer.s5c_teid_local := g_pars.ue_pars.s5c_teic_local; |
| 781 | |
| 782 | s11_fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S11_MME_GTPC, g_pars.ue_pars.s11_teic_local, 0, |
| 783 | f_inet_addr(mp_s11_local_ip), omit); |
| 784 | s5c_fteid_c_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_PGW_GTPC, g_pars.ue_pars.s5c_teic_local, 1, |
| 785 | f_inet_addr(mp_s5c_pgw_ip), omit); |
| 786 | s11_fteid_u_ie := ts_GTP2C_FTEID(FTEID_IF_S1U_SGW_GTPU, g_pars.ue_pars.bearer.s11_teid_local, 0, |
| 787 | f_inet_addr(mp_s11_local_ip), omit); |
| 788 | s5c_fteid_u_ie := ts_GTP2C_FTEID(FTEID_IF_S5S8_PGW_GTPU, g_pars.ue_pars.bearer.s5c_teid_local, 2, |
| 789 | f_inet_addr(mp_s5c_pgw_ip), omit); |
| 790 | paa := ts_GTP2C_PdnAddrAlloc_v4(f_inet_addr(g_pars.ue_pars.ue_ip)); |
| 791 | bctx_ies := ts_GTP2C_BcContextIE(ebi := g_pars.ue_pars.bearer.ebi, |
| 792 | teid_list := { s11_fteid_u_ie, s5c_fteid_u_ie }, |
| 793 | qos := ts_GTP2C_BearerQos('09'O, 0, 0, 0, 0), |
| 794 | charging_id := ts_GTP2C_ChargingID(g_pars.ue_pars.bearer.s11_teid_local)); |
| 795 | |
| 796 | GTP2.send(ts_GTP2C_CreateSessionResp(g_pars.ue_pars.s11_teic_remote, |
| 797 | rx_msg.sequenceNumber, |
| 798 | { s11_fteid_c_ie, s5c_fteid_c_ie }, |
| 799 | paa, { ts_GTP2C_BcGrouped(bctx_ies) } )); |
| 800 | setverdict(pass); |
| 801 | } |
| 802 | [] GTP2.receive { |
| 803 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 804 | log2str("Unexpected GTPv2/S11 message from MME")); |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | private altstep as_GTP2C_ModifyBearer_success() runs on ConnHdlr { |
| 809 | var PDU_GTPCv2 rx_msg; |
| 810 | var BearerContextIEs rx_bctx_ies; |
| 811 | var template (value) FullyQualifiedTEID s11_fteid_c_ie, s11_fteid_u_ie, s5c_fteid_c_ie, s5c_fteid_u_ie; |
| 812 | var template (value) BearerContextIEs bctx_ies; |
| 813 | |
| 814 | [] GTP2.receive(tr_GTP2C_ModifyBearerReq(g_pars.ue_pars.s11_teic_local)) -> value rx_msg { |
| 815 | |
| 816 | rx_bctx_ies := rx_msg.gtpcv2_pdu.modifyBearerRequest.bearerContextGrouped[0].bearerContextIEs; |
| 817 | |
| 818 | /* TODO: validate the S1-U fullyQualifiedTEID announces the IP address provided by the ENB in InitialCtxSetupResp */ |
| 819 | // rx_bctx_ies.fullyQualifiedTEID[0]. == f_inet_addr(mp_mme_ip) |
| 820 | |
| 821 | /* Update S11 TEID */ |
| 822 | g_pars.ue_pars.bearer.s11_teid_remote := rx_bctx_ies.fullyQualifiedTEID[0].tEID_GRE_Key; |
| 823 | |
| 824 | s11_fteid_u_ie := ts_GTP2C_FTEID(FTEID_IF_S1U_SGW_GTPU, g_pars.ue_pars.bearer.s11_teid_local, 0, |
| 825 | f_inet_addr(mp_s11_local_ip), omit); |
| 826 | bctx_ies := ts_GTP2C_BcContextIE(ebi := g_pars.ue_pars.bearer.ebi, |
| 827 | teid_list := { s11_fteid_u_ie }, |
| 828 | qos := ts_GTP2C_BearerQos('09'O, 0, 0, 0, 0), |
| 829 | charging_id := ts_GTP2C_ChargingID(g_pars.ue_pars.bearer.s11_teid_local)); |
| 830 | |
| 831 | GTP2.send(ts_GTP2C_ModifyBearerResp(g_pars.ue_pars.s11_teic_remote, |
| 832 | rx_msg.sequenceNumber, |
| 833 | Request_accepted, |
| 834 | g_pars.ue_pars.bearer.ebi, |
| 835 | { ts_GTP2C_BcGrouped(bctx_ies) } )); |
| 836 | setverdict(pass); |
| 837 | } |
| 838 | [] GTP2.receive { |
| 839 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 840 | log2str("Unexpected GTPv2/S11 message from MME")); |
| 841 | } |
| 842 | } |
| 843 | |
Pau Espin Pedrol | 78c5e41 | 2023-12-21 19:50:11 +0100 | [diff] [blame] | 844 | private altstep as_GTP2C_DeleteSession_success(template Indication ind_flags := *) runs on ConnHdlr { |
Pau Espin Pedrol | 35c0cc2 | 2023-12-21 19:23:48 +0100 | [diff] [blame] | 845 | var PDU_GTPCv2 rx_msg; |
| 846 | |
Pau Espin Pedrol | 78c5e41 | 2023-12-21 19:50:11 +0100 | [diff] [blame] | 847 | [] GTP2.receive(tr_GTP2C_DeleteSessionReq(g_pars.ue_pars.s11_teic_local, indicationFlags := ind_flags)) -> value rx_msg { |
Pau Espin Pedrol | 35c0cc2 | 2023-12-21 19:23:48 +0100 | [diff] [blame] | 848 | GTP2.send(ts_GTP2C_DeleteSessionResp(g_pars.ue_pars.s11_teic_remote, |
| 849 | rx_msg.sequenceNumber, |
| 850 | Request_accepted)); |
| 851 | setverdict(pass); |
| 852 | } |
| 853 | [] GTP2.receive { |
| 854 | Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, |
| 855 | log2str("Unexpected GTPv2/S11 message from MME")); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | private function f_gtp_sgsn_context_4g_to_2g(OCT4 new_sgsn_local_teid := '12345678'O) runs on ConnHdlr { |
| 860 | var template (value) GTPC_PDUs SGSNContextReqPDU; |
| 861 | var RoutingAreaIdentity rai; |
| 862 | var OCT4 ptmsi; |
| 863 | var OCT3 ptmsi_sig; |
| 864 | var Gtp1cUnitdata gtpc_pdu; |
| 865 | var OCT4 old_mme_local_teid; |
| 866 | |
| 867 | guti2rai_ptmsi(g_pars.ue_pars.guti, rai, ptmsi, ptmsi_sig); |
| 868 | |
| 869 | SGSNContextReqPDU := ts_SGSNContextReqPDU(rai, new_sgsn_local_teid, f_inet_addr(mp_gn_local_ip), |
| 870 | ptmsi := ts_PTMSI(ptmsi), ptmsi_sig := ts_PTMSI_sig(ptmsi_sig)); |
| 871 | GTP.send(ts_GTPC_SGSNContextReq(g_gn_iface_peer, 0, SGSNContextReqPDU)); |
| 872 | |
| 873 | timer T := 5.0; |
| 874 | T.start; |
| 875 | alt { |
| 876 | [] GTP.receive(tr_GTPC_SGSNContextResp(g_gn_iface_peer, new_sgsn_local_teid, |
| 877 | tr_SGSNContextRespPDU(GTP_CAUSE_REQUEST_ACCEPTED, |
| 878 | g_pars.ue_pars.imsi))) -> value gtpc_pdu { |
| 879 | old_mme_local_teid := gtpc_pdu.gtpc.gtpc_pdu.sgsn_ContextResponse.teidControlPlane.teidControlPlane; |
| 880 | setverdict(pass); |
| 881 | } |
| 882 | [] GTP.receive { |
| 883 | setverdict(fail, "unexpected GTPC message from MME"); |
| 884 | } |
| 885 | [] T.timeout { |
| 886 | setverdict(fail, "no SGSN Context Response from MME"); |
| 887 | } |
| 888 | } |
| 889 | |
| 890 | GTP.send(ts_GTPC_SGSNContextAck(g_gn_iface_peer, old_mme_local_teid, |
| 891 | oct2int(gtpc_pdu.gtpc.opt_part.sequenceNumber), |
| 892 | ts_SGSNContextAckPDU(GTP_CAUSE_REQUEST_ACCEPTED))); |
| 893 | |
| 894 | } |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 895 | |
| 896 | private function f_attach() runs on ConnHdlr { |
| 897 | var template (value) EPS_MobileIdentityV mi := ts_NAS_MobileId_IMSI(g_pars.ue_pars.imsi); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 898 | var template (value) PDU_NAS_EPS nas_esm, nas_emm; |
Philipp Maier | f74f319 | 2023-09-01 17:24:36 +0200 | [diff] [blame] | 899 | timer T := 5.0; |
| 900 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 901 | nas_esm := ts_NAS_PdnConnReq(bearer_id := '0000'B, proc_tid := int2bit(1,8), |
| 902 | pdn_type := NAS_PDN_T_IPv4, req_type := '001'B); |
| 903 | nas_emm := ts_NAS_AttachRequest(att_type := '000'B, kset_id := '000'B, mobile_id := mi, |
| 904 | ue_net_cap := c_NAS_defaultUeNetCap, |
| 905 | esm_enc := enc_PDU_NAS_EPS(valueof(nas_esm))); |
| 906 | var template (value) S1AP_PDU tx; |
| 907 | tx := ts_S1AP_InitialUE(p_eNB_value := 0, p_nasPdu := enc_PDU_NAS_EPS(valueof(nas_emm)), |
| 908 | p_tAI := ts_enb_S1AP_TAI(g_pars.enb_pars[g_pars.mme_idx]), |
| 909 | p_eUTRAN_CGI := ts_enb_S1AP_CGI(g_pars.enb_pars[g_pars.mme_idx]), |
| 910 | p_rrcCause := mo_Signalling); |
| 911 | S1AP.send(tx); |
| 912 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 913 | as_DIA_AuthInfo(); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 914 | as_s1ap_handle_auth(); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 915 | alt { |
| 916 | [] as_DIA_UpdLoc() { |
| 917 | as_s1ap_handle_sec_mode(); |
| 918 | } |
| 919 | [] as_s1ap_handle_sec_mode() { |
| 920 | as_DIA_UpdLoc(); |
| 921 | } |
| 922 | } |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 923 | |
Philipp Maier | f74f319 | 2023-09-01 17:24:36 +0200 | [diff] [blame] | 924 | /* We now expect the MME to send a Create Session Request to the SGW-C */ |
Philipp Maier | f74f319 | 2023-09-01 17:24:36 +0200 | [diff] [blame] | 925 | f_gtp2_register_udmsg('20'O); |
| 926 | T.start; |
| 927 | alt { |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 928 | [] as_GTP2C_CreateSession_success(); |
| 929 | [] T.timeout { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No message from MME")); } |
Philipp Maier | f74f319 | 2023-09-01 17:24:36 +0200 | [diff] [blame] | 930 | } |
| 931 | |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 932 | T.start; |
| 933 | alt { |
| 934 | [] as_s1ap_handle_IntialCtxSetupReq(); |
| 935 | [] T.timeout { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No message from MME")); } |
| 936 | } |
Philipp Maier | f74f319 | 2023-09-01 17:24:36 +0200 | [diff] [blame] | 937 | |
Pau Espin Pedrol | ecfc7d6 | 2023-12-13 18:49:29 +0100 | [diff] [blame] | 938 | /* We now expect the MME to send a Modify Bearer Request to the SGW-C */ |
| 939 | f_gtp2_register_udmsg('22'O); |
| 940 | T.start; |
| 941 | alt { |
| 942 | [] as_GTP2C_ModifyBearer_success(); |
| 943 | [] T.timeout { Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, log2str("No message from MME")); } |
| 944 | } |
| 945 | } |
| 946 | |
| 947 | private function f_TC_attach(ConnHdlrPars pars) runs on ConnHdlr { |
| 948 | f_init_handler(pars); |
| 949 | f_attach(); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 950 | } |
| 951 | testcase TC_s1ap_attach() runs on MTC_CT { |
| 952 | var charstring id := testcasename(); |
| 953 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 954 | f_init_diameter(id); |
| 955 | f_sleep(10.0); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 956 | f_init_s1ap(id, 4); |
Philipp Maier | f74f319 | 2023-09-01 17:24:36 +0200 | [diff] [blame] | 957 | f_init_gtpv2_s11(id); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 958 | f_s1ap_setup(0); |
| 959 | |
| 960 | var ConnHdlrPars pars := f_init_pars(ue_idx := 0); |
| 961 | var ConnHdlr vc_conn; |
| 962 | vc_conn := f_start_handler_with_pars(refers(f_TC_attach), pars); |
| 963 | vc_conn.done; |
| 964 | } |
| 965 | |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 966 | private function f_TC_gn_echo_request(ConnHdlrPars pars) runs on ConnHdlr { |
| 967 | timer T := 5.0; |
| 968 | f_init_handler(pars); |
| 969 | f_gtp_register_teid('00000000'O); |
| 970 | |
| 971 | GTP.send(ts_GTPC_PING(g_gn_iface_peer, 1)); |
| 972 | T.start; |
| 973 | alt { |
| 974 | [] GTP.receive(tr_GTPC_PONG(?)) { |
| 975 | setverdict(pass); |
| 976 | } |
| 977 | [] GTP.receive { |
| 978 | setverdict(fail, "unexpected GTPC message from MME"); |
| 979 | } |
| 980 | [] T.timeout { |
| 981 | setverdict(fail, "no GTPC ECHO RESPONSE from MME"); |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | testcase TC_gn_echo_request() runs on MTC_CT { |
| 986 | var charstring id := testcasename(); |
| 987 | |
| 988 | f_init_diameter(id); |
Pau Espin Pedrol | ae747ac | 2023-12-20 20:55:32 +0100 | [diff] [blame] | 989 | f_init_s1ap(id, 0); |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 990 | f_s1ap_setup(0); |
| 991 | f_init_gtp(id); |
| 992 | |
| 993 | var ConnHdlrPars pars := f_init_pars(ue_idx := 0); |
| 994 | var ConnHdlr vc_conn; |
| 995 | vc_conn := f_start_handler_with_pars(refers(f_TC_gn_echo_request), pars); |
| 996 | vc_conn.done; |
| 997 | } |
| 998 | |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 999 | external function enc_PDU_GTPC_RAN_INF_REQ(in PDU_BSSGP_RAN_INFORMATION_REQUEST_GTPC gtpc_pdu) return octetstring |
| 1000 | with { extension "prototype(convert)" |
| 1001 | extension "encode(RAW)" |
| 1002 | } |
| 1003 | |
| 1004 | external function enc_PDU_GTPC_RAN_INF(in PDU_BSSGP_RAN_INFORMATION_GTPC gtpc_pdu) return octetstring |
| 1005 | with { extension "prototype(convert)" |
| 1006 | extension "encode(RAW)" |
| 1007 | } |
| 1008 | |
| 1009 | function f_convert_plmn(OCT3 pLMNidentity) return hexstring { |
| 1010 | var hexstring pLMNidentity_hex := oct2hex(pLMNidentity); |
| 1011 | var hexstring pLMNidentity_hex_swapped; |
| 1012 | pLMNidentity_hex_swapped[0] := pLMNidentity_hex[1]; |
| 1013 | pLMNidentity_hex_swapped[1] := pLMNidentity_hex[0]; |
| 1014 | pLMNidentity_hex_swapped[2] := pLMNidentity_hex[3]; |
| 1015 | pLMNidentity_hex_swapped[3] := pLMNidentity_hex[2]; |
| 1016 | pLMNidentity_hex_swapped[4] := pLMNidentity_hex[5]; |
| 1017 | pLMNidentity_hex_swapped[5] := pLMNidentity_hex[4]; |
| 1018 | return pLMNidentity_hex_swapped; |
| 1019 | } |
| 1020 | |
| 1021 | /* Make a template for a GTPC BSSGP container that contains a RAN INFORMATION REQUEST. The template can be used to |
| 1022 | * craft the request for the S1AP/S1-MME interface and also to verfify the contents of the coresponding request on |
| 1023 | * the GTPC/Gn interface */ |
| 1024 | private function f_make_ts_GTPC_RAN_Information_Request(GTP_CellId geran_gtp_ci) |
| 1025 | runs on ConnHdlr return template (value) PDU_BSSGP_RAN_INFORMATION_REQUEST_GTPC { |
| 1026 | var template (value) RIM_Routing_Address_GTPC gtpc_dst_addr, gtpc_src_addr; |
| 1027 | var template (value) RAN_Information_Request_RIM_Container_GTPC gtpc_rim_req_cont; |
| 1028 | var template (value) PDU_BSSGP_RAN_INFORMATION_REQUEST_GTPC gtpc_bssgp_cont; |
| 1029 | var octetstring gnbid; |
| 1030 | var GTP_CellId eutran_gtp_ci; |
| 1031 | eutran_gtp_ci.ra_id.lai.mcc_mnc := f_convert_plmn(g_pars.enb_pars[g_pars.mme_idx].global_enb_id.pLMNidentity); |
| 1032 | |
| 1033 | gnbid := enc_S1AP_Global_ENB_ID(g_pars.enb_pars[g_pars.mme_idx].global_enb_id); |
| 1034 | gtpc_dst_addr := t_GTPC_RIM_Routing_Address_cid(geran_gtp_ci); |
| 1035 | gtpc_src_addr := t_GTPC_RIM_Routing_Address_enbid(eutran_gtp_ci, |
| 1036 | oct2int(g_pars.enb_pars[g_pars.mme_idx].supported_tas[0].tAC), |
| 1037 | gnbid); |
| 1038 | |
| 1039 | gtpc_rim_req_cont := ts_GTPC_RAN_Information_Request_RIM_Container( |
| 1040 | ts_GTPC_RIM_Application_Identity(RIM_APP_ID_NACC), |
| 1041 | ts_GTPC_RIM_Sequence_Number(1), |
| 1042 | ts_GTPC_RIM_PDU_Indications(false, RIM_PDU_TYPE_SING_REP), |
| 1043 | ts_GTPC_RIM_Protocol_Version_Number(1), |
| 1044 | tsu_GTPC_RAN_Information_Request_Application_Container_NACC(geran_gtp_ci), |
| 1045 | omit); |
| 1046 | gtpc_bssgp_cont := ts_GTPC_RAN_Information_Request( |
| 1047 | ts_GTPC_RIM_Routing_Information(RIM_ADDR_GERAN_CELL_ID, gtpc_dst_addr), |
| 1048 | ts_GTPC_RIM_Routing_Information(RIM_ADDR_EUTRAN_NODEB_ID, gtpc_src_addr), |
| 1049 | gtpc_rim_req_cont); |
| 1050 | |
| 1051 | return gtpc_bssgp_cont; |
| 1052 | } |
| 1053 | |
| 1054 | private function f_make_tr_GTPC_RAN_Information_Request(GTP_CellId geran_gtp_ci) |
| 1055 | runs on ConnHdlr return template (present) PDU_BSSGP_RAN_INFORMATION_REQUEST_GTPC { |
| 1056 | var template (present) RIM_Routing_Address_GTPC gtpc_dst_addr, gtpc_src_addr; |
| 1057 | var template (present) RAN_Information_Request_RIM_Container_GTPC gtpc_rim_req_cont; |
| 1058 | var template (present) PDU_BSSGP_RAN_INFORMATION_REQUEST_GTPC gtpc_bssgp_cont; |
| 1059 | var octetstring gnbid; |
| 1060 | var GTP_CellId eutran_gtp_ci; |
| 1061 | eutran_gtp_ci.ra_id.lai.mcc_mnc := f_convert_plmn(g_pars.enb_pars[g_pars.mme_idx].global_enb_id.pLMNidentity); |
| 1062 | |
| 1063 | gnbid := enc_S1AP_Global_ENB_ID(g_pars.enb_pars[g_pars.mme_idx].global_enb_id); |
| 1064 | gtpc_dst_addr := t_GTPC_RIM_Routing_Address_cid(geran_gtp_ci); |
| 1065 | gtpc_src_addr := t_GTPC_RIM_Routing_Address_enbid(eutran_gtp_ci, |
| 1066 | oct2int(g_pars.enb_pars[g_pars.mme_idx].supported_tas[0].tAC), |
| 1067 | gnbid); |
| 1068 | |
| 1069 | gtpc_rim_req_cont := tr_GTPC_RAN_Information_Request_RIM_Container( |
| 1070 | ts_GTPC_RIM_Application_Identity(RIM_APP_ID_NACC), |
| 1071 | ts_GTPC_RIM_Sequence_Number(1), |
| 1072 | ts_GTPC_RIM_PDU_Indications(false, RIM_PDU_TYPE_SING_REP), |
| 1073 | ts_GTPC_RIM_Protocol_Version_Number(1), |
| 1074 | tru_GTPC_RAN_Information_Request_Application_Container_NACC(geran_gtp_ci)); |
| 1075 | gtpc_bssgp_cont := tr_GTPC_RAN_Information_Request( |
| 1076 | tr_GTPC_RIM_Routing_Information(RIM_ADDR_GERAN_CELL_ID, gtpc_dst_addr), |
| 1077 | tr_GTPC_RIM_Routing_Information(RIM_ADDR_EUTRAN_NODEB_ID, gtpc_src_addr), |
| 1078 | gtpc_rim_req_cont); |
| 1079 | |
| 1080 | return gtpc_bssgp_cont; |
| 1081 | } |
| 1082 | |
| 1083 | /* Make initial RAN INFORMATION REQUEST message that is sent on the S1AP/S1-MME interface */ |
| 1084 | private function f_make_ts_S1AP_eNBDirectInfTrans(GTP_CellId geran_gtp_ci) |
| 1085 | runs on ConnHdlr return template (value) S1AP_PDU { |
| 1086 | var template (value) Inter_SystemInformationTransferType inf; |
| 1087 | |
| 1088 | inf.rIMTransfer.rIMInformation := enc_PDU_GTPC_RAN_INF_REQ(valueof(f_make_ts_GTPC_RAN_Information_Request(geran_gtp_ci))); |
| 1089 | inf.rIMTransfer.rIMRoutingAddress.gERAN_Cell_ID.lAI.pLMNidentity := hex2oct(f_convert_plmn(hex2oct(geran_gtp_ci.ra_id.lai.mcc_mnc))); |
| 1090 | inf.rIMTransfer.rIMRoutingAddress.gERAN_Cell_ID.lAI.lAC := int2oct(geran_gtp_ci.ra_id.lai.lac, 2); |
| 1091 | inf.rIMTransfer.rIMRoutingAddress.gERAN_Cell_ID.lAI.iE_Extensions := omit; |
| 1092 | inf.rIMTransfer.rIMRoutingAddress.gERAN_Cell_ID.rAC := int2oct(geran_gtp_ci.ra_id.rac, 1); |
| 1093 | inf.rIMTransfer.rIMRoutingAddress.gERAN_Cell_ID.cI := int2oct(geran_gtp_ci.cell_id, 2); |
| 1094 | inf.rIMTransfer.rIMRoutingAddress.gERAN_Cell_ID.iE_Extensions := omit; |
| 1095 | inf.rIMTransfer.iE_Extensions := omit; |
| 1096 | |
| 1097 | return ts_S1AP_eNBDirectInfTrans(inf); |
| 1098 | } |
| 1099 | |
| 1100 | /* Make RAN INFORMATION (response) message that is sent on the GTPC/Gn interface */ |
| 1101 | private function f_make_ts_GTPC_RANInfoRelay(template Gtp1cUnitdata req_gtpc_pdu, |
| 1102 | GTP_CellId geran_gtp_ci, octetstring geran_si) |
| 1103 | runs on ConnHdlr return template (value) Gtp1cUnitdata { |
| 1104 | var template Gtp1cUnitdata res_gtpc_pdu; |
| 1105 | var template RAN_Information_RIM_Container_GTPC gtpc_rim_res_cont; |
| 1106 | var template PDU_BSSGP_RAN_INFORMATION_GTPC gtpc_bssgp_rim_res_pdu; |
| 1107 | var template RIM_Routing_Information_GTPC gtpc_rim_dst_cell_id, gtpc_rim_src_cell_id; |
| 1108 | var template RIM_RoutingAddress gtpc_rim_ra; |
| 1109 | var template RIM_RoutingAddress_Discriminator gtpc_rim_ra_discr; |
| 1110 | |
| 1111 | /* Assemble GTPC RAN Information */ |
| 1112 | gtpc_rim_res_cont := ts_GTPC_RAN_Information_RIM_Container(ts_GTPC_RIM_Application_Identity(RIM_APP_ID_NACC), |
| 1113 | ts_GTPC_RIM_Sequence_Number(2), |
| 1114 | ts_GTPC_RIM_PDU_Indications(false, RIM_PDU_TYPE_SING_REP), |
| 1115 | ts_GTPC_RIM_Protocol_Version_Number(1), |
| 1116 | tsu_GTPC_ApplContainer_or_ApplErrContainer_NACC(tsu_GTPC_ApplContainer_NACC(geran_gtp_ci, false, 3, geran_si)), |
| 1117 | omit); |
| 1118 | |
| 1119 | /* The source becomes the destination and vice versa */ |
| 1120 | gtpc_rim_dst_cell_id := req_gtpc_pdu.gtpc.gtpc_pdu.ranInformationRelay.transparentContainer. |
| 1121 | rANTransparentContainerField.pDU_BSSGP_RAN_INFORMATION_REQUEST.source_Cell_Identifier |
| 1122 | gtpc_rim_src_cell_id := req_gtpc_pdu.gtpc.gtpc_pdu.ranInformationRelay.transparentContainer. |
| 1123 | rANTransparentContainerField.pDU_BSSGP_RAN_INFORMATION_REQUEST.destination_Cell_Identifier |
| 1124 | gtpc_bssgp_rim_res_pdu := ts_GTPC_RAN_Information(gtpc_rim_dst_cell_id, |
| 1125 | gtpc_rim_src_cell_id, |
| 1126 | gtpc_rim_res_cont); |
| 1127 | |
| 1128 | /* Assemble RIM Routing Address (essentially a copy of the destination cell identifier)*/ |
| 1129 | gtpc_rim_ra := ts_RIM_RoutingAddress(enc_RIM_Routing_Address_GTPC(valueof(gtpc_rim_dst_cell_id.rIM_Routing_Address))); |
| 1130 | gtpc_rim_ra_discr := ts_RIM_RoutingAddress_Discriminator(hex2bit(valueof(gtpc_rim_dst_cell_id.rIMRoutingAddressDiscriminator))); |
| 1131 | |
| 1132 | res_gtpc_pdu := ts_GTPC_RANInfoRelay(g_gn_iface_peer, |
| 1133 | ts_RANTransparentContainer_RAN_INFO(gtpc_bssgp_rim_res_pdu), |
| 1134 | gtpc_rim_ra, gtpc_rim_ra_discr); |
| 1135 | |
| 1136 | return res_gtpc_pdu; |
| 1137 | } |
| 1138 | |
| 1139 | /* Make template to verify the RAN INFORMATION REQUEST as it appears on the GTPC/Gn interface */ |
| 1140 | private function f_make_tr_GTPC_MsgType(GTP_CellId geran_gtp_ci) |
| 1141 | runs on ConnHdlr return template (present) Gtp1cUnitdata { |
| 1142 | var template Gtp1cUnitdata msg; |
| 1143 | var template GTPC_PDUs pdus; |
| 1144 | var template RANTransparentContainer ran_transp_cont; |
| 1145 | |
| 1146 | ran_transp_cont := tr_RANTransparentContainer_RAN_INFO_REQ( |
| 1147 | f_make_tr_GTPC_RAN_Information_Request(geran_gtp_ci)); |
| 1148 | pdus := tr_RANInfoRelay(ran_transp_cont); |
| 1149 | msg := tr_GTPC_MsgType(g_gn_iface_peer, rANInformationRelay, '00000000'O, pdus); |
| 1150 | |
| 1151 | return msg; |
| 1152 | } |
| 1153 | |
| 1154 | /* Make template to verify the RAN INFORMATION (response) as it appears on the S1AP/S1-MME interface */ |
| 1155 | private function f_make_tr_S1AP_MMEDirectInfTrans(Gtp1cUnitdata ran_information_gtpc_pdu) |
| 1156 | runs on ConnHdlr return template (present) S1AP_PDU { |
| 1157 | var template S1AP_PDU msg; |
| 1158 | var template Inter_SystemInformationTransferType inf; |
| 1159 | |
| 1160 | inf.rIMTransfer.rIMInformation := enc_PDU_GTPC_RAN_INF( |
| 1161 | ran_information_gtpc_pdu.gtpc.gtpc_pdu.ranInformationRelay. |
| 1162 | transparentContainer.rANTransparentContainerField. |
| 1163 | pDU_BSSGP_RAN_INFORMATION); |
| 1164 | inf.rIMTransfer.rIMRoutingAddress := omit; |
| 1165 | inf.rIMTransfer.iE_Extensions := omit; |
| 1166 | msg := tr_S1AP_MMEDirectInfTrans(inf); |
| 1167 | |
| 1168 | return msg; |
| 1169 | } |
| 1170 | |
| 1171 | private function f_TC_RIM_RAN_INF(ConnHdlrPars pars) runs on ConnHdlr { |
| 1172 | timer T := 5.0; |
| 1173 | f_init_handler(pars); |
| 1174 | f_gtp_register_teid('00000000'O); |
| 1175 | var Gtp1cUnitdata req_gtpc_pdu; |
| 1176 | var Gtp1cUnitdata resp_gtpc_pdu; |
| 1177 | var GTP_CellId geran_gtp_ci; |
| 1178 | |
| 1179 | /* Assemble data of a fictitiously GERAN cell */ |
Pau Espin Pedrol | 1162585 | 2023-12-22 14:20:42 +0100 | [diff] [blame] | 1180 | geran_gtp_ci.ra_id.rac := mp_gn_local_rac; |
| 1181 | geran_gtp_ci.ra_id.lai.mcc_mnc := mp_gn_local_mcc & mp_gn_local_mnc; |
| 1182 | geran_gtp_ci.ra_id.lai.lac := mp_gn_local_lac; |
| 1183 | geran_gtp_ci.cell_id := mp_gn_local_ci; |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 1184 | const octetstring geran_si1 := '198fb100000000000000000000000000007900002b'O; |
| 1185 | const octetstring geran_si3 := '1b753000f110236ec9033c2747407900003c0b2b2b'O; |
| 1186 | const octetstring geran_si13 := '009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O; |
| 1187 | const octetstring geran_si := geran_si1 & geran_si3 & geran_si13; |
| 1188 | |
| 1189 | /* Send initial RAN information request via S1AP to MME and expect the MME to forward the request on GTP-C |
| 1190 | * (eNB -> MME -> SGSN) */ |
| 1191 | S1AP.send(f_make_ts_S1AP_eNBDirectInfTrans(geran_gtp_ci)); |
| 1192 | T.start; |
| 1193 | alt { |
| 1194 | [] GTP.receive(f_make_tr_GTPC_MsgType(geran_gtp_ci)) -> value req_gtpc_pdu { |
| 1195 | setverdict(pass); |
| 1196 | } |
| 1197 | [] GTP.receive { |
| 1198 | setverdict(fail, "unexpected GTPC message from MME"); |
| 1199 | } |
| 1200 | [] T.timeout { |
| 1201 | setverdict(fail, "no GTPC RAN INFORMATION REQUEST from MME"); |
| 1202 | } |
| 1203 | } |
| 1204 | |
| 1205 | /* Send RAN information response via GTP-C to MME and expect the MME to forward the respnse on S1AP |
| 1206 | * (SGSN -> MME -> eNB) */ |
| 1207 | f_create_s1ap_expect_proc(id_MMEDirectInformationTransfer, self); |
| 1208 | resp_gtpc_pdu := valueof(f_make_ts_GTPC_RANInfoRelay(req_gtpc_pdu, geran_gtp_ci, geran_si)); |
| 1209 | GTP.send(resp_gtpc_pdu); |
| 1210 | T.start; |
| 1211 | alt { |
| 1212 | [] S1AP.receive(f_make_tr_S1AP_MMEDirectInfTrans(resp_gtpc_pdu)) { |
| 1213 | setverdict(pass); |
| 1214 | } |
| 1215 | [] S1AP.receive { |
| 1216 | setverdict(fail, "unexpected S1AP message from MME"); |
| 1217 | } |
| 1218 | [] T.timeout { |
| 1219 | setverdict(fail, "no S1AP RAN INFORMATION from MME"); |
| 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | setverdict(pass); |
| 1224 | } |
| 1225 | |
| 1226 | testcase TC_RIM_RAN_INF() runs on MTC_CT { |
| 1227 | var charstring id := testcasename(); |
| 1228 | |
| 1229 | f_init_diameter(id); |
Pau Espin Pedrol | ae747ac | 2023-12-20 20:55:32 +0100 | [diff] [blame] | 1230 | f_init_s1ap(id, 0); |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 1231 | f_s1ap_setup(0); |
| 1232 | f_init_gtp(id); |
| 1233 | |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 1234 | var ConnHdlrPars pars := f_init_pars(ue_idx := 0); |
| 1235 | var ConnHdlr vc_conn; |
| 1236 | vc_conn := f_start_handler_with_pars(refers(f_TC_RIM_RAN_INF), pars); |
| 1237 | |
| 1238 | vc_conn.done; |
| 1239 | } |
| 1240 | |
Philipp Maier | 46059f0 | 2023-08-16 14:45:27 +0200 | [diff] [blame] | 1241 | /* Successful RESET procedure from eNB to MME */ |
| 1242 | testcase TC_s1ap_reset() runs on MTC_CT { |
| 1243 | var charstring id := testcasename(); |
Pau Espin Pedrol | ae747ac | 2023-12-20 20:55:32 +0100 | [diff] [blame] | 1244 | f_init_s1ap(id, 0); |
Philipp Maier | 46059f0 | 2023-08-16 14:45:27 +0200 | [diff] [blame] | 1245 | f_s1ap_setup(0); |
| 1246 | |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 1247 | var template (value) S1AP_IEs.Cause reset_cause := {misc := om_intervention}; |
Philipp Maier | 46059f0 | 2023-08-16 14:45:27 +0200 | [diff] [blame] | 1248 | var template (value) ResetType reset_type := {s1_Interface := reset_all}; |
| 1249 | timer T := 5.0; |
| 1250 | |
| 1251 | S1AP_UNIT[0].send(ts_S1AP_Reset(reset_cause, reset_type)); |
| 1252 | T.start; |
| 1253 | alt { |
| 1254 | [] S1AP_UNIT[0].receive(tr_S1AP_ResetAck_any) { |
| 1255 | setverdict(pass); |
| 1256 | } |
| 1257 | [] S1AP_UNIT[0].receive { |
| 1258 | setverdict(fail, "Received unexpected S1AP"); |
| 1259 | } |
| 1260 | [] T.timeout { |
| 1261 | setverdict(fail, "Timeout waiting for S1AP Setup result"); |
| 1262 | } |
| 1263 | } |
| 1264 | } |
| 1265 | |
Philipp Maier | 26a09f3 | 2023-09-01 14:18:33 +0200 | [diff] [blame] | 1266 | /* Tracking area update with a GUTI (TMSI) that is unknown to the MME. The MME is expected to reject this TAU |
| 1267 | * request. */ |
| 1268 | private function f_TC_tau_unknown_guti(ConnHdlrPars pars) runs on ConnHdlr { |
| 1269 | |
| 1270 | f_init_handler(pars); |
| 1271 | var template (value) EPS_MobileIdentityV mi := ts_NAS_MobileId_IMSI(pars.ue_pars.imsi); |
| 1272 | var template (value) S1AP_PDU tx; |
| 1273 | var template (value) PDU_NAS_EPS nas_tau; |
| 1274 | timer T := 5.0; |
| 1275 | |
| 1276 | var hexstring mcc_mnc := f_convert_plmn(g_pars.enb_pars[g_pars.mme_idx].global_enb_id.pLMNidentity); |
| 1277 | var EPS_MobileIdentityLV old_guti := valueof(ts_EPS_MobileId_GUTI(mcc_mnc, '0001'O, '01'O, 'AABBCCDD'O)); |
| 1278 | nas_tau := ts_PDU_NAS_EPS_TrackingAreaUpdateRequest(old_guti); |
| 1279 | |
| 1280 | tx := ts_S1AP_InitialUE(p_eNB_value := 0, p_nasPdu := enc_PDU_NAS_EPS(valueof(nas_tau)), |
| 1281 | p_tAI := ts_enb_S1AP_TAI(g_pars.enb_pars[g_pars.mme_idx]), |
| 1282 | p_eUTRAN_CGI := ts_enb_S1AP_CGI(g_pars.enb_pars[g_pars.mme_idx]), |
| 1283 | p_rrcCause := mo_Signalling); |
| 1284 | |
| 1285 | S1AP.send(tx); |
| 1286 | |
| 1287 | T.start; |
| 1288 | alt { |
| 1289 | [] S1AP.receive(tr_PDU_NAS_EPS_TrackingAreaUpdateReject) { |
| 1290 | setverdict(pass); |
| 1291 | } |
| 1292 | [] S1AP.receive { |
| 1293 | setverdict(fail, "unexpected S1AP message from MME"); |
| 1294 | } |
| 1295 | [] T.timeout { |
| 1296 | setverdict(fail, "no message from MME"); |
| 1297 | } |
| 1298 | } |
| 1299 | |
Pau Espin Pedrol | a88e51d | 2024-01-08 15:44:36 +0100 | [diff] [blame] | 1300 | as_s1ap_handle_UeContextReleaseCmd(); |
Philipp Maier | 26a09f3 | 2023-09-01 14:18:33 +0200 | [diff] [blame] | 1301 | } |
| 1302 | testcase TC_s1ap_tau_unknown_guti() runs on MTC_CT { |
| 1303 | var charstring id := testcasename(); |
| 1304 | |
| 1305 | f_init_diameter(id); |
Pau Espin Pedrol | ae747ac | 2023-12-20 20:55:32 +0100 | [diff] [blame] | 1306 | f_init_s1ap(id, 5); |
Philipp Maier | 26a09f3 | 2023-09-01 14:18:33 +0200 | [diff] [blame] | 1307 | f_s1ap_setup(0); |
| 1308 | |
| 1309 | var ConnHdlrPars pars := f_init_pars(ue_idx := 0); |
| 1310 | var ConnHdlr vc_conn; |
| 1311 | vc_conn := f_start_handler_with_pars(refers(f_TC_tau_unknown_guti), pars); |
| 1312 | vc_conn.done; |
| 1313 | } |
| 1314 | |
Pau Espin Pedrol | 408e0ae | 2023-12-15 18:56:31 +0100 | [diff] [blame] | 1315 | /* Test UE attached to EUTRAN reselecting a GERAN cell. In this scenario, the |
| 1316 | * new SGSN will attempt to obtain information of the UE from the old SGSN (MME) |
| 1317 | * through Gn interface using SGSN Context Request/Response procedure (OS#6294). */ |
| 1318 | /* TS 23.003 2.8.2.1 */ |
| 1319 | private function guti2rai_ptmsi(in NAS_EPS_Types.GUTI guti, out RoutingAreaIdentity rai, out OCT4 ptmsi, out OCT3 ptmsi_sig) runs on ConnHdlr { |
| 1320 | var bitstring mtmsi_bits := oct2bit(guti.mTMSI); |
| 1321 | var bitstring ptmsi_bits; |
| 1322 | var bitstring ptmsi_sig_bits; |
| 1323 | |
| 1324 | rai := valueof(ts_RoutingAreaIdentity(guti.mccDigit1 & guti.mccDigit2 & guti.mccDigit3, |
| 1325 | guti.mncDigit3 & guti.mncDigit1 & guti.mncDigit2, |
| 1326 | guti.mMEGI, guti.mMEC)); |
| 1327 | /* 3GPP TS 23.003 2.8.2.0: "P-TMSI shall be of 32 bits length where the two topmost bits are |
| 1328 | * reserved and always set to '11'. Hence, for a UE which may handover to GERAN/UTRAN (based on |
| 1329 | * subscription and UE capabilities), the corresponding bits in the M-TMSI are set to '11'" |
| 1330 | */ |
| 1331 | ptmsi_bits := '11'B & substr(mtmsi_bits, 2, 6) & oct2bit(guti.mMEC) & substr(mtmsi_bits, 16, 16); |
| 1332 | ptmsi_sig_bits := substr(mtmsi_bits, 8, 8) & oct2bit('0000'O); |
| 1333 | ptmsi := bit2oct(ptmsi_bits); |
| 1334 | ptmsi_sig := bit2oct(ptmsi_sig_bits); |
| 1335 | /* TODO: The UE shall fill the remaining 2 octets of the <P-TMSI signature> according to clauses 9.1.1, 9.4.1, 10.2.1, or |
| 1336 | * 10.5.1 of 3GPP TS.33.401 [89] , as appropriate, for RAU/Attach procedures.*/ |
| 1337 | /* TODO: 3GPP TS 33.401 9.1.1 The 16 least significant bits available in |
| 1338 | * the P-TMSI signature field shall be filled with the truncated NAS-token |
| 1339 | * according to 3GPP TS 23.003 [3].The truncated NAS-token is defined as the 16 |
| 1340 | * least significant bits of the NAS-token. |
| 1341 | * The NAS-token is derived as specified in Annex A.9. The UE shall use the uplink NAS COUNT value that it would use |
| 1342 | * in the next NAS message to calculate the NAS-token and increase the stored uplink NAS COUNT value by 1.*/ |
| 1343 | /* TODO: mMEC "also copied into the 8 Most Significant Bits of the NRI field within the P-TMSI" */ |
| 1344 | } |
| 1345 | private function f_TC_ue_cell_reselect_eutran_to_geran(ConnHdlrPars pars) runs on ConnHdlr { |
Pau Espin Pedrol | 408e0ae | 2023-12-15 18:56:31 +0100 | [diff] [blame] | 1346 | f_init_handler(pars); |
| 1347 | f_gtp_register_imsi(g_pars.ue_pars.imsi); |
| 1348 | f_attach(); |
| 1349 | |
Pau Espin Pedrol | 35c0cc2 | 2023-12-21 19:23:48 +0100 | [diff] [blame] | 1350 | /* TS 23.401 Figure D.3.5-1 Steps 1,2,3,4: */ |
| 1351 | f_gtp_sgsn_context_4g_to_2g(); |
Pau Espin Pedrol | 408e0ae | 2023-12-15 18:56:31 +0100 | [diff] [blame] | 1352 | |
Pau Espin Pedrol | 35c0cc2 | 2023-12-21 19:23:48 +0100 | [diff] [blame] | 1353 | /* TS 23.401 Figure D.3.5-1 Step 8: */ |
| 1354 | f_DIA_CancelLocation(); |
Pau Espin Pedrol | 408e0ae | 2023-12-15 18:56:31 +0100 | [diff] [blame] | 1355 | |
Pau Espin Pedrol | 35c0cc2 | 2023-12-21 19:23:48 +0100 | [diff] [blame] | 1356 | /* TS 23.401 Figure D.3.5-1 Step 13: |
| 1357 | * Upon rx of SGSN Context Acknowledge, MME released the ENB/UE context: |
| 1358 | */ |
| 1359 | as_s1ap_handle_UeContextReleaseCmd(); |
Pau Espin Pedrol | 408e0ae | 2023-12-15 18:56:31 +0100 | [diff] [blame] | 1360 | |
Pau Espin Pedrol | 35c0cc2 | 2023-12-21 19:23:48 +0100 | [diff] [blame] | 1361 | /* TS 23.401 Figure D.3.5-1 Step 13: |
Pau Espin Pedrol | 78c5e41 | 2023-12-21 19:50:11 +0100 | [diff] [blame] | 1362 | * After Gn timer triggers, the SGW session is deleted. |
| 1363 | * Make sure Operation Indication is set to 0, to tell the SGW to keep the Session up at the PGW. |
Pau Espin Pedrol | 35c0cc2 | 2023-12-21 19:23:48 +0100 | [diff] [blame] | 1364 | */ |
Pau Espin Pedrol | 78c5e41 | 2023-12-21 19:50:11 +0100 | [diff] [blame] | 1365 | as_GTP2C_DeleteSession_success(tr_GTP2C_Indication(oI := '0'B)); |
Pau Espin Pedrol | 35c0cc2 | 2023-12-21 19:23:48 +0100 | [diff] [blame] | 1366 | /* Let MME some time to handle the Create Session Response: */ |
Pau Espin Pedrol | 408e0ae | 2023-12-15 18:56:31 +0100 | [diff] [blame] | 1367 | f_sleep(3.0); |
| 1368 | } |
| 1369 | testcase TC_ue_cell_reselect_eutran_to_geran() runs on MTC_CT { |
| 1370 | var charstring id := testcasename(); |
| 1371 | |
| 1372 | f_init_diameter(id); |
Pau Espin Pedrol | ae747ac | 2023-12-20 20:55:32 +0100 | [diff] [blame] | 1373 | f_init_s1ap(id, 6); |
Pau Espin Pedrol | 408e0ae | 2023-12-15 18:56:31 +0100 | [diff] [blame] | 1374 | f_init_gtpv2_s11(id); |
| 1375 | f_s1ap_setup(0); |
| 1376 | f_init_gtp(id); |
| 1377 | |
| 1378 | var ConnHdlrPars pars := f_init_pars(ue_idx := 0); |
| 1379 | var ConnHdlr vc_conn; |
| 1380 | vc_conn := f_start_handler_with_pars(refers(f_TC_ue_cell_reselect_eutran_to_geran), pars); |
| 1381 | vc_conn.done; |
| 1382 | } |
| 1383 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 1384 | control { |
| 1385 | execute( TC_s1ap_setup_wrong_plmn() ); |
| 1386 | execute( TC_s1ap_setup_wrong_tac() ); |
| 1387 | execute( TC_s1ap_setup() ); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 1388 | execute( TC_s1ap_attach() ); |
Philipp Maier | 26a09f3 | 2023-09-01 14:18:33 +0200 | [diff] [blame] | 1389 | execute( TC_s1ap_tau_unknown_guti() ); |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 1390 | execute( TC_gn_echo_request() ); |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 1391 | execute( TC_RIM_RAN_INF() ); |
Philipp Maier | 46059f0 | 2023-08-16 14:45:27 +0200 | [diff] [blame] | 1392 | execute( TC_s1ap_reset() ); |
Pau Espin Pedrol | 408e0ae | 2023-12-15 18:56:31 +0100 | [diff] [blame] | 1393 | execute( TC_ue_cell_reselect_eutran_to_geran() ); |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 1394 | } |
| 1395 | |
Philipp Maier | 46059f0 | 2023-08-16 14:45:27 +0200 | [diff] [blame] | 1396 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 1397 | } |