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; |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 16 | import from S1AP_Types all; |
| 17 | import from S1AP_Templates all; |
| 18 | import from S1AP_Emulation all; |
| 19 | import from S1AP_PDU_Descriptions all; |
| 20 | import from S1AP_IEs all; |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 21 | import from S1AP_PDU_Contents all; |
| 22 | import from S1AP_Constants all; |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 23 | |
| 24 | import from NAS_EPS_Types all; |
| 25 | import from NAS_Templates all; |
| 26 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 27 | import from DIAMETER_Types all; |
| 28 | import from DIAMETER_Templates all; |
| 29 | import from DIAMETER_Emulation all; |
| 30 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 31 | import from SGsAP_Types all; |
| 32 | import from SGsAP_Templates all; |
| 33 | import from SGsAP_Emulation all; |
| 34 | |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 35 | import from GTP_Emulation all; |
| 36 | import from GTP_Templates all; |
| 37 | import from GTP_CodecPort all; |
| 38 | import from GTPC_Types all; |
| 39 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 40 | import from LTE_CryptoFunctions all; |
| 41 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 42 | import from L3_Templates all; |
| 43 | import from DNS_Helpers all; |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 44 | import from Osmocom_Types all; |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 45 | import from Osmocom_Gb_Types all; |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 46 | |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 47 | import from GTPv2_Types all; |
| 48 | import from GTPv2_Templates all; |
| 49 | import from GTPv2_Emulation all; |
| 50 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 51 | friend module MME_Tests_SGsAP; |
| 52 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 53 | /* (maximum) number of emulated eNBs */ |
| 54 | const integer NUM_ENB := 3; |
| 55 | |
| 56 | /* (maximum) number of emulated UEs */ |
| 57 | const integer NUM_UE := 3; |
| 58 | |
| 59 | /* parameters of emulated ENB */ |
| 60 | type record EnbParams { |
| 61 | Global_ENB_ID global_enb_id, |
| 62 | integer cell_identity, |
| 63 | SupportedTAs supported_tas |
| 64 | } |
| 65 | |
| 66 | /* parameters of emulated UE */ |
| 67 | type record UeParams { |
| 68 | hexstring imsi |
| 69 | } |
| 70 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 71 | type component MTC_CT { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 72 | /* S1 intreface of emulated ENBs */ |
| 73 | var EnbParams g_enb_pars[NUM_ENB]; |
| 74 | var S1AP_Emulation_CT vc_S1AP[NUM_ENB]; |
| 75 | port S1AP_PT S1AP_UNIT[NUM_ENB]; |
| 76 | port S1APEM_PROC_PT S1AP_PROC[NUM_ENB]; |
| 77 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 78 | /* S6a/S6d interface of emulated HSS */ |
| 79 | var DIAMETER_Emulation_CT vc_DIAMETER; |
| 80 | port DIAMETER_PT DIAMETER_UNIT; |
| 81 | port DIAMETEREM_PROC_PT DIAMETER_PROC; |
| 82 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 83 | /* SGs interface of emulated MSC/VLR */ |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 84 | var SGsAP_Emulation_CT vc_SGsAP; |
| 85 | port SGsAP_PT SGsAP_UNIT; |
| 86 | port SGsAPEM_PROC_PT SGsAP_PROC; |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 87 | |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 88 | /* Gn interface (GTPv1C) of emulated SGSN (Rel. 7) */ |
| 89 | var GTP_Emulation_CT vc_GTP; |
| 90 | |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 91 | /* S11 interface (GTPv2C) of emulated SGW-C */ |
| 92 | var GTPv2_Emulation_CT vc_GTP2; |
| 93 | port GTP2EM_PT TEID0; |
| 94 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 95 | var UeParams g_ue_pars[NUM_UE]; |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 98 | /* Encode an S1AP Global-ENB-ID into an octetstring */ |
| 99 | private function enc_S1AP_Global_ENB_ID(Global_ENB_ID global_enb_id) return octetstring { |
| 100 | |
| 101 | /* Due to the limitations of libfftranscode, we can not define encoders (or decoders) for individual |
| 102 | * information elements (in S1AP_Types.cc). Unfortuantely Global-ENB-ID also appears in BSSGP in its |
| 103 | * encoded form. (see also: GTP-C 3GPP TS 48.018, section 11.3.70). To encode a given Global-ENB-ID |
| 104 | * we craft a full S1AP PDU and encode it. Then we can cut out the encoded Global-ENB-ID from the |
| 105 | * generated octetstring. */ |
| 106 | |
| 107 | var SupportedTAs supported_tas_dummy := {{ |
| 108 | tAC := '0000'O, |
| 109 | broadcastPLMNs := { '00f000'O }, |
| 110 | iE_Extensions := omit |
| 111 | }}; |
| 112 | var octetstring encoded; |
| 113 | var integer global_enb_id_len; |
| 114 | |
| 115 | if (ispresent(global_enb_id.eNB_ID.macroENB_ID)) { |
| 116 | global_enb_id_len := 8; |
| 117 | } else { |
| 118 | /* All other ENB ID types fit into 8 byte (homeENB_ID, short_macroENB_ID, long_macroENB_ID) */ |
| 119 | global_enb_id_len := 9; |
| 120 | } |
| 121 | |
| 122 | encoded := enc_S1AP_PDU(valueof(ts_S1AP_SetupReq(global_enb_id, supported_tas_dummy, v32))); |
| 123 | |
| 124 | return substr(encoded, 11, global_enb_id_len); |
| 125 | } |
| 126 | |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 127 | 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] | 128 | var ConnHdlrPars g_pars; |
| 129 | timer g_Tguard := 30.0; |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 130 | |
| 131 | var GtpPeer g_gn_iface_peer := { connId := 1, remName := mp_gn_remote_ip, remPort := mp_gn_local_port }; |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | type record ConnHdlrPars { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 135 | /* copied over from MTC_CT on start of component */ |
| 136 | EnbParams enb_pars[NUM_ENB], |
| 137 | /* copied over from MTC_CT on start of component */ |
| 138 | UeParams ue_pars, |
| 139 | /* currently used MME (index into enb_pars, S1AP, ...) */ |
| 140 | integer mme_idx |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | modulepar { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 144 | /* S1 interface */ |
| 145 | charstring mp_mme_ip := "127.0.0.1"; |
| 146 | integer mp_mme_s1ap_port := 36412; |
| 147 | charstring mp_s1_local_ip := "127.0.0.1"; |
| 148 | integer mp_s1_local_port := 50000; |
| 149 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 150 | /* S6 interface */ |
| 151 | charstring mp_s6_local_ip := "127.0.0.4"; |
| 152 | integer mp_s6_local_port := 3868; |
| 153 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 154 | /* SGs interface */ |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 155 | charstring mp_sgs_local_ip := "127.0.0.1"; |
| 156 | integer mp_sgs_local_port := 29118; |
| 157 | charstring mp_vlr_name := "vlr.example.net"; |
| 158 | charstring mp_mme_name := "mmec01.mmegi0001.mme.epc.mnc070.mcc901.3gppnetwork.org"; |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 159 | |
| 160 | /* Gn interface (GTPv1C) */ |
| 161 | charstring mp_gn_local_ip := "127.0.0.22"; |
| 162 | integer mp_gn_local_port := 2123; |
| 163 | charstring mp_gn_remote_ip := "127.0.0.2"; |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 164 | |
| 165 | /* S11 interface (GTPv2C, interface between MME and SGW) */ |
| 166 | charstring mp_s11_local_ip := "127.0.0.3"; |
| 167 | integer mp_s11_local_port := 2123; |
| 168 | charstring mp_s11_remote_ip := "127.0.0.2"; |
| 169 | integer mp_s11_remote_port := 2123; |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /* send incoming unit data messages (like reset) to global SGsAP_UNIT port */ |
| 173 | friend function ForwardUnitdataCallback(PDU_SGsAP msg) |
| 174 | runs on SGsAP_Emulation_CT return template PDU_SGsAP { |
| 175 | SGsAP_UNIT.send(msg); |
| 176 | return omit; |
| 177 | } |
| 178 | |
| 179 | friend function f_init_sgsap(charstring id) runs on MTC_CT { |
| 180 | id := id & "-SGsAP"; |
| 181 | var SGsAPOps ops := { |
| 182 | create_cb := refers(SGsAP_Emulation.ExpectedCreateCallback), |
| 183 | unitdata_cb := refers(ForwardUnitdataCallback) |
| 184 | } |
| 185 | var SGsAP_conn_parameters pars := { |
| 186 | remote_ip := "", |
| 187 | remote_sctp_port := -1, |
| 188 | local_ip := mp_sgs_local_ip, |
| 189 | local_sctp_port := mp_sgs_local_port |
| 190 | } |
| 191 | |
| 192 | vc_SGsAP := SGsAP_Emulation_CT.create(id); |
| 193 | map(vc_SGsAP:SGsAP, system:SGsAP_CODEC_PT); |
| 194 | connect(vc_SGsAP:SGsAP_PROC, self:SGsAP_PROC); |
| 195 | connect(vc_SGsAP:SGsAP_UNIT, self:SGsAP_UNIT); |
| 196 | vc_SGsAP.start(SGsAP_Emulation.main(ops, pars, id)); |
| 197 | } |
| 198 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 199 | /* send incoming unit data messages (like reset) to global S1AP_UNIT port */ |
| 200 | friend function S1apForwardUnitdataCallback(S1AP_PDU msg) |
| 201 | runs on S1AP_Emulation_CT return template S1AP_PDU { |
| 202 | S1AP_UNIT.send(msg); |
| 203 | return omit; |
| 204 | } |
| 205 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 206 | friend function f_init_one_enb(charstring id, integer num := 0) runs on MTC_CT { |
| 207 | id := id & "-S1AP" & int2str(num); |
| 208 | var S1APOps ops := { |
Philipp Maier | 7147c92 | 2023-07-07 14:18:32 +0200 | [diff] [blame] | 209 | create_cb := refers(S1AP_Emulation.ExpectedCreateCallback), |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 210 | unitdata_cb := refers(S1apForwardUnitdataCallback) |
| 211 | } |
| 212 | var S1AP_conn_parameters pars := { |
| 213 | remote_ip := mp_mme_ip, |
| 214 | remote_sctp_port := mp_mme_s1ap_port, |
| 215 | local_ip := mp_s1_local_ip, |
| 216 | local_sctp_port := mp_s1_local_port + num, |
| 217 | role := NAS_ROLE_UE |
| 218 | } |
| 219 | var PLMNidentity plmn_id := '00f110'O; |
| 220 | var EnbParams enb_pars := { |
| 221 | global_enb_id := { |
| 222 | pLMNidentity := plmn_id, |
| 223 | eNB_ID := { |
| 224 | macroENB_ID := int2bit(num, 20) |
| 225 | }, |
| 226 | iE_Extensions := omit |
| 227 | }, |
| 228 | cell_identity := num, |
| 229 | supported_tas := { |
| 230 | { |
| 231 | tAC := int2oct(12345, 2), |
| 232 | broadcastPLMNs := { plmn_id }, |
| 233 | iE_Extensions := omit |
| 234 | } |
| 235 | } |
| 236 | }; |
| 237 | |
| 238 | g_enb_pars[num] := enb_pars; |
| 239 | vc_S1AP[num] := S1AP_Emulation_CT.create(id); |
| 240 | map(vc_S1AP[num]:S1AP, system:S1AP_CODEC_PT); |
| 241 | connect(vc_S1AP[num]:S1AP_PROC, self:S1AP_PROC[num]); |
| 242 | connect(vc_S1AP[num]:S1AP_UNIT, self:S1AP_UNIT[num]); |
| 243 | vc_S1AP[num].start(S1AP_Emulation.main(ops, pars, id)); |
| 244 | S1AP_UNIT[num].receive(S1APEM_Event:{up_down:=S1APEM_EVENT_UP}); |
| 245 | } |
| 246 | friend function f_init_one_ue(inout UeParams uep, integer imsi_suffix) { |
| 247 | uep := { |
| 248 | imsi := f_gen_imsi(imsi_suffix) |
| 249 | } |
| 250 | } |
| 251 | friend function f_init_s1ap(charstring id, integer imsi_suffix) runs on MTC_CT { |
| 252 | var integer i; |
| 253 | for (i := 0; i < NUM_ENB; i := i+1) { |
| 254 | f_init_one_enb(id, i); |
| 255 | } |
| 256 | for (i := 0; i < NUM_UE; i := i+1) { |
| 257 | f_init_one_ue(g_ue_pars[i], i*1000 + imsi_suffix); |
| 258 | } |
| 259 | } |
| 260 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 261 | friend function DiameterForwardUnitdataCallback(PDU_DIAMETER msg) |
| 262 | runs on DIAMETER_Emulation_CT return template PDU_DIAMETER { |
| 263 | DIAMETER_UNIT.send(msg); |
| 264 | return omit; |
| 265 | } |
| 266 | |
| 267 | friend function f_init_diameter(charstring id) runs on MTC_CT { |
| 268 | var DIAMETEROps ops := { |
| 269 | create_cb := refers(DIAMETER_Emulation.ExpectedCreateCallback), |
Vadim Yanitskiy | b46f01e | 2021-12-06 03:23:13 +0300 | [diff] [blame] | 270 | unitdata_cb := refers(DiameterForwardUnitdataCallback), |
| 271 | raw := false /* handler mode (IMSI based routing) */ |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 272 | }; |
| 273 | var DIAMETER_conn_parameters pars := { |
| 274 | remote_ip := mp_mme_ip, |
| 275 | remote_sctp_port := -1, |
| 276 | local_ip := mp_s6_local_ip, |
Harald Welte | 61f73d5 | 2020-04-26 21:41:12 +0200 | [diff] [blame] | 277 | local_sctp_port := mp_s6_local_port, |
| 278 | origin_host := "hss.localdomain", |
| 279 | origin_realm := "localdomain", |
Pau Espin Pedrol | 33b4749 | 2022-03-08 17:43:01 +0100 | [diff] [blame] | 280 | auth_app_id := omit, |
Harald Welte | 61f73d5 | 2020-04-26 21:41:12 +0200 | [diff] [blame] | 281 | vendor_app_id := c_DIAMETER_3GPP_S6_AID |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 282 | }; |
| 283 | vc_DIAMETER := DIAMETER_Emulation_CT.create(id); |
| 284 | map(vc_DIAMETER:DIAMETER, system:DIAMETER_CODEC_PT); |
| 285 | connect(vc_DIAMETER:DIAMETER_UNIT, self:DIAMETER_UNIT); |
| 286 | connect(vc_DIAMETER:DIAMETER_PROC, self:DIAMETER_PROC); |
| 287 | vc_DIAMETER.start(DIAMETER_Emulation.main(ops, pars, id)); |
Harald Welte | d01b5d0 | 2020-04-26 22:05:53 +0200 | [diff] [blame] | 288 | |
| 289 | f_diameter_wait_capability(DIAMETER_UNIT); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 290 | } |
| 291 | |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 292 | friend function f_init_gtp(charstring id) runs on MTC_CT { |
| 293 | id := id & "-GTP"; |
| 294 | |
| 295 | var GtpEmulationCfg gtp_cfg := { |
| 296 | gtpc_bind_ip := mp_gn_local_ip, |
| 297 | gtpc_bind_port := mp_gn_local_port, |
| 298 | gtpu_bind_ip := omit, |
| 299 | gtpu_bind_port := omit, |
| 300 | sgsn_role := true |
| 301 | }; |
| 302 | |
| 303 | vc_GTP := GTP_Emulation_CT.create(id); |
| 304 | vc_GTP.start(GTP_Emulation.main(gtp_cfg)); |
| 305 | } |
| 306 | |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 307 | friend function f_init_gtpv2_s11(charstring id) runs on MTC_CT { |
| 308 | id := id & "-GTPV2"; |
| 309 | |
| 310 | var Gtp2EmulationCfg cfg := { |
| 311 | gtpc_bind_ip := mp_s11_local_ip, |
| 312 | gtpc_bind_port := mp_s11_local_port, |
| 313 | gtpc_remote_ip := mp_s11_remote_ip, |
| 314 | gtpc_remote_port := mp_s11_remote_port, |
| 315 | sgw_role := true, |
| 316 | use_gtpu_daemon := false |
| 317 | }; |
| 318 | |
| 319 | vc_GTP2 := GTPv2_Emulation_CT.create(id); |
| 320 | map(vc_GTP2:GTP2C, system:GTP2C); |
| 321 | connect(vc_GTP2:TEID0, self:TEID0); |
| 322 | vc_GTP2.start(GTPv2_Emulation.main(cfg)); |
| 323 | } |
| 324 | |
| 325 | friend template (value) S1AP_IEs.TAI ts_enb_S1AP_TAI(EnbParams enb) := { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 326 | pLMNidentity := enb.global_enb_id.pLMNidentity, |
| 327 | tAC := enb.supported_tas[0].tAC, |
| 328 | iE_Extensions := omit |
| 329 | } |
| 330 | |
| 331 | friend template (value) EUTRAN_CGI ts_enb_S1AP_CGI(EnbParams enb) := { |
| 332 | pLMNidentity := enb.global_enb_id.pLMNidentity, |
| 333 | cell_ID := int2bit(enb.cell_identity, 28), |
| 334 | iE_Extensions := omit |
| 335 | } |
| 336 | |
| 337 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 338 | /* generate parameters for a connection handler */ |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 339 | friend function f_init_pars(integer ue_idx := 0) |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 340 | runs on MTC_CT return ConnHdlrPars { |
| 341 | var ConnHdlrPars pars := { |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 342 | enb_pars := g_enb_pars, |
| 343 | ue_pars := g_ue_pars[ue_idx], |
| 344 | mme_idx := 0 |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 345 | }; |
| 346 | return pars; |
| 347 | } |
| 348 | |
| 349 | type function void_fn(ConnHdlrPars pars) runs on ConnHdlr; |
| 350 | |
| 351 | /* start a connection handler with given parameters */ |
| 352 | friend function f_start_handler_with_pars(void_fn fn, ConnHdlrPars pars, integer s1ap_idx := 0) |
| 353 | runs on MTC_CT return ConnHdlr { |
| 354 | var ConnHdlr vc_conn; |
| 355 | var charstring id := testcasename() & int2str(s1ap_idx); |
| 356 | |
| 357 | vc_conn := ConnHdlr.create(id); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 358 | /* S1AP part */ |
| 359 | connect(vc_conn:S1AP, vc_S1AP[s1ap_idx]:S1AP_CLIENT); |
| 360 | connect(vc_conn:S1AP_PROC, vc_S1AP[s1ap_idx]:S1AP_PROC); |
| 361 | if (isbound(vc_SGsAP)) { |
| 362 | /* SGsAP part */ |
| 363 | connect(vc_conn:SGsAP, vc_SGsAP:SGsAP_CLIENT); |
| 364 | connect(vc_conn:SGsAP_PROC, vc_SGsAP:SGsAP_PROC); |
| 365 | } |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 366 | if (isbound(vc_DIAMETER)) { |
| 367 | connect(vc_conn:DIAMETER, vc_DIAMETER:DIAMETER_CLIENT); |
| 368 | connect(vc_conn:DIAMETER_PROC, vc_DIAMETER:DIAMETER_PROC); |
| 369 | } |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 370 | if (isbound(vc_GTP)) { |
| 371 | connect(vc_conn:GTP, vc_GTP:CLIENT); |
| 372 | connect(vc_conn:GTP_PROC, vc_GTP:CLIENT_PROC); |
| 373 | } |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 374 | if (isbound(vc_GTP2)) { |
| 375 | connect(vc_conn:GTP2, vc_GTP2:CLIENT); |
| 376 | connect(vc_conn:GTP2_PROC, vc_GTP2:CLIENT_PROC); |
| 377 | } |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 378 | |
| 379 | /* We cannot use vc_conn.start(f_init_handler(fn, id, pars)); as we cannot have |
| 380 | * a stand-alone 'derefers()' call, see https://www.eclipse.org/forums/index.php/t/1091364/ */ |
| 381 | vc_conn.start(derefers(fn)(pars)); |
| 382 | return vc_conn; |
| 383 | } |
| 384 | |
| 385 | /* altstep for the global guard timer */ |
| 386 | private altstep as_Tguard()runs on ConnHdlr { |
| 387 | [] g_Tguard.timeout { |
| 388 | setverdict(fail, "Tguard timeout"); |
| 389 | mtc.stop; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | friend function f_init_handler(ConnHdlrPars pars, float t_guard := 30.0) runs on ConnHdlr { |
| 394 | /* make parameters available via component variable */ |
| 395 | g_pars := pars; |
| 396 | /* start guard timre and activate it as default */ |
| 397 | g_Tguard.start(t_guard); |
| 398 | activate(as_Tguard()); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 399 | if (DIAMETER_PROC.checkstate("Connected")) { |
Pau Espin Pedrol | db017f4 | 2023-08-25 19:22:25 +0200 | [diff] [blame] | 400 | f_diameter_expect_imsi(g_pars.ue_pars.imsi); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 401 | } |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 402 | if (SGsAP_PROC.checkstate("Connected")) { |
| 403 | /* Route all SGsAP mesages for our IMSIto us */ |
| 404 | f_create_sgsap_expect(pars.ue_pars.imsi); |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | |
| 409 | |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 410 | friend function f_s1ap_setup(integer idx := 0, template S1AP_IEs.Cause cause := omit) runs on MTC_CT { |
| 411 | var template (present) S1AP_IEs.Cause exp_cause; |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 412 | var boolean exp_fail := false; |
| 413 | timer T := 5.0; |
| 414 | if (not istemplatekind(cause, "omit")) { |
| 415 | exp_fail := true; |
| 416 | exp_cause := cause; |
| 417 | } |
| 418 | |
| 419 | S1AP_UNIT[idx].send(ts_S1AP_SetupReq(g_enb_pars[idx].global_enb_id, |
| 420 | g_enb_pars[idx].supported_tas, v32)); |
| 421 | T.start; |
| 422 | alt { |
| 423 | [exp_fail] S1AP_UNIT[idx].receive(tr_S1AP_SetupFail(exp_cause)) { |
| 424 | setverdict(pass); |
| 425 | } |
| 426 | [not exp_fail] S1AP_UNIT[idx].receive(tr_S1AP_SetupResp) { |
| 427 | setverdict(pass); |
| 428 | } |
| 429 | [] S1AP_UNIT[idx].receive { |
| 430 | setverdict(fail, "Received unexpected S1AP"); |
| 431 | } |
| 432 | [] T.timeout { |
| 433 | setverdict(fail, "Timeout waiting for S1AP Setup result"); |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | /* Unsuccessful S1 Setup procedure to MME (wrong PLMN) */ |
| 439 | testcase TC_s1ap_setup_wrong_plmn() runs on MTC_CT { |
| 440 | var charstring id := testcasename(); |
| 441 | f_init_s1ap(id, 1); |
| 442 | g_enb_pars[0].global_enb_id.pLMNidentity := '62F224'O; |
| 443 | f_s1ap_setup(0, {misc:=unknown_PLMN}); |
| 444 | } |
| 445 | |
| 446 | /* Unsuccessful S1 Setup procedure to MME (wrong PLMN) */ |
| 447 | testcase TC_s1ap_setup_wrong_tac() runs on MTC_CT { |
| 448 | var charstring id := testcasename(); |
| 449 | f_init_s1ap(id, 2); |
| 450 | g_enb_pars[0].supported_tas[0].broadcastPLMNs[0] := '62F224'O; |
| 451 | f_s1ap_setup(0, {misc:=unknown_PLMN}); |
| 452 | } |
| 453 | |
| 454 | /* Successful S1 Setup procedure to MME */ |
| 455 | testcase TC_s1ap_setup() runs on MTC_CT { |
| 456 | var charstring id := testcasename(); |
| 457 | f_init_s1ap(id, 3); |
| 458 | f_s1ap_setup(0); |
| 459 | } |
| 460 | |
| 461 | private const EPS_QualityOfServiceV c_NAS_defaultQoS := { |
| 462 | qCI := '00'O, |
| 463 | maxBitRateUplink := omit, |
| 464 | maxBitRateDownlink := omit, |
| 465 | guaranteedBitRateUplink := omit, |
| 466 | guaranteedBitRateDownlink := omit, |
| 467 | maxBitRateUplinkExt := omit, |
| 468 | maxBitRateDownlinkExt := omit, |
| 469 | guaranteedBitRateUplinkExt := omit, |
| 470 | guaranteedBitRateDownlinkExt := omit, |
| 471 | maxBitRateUplinkExt2 := omit, |
| 472 | maxBitRateDownlinkExt2 := omit, |
| 473 | guaranteedBitRateUplinkExt2 := omit, |
| 474 | guaranteedBitRateDownlinkExt2 := omit |
| 475 | }; |
| 476 | |
| 477 | private const UENetworkCapabilityV c_NAS_defaultUeNetCap := { |
| 478 | eEA := '10000000'B, |
| 479 | eIA := '11000000'B, |
| 480 | uEA := omit, |
| 481 | uIA := omit, |
| 482 | uCS2 := omit, |
| 483 | nF := omit, |
| 484 | vCC := omit, |
| 485 | lCS := omit, |
| 486 | lPP := omit, |
| 487 | aCC_CSFB := omit, |
| 488 | h245_ASH := omit, |
| 489 | proSe := omit, |
| 490 | proSe_dd := omit, |
| 491 | proSe_dc := omit, |
| 492 | proSe_relay := omit, |
| 493 | cP_CIoT := omit, |
| 494 | uP_CIoT := omit, |
| 495 | s1_Udata := omit, |
| 496 | eRwoPDN := omit, |
| 497 | hC_CP_CIoT := omit, |
| 498 | ePCO := omit, |
| 499 | multipleDRB := omit, |
| 500 | v2XPC5 := omit, |
| 501 | restrictEC := omit, |
| 502 | cPbackoff := omit, |
| 503 | dCNR := omit, |
| 504 | n1Mode := omit, |
| 505 | sGC := omit, |
| 506 | spare1 := omit, |
| 507 | spare := omit |
| 508 | }; |
| 509 | |
| 510 | private const octetstring c_NAS_defaultAPN := '00'O; |
| 511 | |
| 512 | private altstep as_s1ap_handle_auth() runs on ConnHdlr { |
| 513 | var PDU_NAS_EPS rx_nas; |
| 514 | [] S1AP.receive(tr_NAS_AuthReq) -> value rx_nas { |
| 515 | /* static XRES result as we fixed the HSS RAND value and always have the following |
| 516 | RAND: 20080c3818183b522614162c07601d0d |
| 517 | AUTN: f11b89a2a8be00001f9c526f3d75d44c |
| 518 | IK: 11329aae8e8d2941bb226b2061137c58 |
| 519 | CK: 740d62df9803eebde5120acf358433d0 |
| 520 | RES: 6a91970e838fd079 |
| 521 | SRES: e91e4777 |
| 522 | Kc: 3b0f999e42198874 |
| 523 | SQN: 32 |
| 524 | IND: 0 |
| 525 | */ |
| 526 | /* KASME: 95AFAD9A0D29AFAA079A9451DF7161D7EE4CBF2AF9387F766D058BB6B44B905D */ |
| 527 | const OCT16 ck := '740d62df9803eebde5120acf358433d0'O; |
| 528 | const OCT16 ik := '11329aae8e8d2941bb226b2061137c58'O; |
| 529 | const OCT16 autn := 'f11b89a2a8be00001f9c526f3d75d44c'O; |
| 530 | const OCT8 res := '6a91970e838fd079'O; |
| 531 | const OCT3 plmn_id := '00F110'O; |
| 532 | const OCT6 sqn := '000000000020'O; |
| 533 | const OCT6 ak := substr(autn, 0, 6) xor4b sqn; |
| 534 | var octetstring kasme := f_kdf_kasme(ck, ik, plmn_id, sqn, ak); |
| 535 | var S1APEM_Config cfg := { |
| 536 | set_nas_keys := { |
| 537 | k_nas_int := f_kdf_nas_int(1, kasme), |
| 538 | k_nas_enc := f_kdf_nas_enc(1, kasme) |
| 539 | } |
| 540 | }; |
| 541 | S1AP.send(cfg); |
| 542 | S1AP.send(ts_NAS_AuthResp(res)); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | private altstep as_s1ap_handle_sec_mode() runs on ConnHdlr { |
| 547 | var PDU_NAS_EPS rx_nas; |
| 548 | var NAS_SecurityAlgorithmsV alg := { |
| 549 | typeOfIntegrityProtection := '001'B, |
| 550 | spare1 := '0'B, |
| 551 | typeOfCiphering := '000'B, |
| 552 | spare2 := '0'B |
| 553 | }; |
| 554 | var NAS_KeySetIdentifierV kset_id := { |
| 555 | identifier := '000'B, |
| 556 | tSC := '0'B |
| 557 | }; |
| 558 | [] S1AP.receive(tr_NAS_SecModeCmd(alg, kset_id, ?)) { |
| 559 | S1AP.send(ts_NAS_SecModeCmpl); |
| 560 | } |
| 561 | } |
| 562 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 563 | /* Exepect AuthInfoReq (AIR) from HSS; respond with AuthInforAnswer (AIA) */ |
| 564 | private altstep as_DIA_AuthInfo() runs on ConnHdlr { |
| 565 | var PDU_DIAMETER rx_dia; |
| 566 | [] DIAMETER.receive(tr_DIA_AIR(g_pars.ue_pars.imsi)) -> value rx_dia { |
| 567 | var template (omit) AVP avp; |
| 568 | var octetstring sess_id; |
| 569 | var octetstring vplmn_id; |
| 570 | var hexstring imsi; |
| 571 | var template (value) AVP_list auth_info_content; |
| 572 | |
| 573 | /* retrieve input data */ |
| 574 | imsi := valueof(f_DIAMETER_get_imsi(rx_dia)); |
| 575 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_BASE_NONE_Session_Id); |
| 576 | sess_id := valueof(avp.avp_data.avp_BASE_NONE_Session_Id); |
| 577 | avp := f_DIAMETER_get_avp(rx_dia, c_AVP_Code_AAA_3GPP_Visited_PLMN_Id); |
| 578 | vplmn_id := valueof(avp.avp_data.avp_AAA_3GPP_Visited_PLMN_Id); |
| 579 | |
| 580 | /* compute tuple */ |
| 581 | auth_info_content := { ts_AVP_EutranVec(1, '20080c3818183b522614162c07601d0d'O, '6a91970e838fd079'O, 'f11b89a2a8be00001f9c526f3d75d44c'O, '95AFAD9A0D29AFAA079A9451DF7161D7EE4CBF2AF9387F766D058BB6B44B905D'O) }; |
| 582 | |
Vadim Yanitskiy | 2dba494 | 2021-12-11 15:46:30 +0300 | [diff] [blame] | 583 | DIAMETER.send(ts_DIA_AIA(auth_info_content, sess_id, |
| 584 | hbh_id := rx_dia.hop_by_hop_id, |
| 585 | ete_id := rx_dia.end_to_end_id)); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 586 | } |
| 587 | } |
| 588 | |
| 589 | /* Expect UpdateLocationReq (ULR); respond with UpdateLocationAnswer (ULA) */ |
| 590 | private altstep as_DIA_UpdLoc() runs on ConnHdlr { |
| 591 | var PDU_DIAMETER rx_dia; |
| 592 | [] DIAMETER.receive(tr_DIA_ULR(g_pars.ue_pars.imsi)) -> value rx_dia { |
| 593 | var template (omit) AVP avp; |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 594 | var hexstring imsi; |
| 595 | var template (value) AVP_list sub_data; |
| 596 | |
| 597 | /* retrieve input data */ |
| 598 | imsi := valueof(f_DIAMETER_get_imsi(rx_dia)); |
| 599 | 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] | 600 | |
| 601 | sub_data := { |
| 602 | ts_AVP_3GPP_SubscriberStatus(SERVICE_GRANTED), |
| 603 | ts_AVP_3GPP_SubscrRauTauTmr(30), |
| 604 | ts_AVP_3GPP_AMBR(1000, 2000), |
| 605 | ts_AVP_3GPP_ApnConfigProfile({ |
| 606 | ts_AVP_3GPP_ContextId(1), |
| 607 | ts_AVP_3GPP_AllApnConfigsIncl, |
| 608 | ts_AVP_3GPP_ApnConfig(1, IPv4, "*") |
| 609 | }) |
| 610 | }; |
| 611 | |
Vadim Yanitskiy | 0e8f516 | 2021-12-15 05:00:32 +0300 | [diff] [blame] | 612 | DIAMETER.send(ts_DIA_ULA(sub_data, avp.avp_data.avp_BASE_NONE_Session_Id, |
| 613 | hbh_id := rx_dia.hop_by_hop_id, |
| 614 | ete_id := rx_dia.end_to_end_id)); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 615 | } |
| 616 | } |
| 617 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 618 | private function f_TC_attach(ConnHdlrPars pars) runs on ConnHdlr { |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 619 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 620 | f_init_handler(pars); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 621 | var template (value) EPS_MobileIdentityV mi := ts_NAS_MobileId_IMSI(pars.ue_pars.imsi); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 622 | var template (value) PDU_NAS_EPS nas_esm, nas_emm; |
| 623 | /* |
| 624 | nas_esm := ts_NAS_ActDefEpsBearCtxReq(bearer_id := '0000'B, proc_tid := int2bit(1,8), |
| 625 | qos := c_NAS_defaultQoS, apn := c_NAS_defaultAPN, |
| 626 | addr_type := '000'B, addr_info := ''O); |
| 627 | */ |
| 628 | nas_esm := ts_NAS_PdnConnReq(bearer_id := '0000'B, proc_tid := int2bit(1,8), |
| 629 | pdn_type := NAS_PDN_T_IPv4, req_type := '001'B); |
| 630 | nas_emm := ts_NAS_AttachRequest(att_type := '000'B, kset_id := '000'B, mobile_id := mi, |
| 631 | ue_net_cap := c_NAS_defaultUeNetCap, |
| 632 | esm_enc := enc_PDU_NAS_EPS(valueof(nas_esm))); |
| 633 | var template (value) S1AP_PDU tx; |
| 634 | tx := ts_S1AP_InitialUE(p_eNB_value := 0, p_nasPdu := enc_PDU_NAS_EPS(valueof(nas_emm)), |
| 635 | p_tAI := ts_enb_S1AP_TAI(g_pars.enb_pars[g_pars.mme_idx]), |
| 636 | p_eUTRAN_CGI := ts_enb_S1AP_CGI(g_pars.enb_pars[g_pars.mme_idx]), |
| 637 | p_rrcCause := mo_Signalling); |
| 638 | S1AP.send(tx); |
| 639 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 640 | as_DIA_AuthInfo(); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 641 | as_s1ap_handle_auth(); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 642 | alt { |
| 643 | [] as_DIA_UpdLoc() { |
| 644 | as_s1ap_handle_sec_mode(); |
| 645 | } |
| 646 | [] as_s1ap_handle_sec_mode() { |
| 647 | as_DIA_UpdLoc(); |
| 648 | } |
| 649 | } |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 650 | |
| 651 | f_sleep(10.0); |
| 652 | } |
| 653 | testcase TC_s1ap_attach() runs on MTC_CT { |
| 654 | var charstring id := testcasename(); |
| 655 | |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 656 | f_init_diameter(id); |
| 657 | f_sleep(10.0); |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 658 | f_init_s1ap(id, 4); |
| 659 | f_s1ap_setup(0); |
| 660 | |
| 661 | var ConnHdlrPars pars := f_init_pars(ue_idx := 0); |
| 662 | var ConnHdlr vc_conn; |
| 663 | vc_conn := f_start_handler_with_pars(refers(f_TC_attach), pars); |
| 664 | vc_conn.done; |
| 665 | } |
| 666 | |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 667 | private function f_TC_gn_echo_request(ConnHdlrPars pars) runs on ConnHdlr { |
| 668 | timer T := 5.0; |
| 669 | f_init_handler(pars); |
| 670 | f_gtp_register_teid('00000000'O); |
| 671 | |
| 672 | GTP.send(ts_GTPC_PING(g_gn_iface_peer, 1)); |
| 673 | T.start; |
| 674 | alt { |
| 675 | [] GTP.receive(tr_GTPC_PONG(?)) { |
| 676 | setverdict(pass); |
| 677 | } |
| 678 | [] GTP.receive { |
| 679 | setverdict(fail, "unexpected GTPC message from MME"); |
| 680 | } |
| 681 | [] T.timeout { |
| 682 | setverdict(fail, "no GTPC ECHO RESPONSE from MME"); |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | testcase TC_gn_echo_request() runs on MTC_CT { |
| 687 | var charstring id := testcasename(); |
| 688 | |
| 689 | f_init_diameter(id); |
| 690 | f_init_s1ap(id, 4); |
| 691 | f_s1ap_setup(0); |
| 692 | f_init_gtp(id); |
| 693 | |
| 694 | var ConnHdlrPars pars := f_init_pars(ue_idx := 0); |
| 695 | var ConnHdlr vc_conn; |
| 696 | vc_conn := f_start_handler_with_pars(refers(f_TC_gn_echo_request), pars); |
| 697 | vc_conn.done; |
| 698 | } |
| 699 | |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 700 | external function enc_PDU_GTPC_RAN_INF_REQ(in PDU_BSSGP_RAN_INFORMATION_REQUEST_GTPC gtpc_pdu) return octetstring |
| 701 | with { extension "prototype(convert)" |
| 702 | extension "encode(RAW)" |
| 703 | } |
| 704 | |
| 705 | external function enc_PDU_GTPC_RAN_INF(in PDU_BSSGP_RAN_INFORMATION_GTPC gtpc_pdu) return octetstring |
| 706 | with { extension "prototype(convert)" |
| 707 | extension "encode(RAW)" |
| 708 | } |
| 709 | |
| 710 | function f_convert_plmn(OCT3 pLMNidentity) return hexstring { |
| 711 | var hexstring pLMNidentity_hex := oct2hex(pLMNidentity); |
| 712 | var hexstring pLMNidentity_hex_swapped; |
| 713 | pLMNidentity_hex_swapped[0] := pLMNidentity_hex[1]; |
| 714 | pLMNidentity_hex_swapped[1] := pLMNidentity_hex[0]; |
| 715 | pLMNidentity_hex_swapped[2] := pLMNidentity_hex[3]; |
| 716 | pLMNidentity_hex_swapped[3] := pLMNidentity_hex[2]; |
| 717 | pLMNidentity_hex_swapped[4] := pLMNidentity_hex[5]; |
| 718 | pLMNidentity_hex_swapped[5] := pLMNidentity_hex[4]; |
| 719 | return pLMNidentity_hex_swapped; |
| 720 | } |
| 721 | |
| 722 | /* Make a template for a GTPC BSSGP container that contains a RAN INFORMATION REQUEST. The template can be used to |
| 723 | * craft the request for the S1AP/S1-MME interface and also to verfify the contents of the coresponding request on |
| 724 | * the GTPC/Gn interface */ |
| 725 | private function f_make_ts_GTPC_RAN_Information_Request(GTP_CellId geran_gtp_ci) |
| 726 | runs on ConnHdlr return template (value) PDU_BSSGP_RAN_INFORMATION_REQUEST_GTPC { |
| 727 | var template (value) RIM_Routing_Address_GTPC gtpc_dst_addr, gtpc_src_addr; |
| 728 | var template (value) RAN_Information_Request_RIM_Container_GTPC gtpc_rim_req_cont; |
| 729 | var template (value) PDU_BSSGP_RAN_INFORMATION_REQUEST_GTPC gtpc_bssgp_cont; |
| 730 | var octetstring gnbid; |
| 731 | var GTP_CellId eutran_gtp_ci; |
| 732 | eutran_gtp_ci.ra_id.lai.mcc_mnc := f_convert_plmn(g_pars.enb_pars[g_pars.mme_idx].global_enb_id.pLMNidentity); |
| 733 | |
| 734 | gnbid := enc_S1AP_Global_ENB_ID(g_pars.enb_pars[g_pars.mme_idx].global_enb_id); |
| 735 | gtpc_dst_addr := t_GTPC_RIM_Routing_Address_cid(geran_gtp_ci); |
| 736 | gtpc_src_addr := t_GTPC_RIM_Routing_Address_enbid(eutran_gtp_ci, |
| 737 | oct2int(g_pars.enb_pars[g_pars.mme_idx].supported_tas[0].tAC), |
| 738 | gnbid); |
| 739 | |
| 740 | gtpc_rim_req_cont := ts_GTPC_RAN_Information_Request_RIM_Container( |
| 741 | ts_GTPC_RIM_Application_Identity(RIM_APP_ID_NACC), |
| 742 | ts_GTPC_RIM_Sequence_Number(1), |
| 743 | ts_GTPC_RIM_PDU_Indications(false, RIM_PDU_TYPE_SING_REP), |
| 744 | ts_GTPC_RIM_Protocol_Version_Number(1), |
| 745 | tsu_GTPC_RAN_Information_Request_Application_Container_NACC(geran_gtp_ci), |
| 746 | omit); |
| 747 | gtpc_bssgp_cont := ts_GTPC_RAN_Information_Request( |
| 748 | ts_GTPC_RIM_Routing_Information(RIM_ADDR_GERAN_CELL_ID, gtpc_dst_addr), |
| 749 | ts_GTPC_RIM_Routing_Information(RIM_ADDR_EUTRAN_NODEB_ID, gtpc_src_addr), |
| 750 | gtpc_rim_req_cont); |
| 751 | |
| 752 | return gtpc_bssgp_cont; |
| 753 | } |
| 754 | |
| 755 | private function f_make_tr_GTPC_RAN_Information_Request(GTP_CellId geran_gtp_ci) |
| 756 | runs on ConnHdlr return template (present) PDU_BSSGP_RAN_INFORMATION_REQUEST_GTPC { |
| 757 | var template (present) RIM_Routing_Address_GTPC gtpc_dst_addr, gtpc_src_addr; |
| 758 | var template (present) RAN_Information_Request_RIM_Container_GTPC gtpc_rim_req_cont; |
| 759 | var template (present) PDU_BSSGP_RAN_INFORMATION_REQUEST_GTPC gtpc_bssgp_cont; |
| 760 | var octetstring gnbid; |
| 761 | var GTP_CellId eutran_gtp_ci; |
| 762 | eutran_gtp_ci.ra_id.lai.mcc_mnc := f_convert_plmn(g_pars.enb_pars[g_pars.mme_idx].global_enb_id.pLMNidentity); |
| 763 | |
| 764 | gnbid := enc_S1AP_Global_ENB_ID(g_pars.enb_pars[g_pars.mme_idx].global_enb_id); |
| 765 | gtpc_dst_addr := t_GTPC_RIM_Routing_Address_cid(geran_gtp_ci); |
| 766 | gtpc_src_addr := t_GTPC_RIM_Routing_Address_enbid(eutran_gtp_ci, |
| 767 | oct2int(g_pars.enb_pars[g_pars.mme_idx].supported_tas[0].tAC), |
| 768 | gnbid); |
| 769 | |
| 770 | gtpc_rim_req_cont := tr_GTPC_RAN_Information_Request_RIM_Container( |
| 771 | ts_GTPC_RIM_Application_Identity(RIM_APP_ID_NACC), |
| 772 | ts_GTPC_RIM_Sequence_Number(1), |
| 773 | ts_GTPC_RIM_PDU_Indications(false, RIM_PDU_TYPE_SING_REP), |
| 774 | ts_GTPC_RIM_Protocol_Version_Number(1), |
| 775 | tru_GTPC_RAN_Information_Request_Application_Container_NACC(geran_gtp_ci)); |
| 776 | gtpc_bssgp_cont := tr_GTPC_RAN_Information_Request( |
| 777 | tr_GTPC_RIM_Routing_Information(RIM_ADDR_GERAN_CELL_ID, gtpc_dst_addr), |
| 778 | tr_GTPC_RIM_Routing_Information(RIM_ADDR_EUTRAN_NODEB_ID, gtpc_src_addr), |
| 779 | gtpc_rim_req_cont); |
| 780 | |
| 781 | return gtpc_bssgp_cont; |
| 782 | } |
| 783 | |
| 784 | /* Make initial RAN INFORMATION REQUEST message that is sent on the S1AP/S1-MME interface */ |
| 785 | private function f_make_ts_S1AP_eNBDirectInfTrans(GTP_CellId geran_gtp_ci) |
| 786 | runs on ConnHdlr return template (value) S1AP_PDU { |
| 787 | var template (value) Inter_SystemInformationTransferType inf; |
| 788 | |
| 789 | inf.rIMTransfer.rIMInformation := enc_PDU_GTPC_RAN_INF_REQ(valueof(f_make_ts_GTPC_RAN_Information_Request(geran_gtp_ci))); |
| 790 | inf.rIMTransfer.rIMRoutingAddress.gERAN_Cell_ID.lAI.pLMNidentity := hex2oct(f_convert_plmn(hex2oct(geran_gtp_ci.ra_id.lai.mcc_mnc))); |
| 791 | inf.rIMTransfer.rIMRoutingAddress.gERAN_Cell_ID.lAI.lAC := int2oct(geran_gtp_ci.ra_id.lai.lac, 2); |
| 792 | inf.rIMTransfer.rIMRoutingAddress.gERAN_Cell_ID.lAI.iE_Extensions := omit; |
| 793 | inf.rIMTransfer.rIMRoutingAddress.gERAN_Cell_ID.rAC := int2oct(geran_gtp_ci.ra_id.rac, 1); |
| 794 | inf.rIMTransfer.rIMRoutingAddress.gERAN_Cell_ID.cI := int2oct(geran_gtp_ci.cell_id, 2); |
| 795 | inf.rIMTransfer.rIMRoutingAddress.gERAN_Cell_ID.iE_Extensions := omit; |
| 796 | inf.rIMTransfer.iE_Extensions := omit; |
| 797 | |
| 798 | return ts_S1AP_eNBDirectInfTrans(inf); |
| 799 | } |
| 800 | |
| 801 | /* Make RAN INFORMATION (response) message that is sent on the GTPC/Gn interface */ |
| 802 | private function f_make_ts_GTPC_RANInfoRelay(template Gtp1cUnitdata req_gtpc_pdu, |
| 803 | GTP_CellId geran_gtp_ci, octetstring geran_si) |
| 804 | runs on ConnHdlr return template (value) Gtp1cUnitdata { |
| 805 | var template Gtp1cUnitdata res_gtpc_pdu; |
| 806 | var template RAN_Information_RIM_Container_GTPC gtpc_rim_res_cont; |
| 807 | var template PDU_BSSGP_RAN_INFORMATION_GTPC gtpc_bssgp_rim_res_pdu; |
| 808 | var template RIM_Routing_Information_GTPC gtpc_rim_dst_cell_id, gtpc_rim_src_cell_id; |
| 809 | var template RIM_RoutingAddress gtpc_rim_ra; |
| 810 | var template RIM_RoutingAddress_Discriminator gtpc_rim_ra_discr; |
| 811 | |
| 812 | /* Assemble GTPC RAN Information */ |
| 813 | gtpc_rim_res_cont := ts_GTPC_RAN_Information_RIM_Container(ts_GTPC_RIM_Application_Identity(RIM_APP_ID_NACC), |
| 814 | ts_GTPC_RIM_Sequence_Number(2), |
| 815 | ts_GTPC_RIM_PDU_Indications(false, RIM_PDU_TYPE_SING_REP), |
| 816 | ts_GTPC_RIM_Protocol_Version_Number(1), |
| 817 | tsu_GTPC_ApplContainer_or_ApplErrContainer_NACC(tsu_GTPC_ApplContainer_NACC(geran_gtp_ci, false, 3, geran_si)), |
| 818 | omit); |
| 819 | |
| 820 | /* The source becomes the destination and vice versa */ |
| 821 | gtpc_rim_dst_cell_id := req_gtpc_pdu.gtpc.gtpc_pdu.ranInformationRelay.transparentContainer. |
| 822 | rANTransparentContainerField.pDU_BSSGP_RAN_INFORMATION_REQUEST.source_Cell_Identifier |
| 823 | gtpc_rim_src_cell_id := req_gtpc_pdu.gtpc.gtpc_pdu.ranInformationRelay.transparentContainer. |
| 824 | rANTransparentContainerField.pDU_BSSGP_RAN_INFORMATION_REQUEST.destination_Cell_Identifier |
| 825 | gtpc_bssgp_rim_res_pdu := ts_GTPC_RAN_Information(gtpc_rim_dst_cell_id, |
| 826 | gtpc_rim_src_cell_id, |
| 827 | gtpc_rim_res_cont); |
| 828 | |
| 829 | /* Assemble RIM Routing Address (essentially a copy of the destination cell identifier)*/ |
| 830 | gtpc_rim_ra := ts_RIM_RoutingAddress(enc_RIM_Routing_Address_GTPC(valueof(gtpc_rim_dst_cell_id.rIM_Routing_Address))); |
| 831 | gtpc_rim_ra_discr := ts_RIM_RoutingAddress_Discriminator(hex2bit(valueof(gtpc_rim_dst_cell_id.rIMRoutingAddressDiscriminator))); |
| 832 | |
| 833 | res_gtpc_pdu := ts_GTPC_RANInfoRelay(g_gn_iface_peer, |
| 834 | ts_RANTransparentContainer_RAN_INFO(gtpc_bssgp_rim_res_pdu), |
| 835 | gtpc_rim_ra, gtpc_rim_ra_discr); |
| 836 | |
| 837 | return res_gtpc_pdu; |
| 838 | } |
| 839 | |
| 840 | /* Make template to verify the RAN INFORMATION REQUEST as it appears on the GTPC/Gn interface */ |
| 841 | private function f_make_tr_GTPC_MsgType(GTP_CellId geran_gtp_ci) |
| 842 | runs on ConnHdlr return template (present) Gtp1cUnitdata { |
| 843 | var template Gtp1cUnitdata msg; |
| 844 | var template GTPC_PDUs pdus; |
| 845 | var template RANTransparentContainer ran_transp_cont; |
| 846 | |
| 847 | ran_transp_cont := tr_RANTransparentContainer_RAN_INFO_REQ( |
| 848 | f_make_tr_GTPC_RAN_Information_Request(geran_gtp_ci)); |
| 849 | pdus := tr_RANInfoRelay(ran_transp_cont); |
| 850 | msg := tr_GTPC_MsgType(g_gn_iface_peer, rANInformationRelay, '00000000'O, pdus); |
| 851 | |
| 852 | return msg; |
| 853 | } |
| 854 | |
| 855 | /* Make template to verify the RAN INFORMATION (response) as it appears on the S1AP/S1-MME interface */ |
| 856 | private function f_make_tr_S1AP_MMEDirectInfTrans(Gtp1cUnitdata ran_information_gtpc_pdu) |
| 857 | runs on ConnHdlr return template (present) S1AP_PDU { |
| 858 | var template S1AP_PDU msg; |
| 859 | var template Inter_SystemInformationTransferType inf; |
| 860 | |
| 861 | inf.rIMTransfer.rIMInformation := enc_PDU_GTPC_RAN_INF( |
| 862 | ran_information_gtpc_pdu.gtpc.gtpc_pdu.ranInformationRelay. |
| 863 | transparentContainer.rANTransparentContainerField. |
| 864 | pDU_BSSGP_RAN_INFORMATION); |
| 865 | inf.rIMTransfer.rIMRoutingAddress := omit; |
| 866 | inf.rIMTransfer.iE_Extensions := omit; |
| 867 | msg := tr_S1AP_MMEDirectInfTrans(inf); |
| 868 | |
| 869 | return msg; |
| 870 | } |
| 871 | |
| 872 | private function f_TC_RIM_RAN_INF(ConnHdlrPars pars) runs on ConnHdlr { |
| 873 | timer T := 5.0; |
| 874 | f_init_handler(pars); |
| 875 | f_gtp_register_teid('00000000'O); |
| 876 | var Gtp1cUnitdata req_gtpc_pdu; |
| 877 | var Gtp1cUnitdata resp_gtpc_pdu; |
| 878 | var GTP_CellId geran_gtp_ci; |
| 879 | |
| 880 | /* Assemble data of a fictitiously GERAN cell */ |
| 881 | geran_gtp_ci.ra_id.rac := oct2int('BB'O); |
| 882 | geran_gtp_ci.ra_id.lai.mcc_mnc := '262f42'H |
| 883 | geran_gtp_ci.ra_id.lai.lac := oct2int('AAAA'O); |
| 884 | geran_gtp_ci.cell_id := oct2int('04C7'O); |
| 885 | const octetstring geran_si1 := '198fb100000000000000000000000000007900002b'O; |
| 886 | const octetstring geran_si3 := '1b753000f110236ec9033c2747407900003c0b2b2b'O; |
| 887 | const octetstring geran_si13 := '009000185a6fc9e08410ab2b2b2b2b2b2b2b2b2b2b'O; |
| 888 | const octetstring geran_si := geran_si1 & geran_si3 & geran_si13; |
| 889 | |
| 890 | /* Send initial RAN information request via S1AP to MME and expect the MME to forward the request on GTP-C |
| 891 | * (eNB -> MME -> SGSN) */ |
| 892 | S1AP.send(f_make_ts_S1AP_eNBDirectInfTrans(geran_gtp_ci)); |
| 893 | T.start; |
| 894 | alt { |
| 895 | [] GTP.receive(f_make_tr_GTPC_MsgType(geran_gtp_ci)) -> value req_gtpc_pdu { |
| 896 | setverdict(pass); |
| 897 | } |
| 898 | [] GTP.receive { |
| 899 | setverdict(fail, "unexpected GTPC message from MME"); |
| 900 | } |
| 901 | [] T.timeout { |
| 902 | setverdict(fail, "no GTPC RAN INFORMATION REQUEST from MME"); |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | /* Send RAN information response via GTP-C to MME and expect the MME to forward the respnse on S1AP |
| 907 | * (SGSN -> MME -> eNB) */ |
| 908 | f_create_s1ap_expect_proc(id_MMEDirectInformationTransfer, self); |
| 909 | resp_gtpc_pdu := valueof(f_make_ts_GTPC_RANInfoRelay(req_gtpc_pdu, geran_gtp_ci, geran_si)); |
| 910 | GTP.send(resp_gtpc_pdu); |
| 911 | T.start; |
| 912 | alt { |
| 913 | [] S1AP.receive(f_make_tr_S1AP_MMEDirectInfTrans(resp_gtpc_pdu)) { |
| 914 | setverdict(pass); |
| 915 | } |
| 916 | [] S1AP.receive { |
| 917 | setverdict(fail, "unexpected S1AP message from MME"); |
| 918 | } |
| 919 | [] T.timeout { |
| 920 | setverdict(fail, "no S1AP RAN INFORMATION from MME"); |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | setverdict(pass); |
| 925 | } |
| 926 | |
| 927 | testcase TC_RIM_RAN_INF() runs on MTC_CT { |
| 928 | var charstring id := testcasename(); |
| 929 | |
| 930 | f_init_diameter(id); |
| 931 | f_init_s1ap(id, 4); |
| 932 | f_s1ap_setup(0); |
| 933 | f_init_gtp(id); |
| 934 | |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 935 | var ConnHdlrPars pars := f_init_pars(ue_idx := 0); |
| 936 | var ConnHdlr vc_conn; |
| 937 | vc_conn := f_start_handler_with_pars(refers(f_TC_RIM_RAN_INF), pars); |
| 938 | |
| 939 | vc_conn.done; |
| 940 | } |
| 941 | |
Philipp Maier | 46059f0 | 2023-08-16 14:45:27 +0200 | [diff] [blame] | 942 | /* Successful RESET procedure from eNB to MME */ |
| 943 | testcase TC_s1ap_reset() runs on MTC_CT { |
| 944 | var charstring id := testcasename(); |
| 945 | f_init_s1ap(id, 3); |
| 946 | f_s1ap_setup(0); |
| 947 | |
Philipp Maier | 9abb8c9 | 2023-08-31 13:12:28 +0200 | [diff] [blame] | 948 | var template (value) S1AP_IEs.Cause reset_cause := {misc := om_intervention}; |
Philipp Maier | 46059f0 | 2023-08-16 14:45:27 +0200 | [diff] [blame] | 949 | var template (value) ResetType reset_type := {s1_Interface := reset_all}; |
| 950 | timer T := 5.0; |
| 951 | |
| 952 | S1AP_UNIT[0].send(ts_S1AP_Reset(reset_cause, reset_type)); |
| 953 | T.start; |
| 954 | alt { |
| 955 | [] S1AP_UNIT[0].receive(tr_S1AP_ResetAck_any) { |
| 956 | setverdict(pass); |
| 957 | } |
| 958 | [] S1AP_UNIT[0].receive { |
| 959 | setverdict(fail, "Received unexpected S1AP"); |
| 960 | } |
| 961 | [] T.timeout { |
| 962 | setverdict(fail, "Timeout waiting for S1AP Setup result"); |
| 963 | } |
| 964 | } |
| 965 | } |
| 966 | |
Harald Welte | 95333a1 | 2019-07-11 22:51:45 +0800 | [diff] [blame] | 967 | control { |
| 968 | execute( TC_s1ap_setup_wrong_plmn() ); |
| 969 | execute( TC_s1ap_setup_wrong_tac() ); |
| 970 | execute( TC_s1ap_setup() ); |
Harald Welte | 6ec6439 | 2019-08-14 12:37:07 +0200 | [diff] [blame] | 971 | execute( TC_s1ap_attach() ); |
Philipp Maier | 74d776a | 2023-07-12 14:04:14 +0200 | [diff] [blame] | 972 | execute( TC_gn_echo_request() ); |
Philipp Maier | a930620 | 2023-07-24 11:41:51 +0200 | [diff] [blame] | 973 | execute( TC_RIM_RAN_INF() ); |
Philipp Maier | 46059f0 | 2023-08-16 14:45:27 +0200 | [diff] [blame] | 974 | execute( TC_s1ap_reset() ); |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 975 | } |
| 976 | |
Philipp Maier | 46059f0 | 2023-08-16 14:45:27 +0200 | [diff] [blame] | 977 | |
Harald Welte | b8a4ac8 | 2019-06-23 11:04:12 +0200 | [diff] [blame] | 978 | } |