Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 1 | module GBProxy_Tests { |
| 2 | |
| 3 | /* Osmocom GBProxy test suite in TTCN-3 |
| 4 | * (C) 2020 sysmocom - s.f.m.c. GmbH |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Author: Daniel Willmann <dwillmann@sysmocom.de> |
| 8 | |
| 9 | * Released under the terms of GNU General Public License, Version 2 or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 13 | */ |
| 14 | |
| 15 | import from General_Types all; |
| 16 | import from Osmocom_Types all; |
| 17 | import from GSM_Types all; |
| 18 | import from Native_Functions all; |
| 19 | import from NS_Types all; |
| 20 | import from NS_Emulation all; |
| 21 | import from BSSGP_Types all; |
| 22 | import from BSSGP_Emulation all; |
| 23 | import from SCCPasp_Types all; |
| 24 | import from Osmocom_Gb_Types all; |
| 25 | |
| 26 | import from MobileL3_CommonIE_Types all; |
| 27 | import from MobileL3_GMM_SM_Types all; |
| 28 | import from MobileL3_Types all; |
| 29 | import from L3_Templates all; |
| 30 | import from L3_Common all; |
| 31 | |
| 32 | import from TELNETasp_PortType all; |
| 33 | import from Osmocom_VTY_Functions all; |
| 34 | |
| 35 | import from LLC_Types all; |
| 36 | import from LLC_Templates all; |
| 37 | |
| 38 | import from GSM_RR_Types all; |
| 39 | |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 40 | /* mcc_mnc is 24.008 10.5.5.15 encoded. 262 42 */ |
| 41 | const BcdMccMnc c_mcc_mnc := '262F42'H; |
| 42 | |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 43 | modulepar { |
| 44 | /* IP/port on which we run our internal GSUP/HLR emulation */ |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 45 | NSConfigurations mp_nsconfig_sgsn := { |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 46 | { |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 47 | nsei := 101, |
| 48 | role_sgsn := true, |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 49 | handle_sns := false, |
| 50 | nsvc := { |
| 51 | { |
| 52 | provider := { |
| 53 | ip := { |
| 54 | address_family := AF_INET, |
| 55 | local_udp_port := 7777, |
| 56 | local_ip := "127.0.0.1", |
| 57 | remote_udp_port := 23000, |
| 58 | remote_ip := "127.0.0.1" |
| 59 | } |
| 60 | }, |
| 61 | nsvci := 101 |
| 62 | } |
| 63 | } |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 64 | } |
| 65 | }; |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 66 | NSConfigurations mp_nsconfig_pcu := { |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 67 | { |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 68 | nsei := 96, |
| 69 | role_sgsn := false, |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 70 | handle_sns := false, |
| 71 | nsvc := { |
| 72 | { |
| 73 | provider := { |
| 74 | ip := { |
| 75 | address_family := AF_INET, |
| 76 | local_udp_port := 21010, |
| 77 | local_ip := "127.0.0.1", |
| 78 | remote_udp_port := 23000, |
| 79 | remote_ip := "127.0.0.1" |
| 80 | } |
| 81 | }, |
| 82 | nsvci := 97 |
| 83 | } |
| 84 | } |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 85 | }, |
| 86 | { |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 87 | nsei := 97, |
| 88 | role_sgsn := false, |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 89 | handle_sns := false, |
| 90 | nsvc := { |
| 91 | { |
| 92 | provider := { |
| 93 | ip := { |
| 94 | address_family := AF_INET, |
| 95 | local_udp_port := 21011, |
| 96 | local_ip := "127.0.0.1", |
| 97 | remote_udp_port := 23000, |
| 98 | remote_ip := "127.0.0.1" |
| 99 | } |
| 100 | }, |
| 101 | nsvci := 98 |
| 102 | } |
| 103 | } |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 104 | }, |
| 105 | { |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 106 | nsei := 98, |
| 107 | role_sgsn := false, |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 108 | handle_sns := false, |
| 109 | nsvc := { |
| 110 | { |
| 111 | provider := { |
| 112 | ip := { |
| 113 | address_family := AF_INET, |
| 114 | local_udp_port := 21012, |
| 115 | local_ip := "127.0.0.1", |
| 116 | remote_udp_port := 23000, |
| 117 | remote_ip := "127.0.0.1" |
| 118 | } |
| 119 | }, |
| 120 | nsvci := 99 |
| 121 | } |
| 122 | } |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 123 | } |
| 124 | }; |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 125 | BssgpConfigs mp_gbconfigs := { |
| 126 | { |
| 127 | nsei := 96, |
| 128 | sgsn_role := false, |
| 129 | bvc := { |
| 130 | { |
| 131 | bvci := 196, |
| 132 | cell_id := { |
| 133 | ra_id := { |
| 134 | lai := { |
| 135 | mcc_mnc := c_mcc_mnc, |
| 136 | lac := 13135 |
| 137 | }, |
| 138 | rac := 0 |
| 139 | }, |
| 140 | cell_id := 20960 |
| 141 | }, |
| 142 | depth := BSSGP_DECODE_DEPTH_BSSGP, |
| 143 | create_cb := refers(BSSGP_Emulation.DefaultCreateCallback) |
| 144 | } |
| 145 | } |
| 146 | }, { |
| 147 | nsei := 97, |
| 148 | sgsn_role := false, |
| 149 | bvc := { |
| 150 | { |
| 151 | bvci := 210, |
| 152 | cell_id := { |
| 153 | ra_id := { |
| 154 | lai := { |
| 155 | mcc_mnc := c_mcc_mnc, |
| 156 | lac := 13200 |
| 157 | }, |
| 158 | rac := 0 |
| 159 | }, |
| 160 | cell_id := 20961 |
| 161 | }, |
| 162 | depth := BSSGP_DECODE_DEPTH_BSSGP, |
| 163 | create_cb := refers(BSSGP_Emulation.DefaultCreateCallback) |
| 164 | } |
| 165 | } |
| 166 | }, { |
| 167 | nsei := 98, |
| 168 | sgsn_role := false, |
| 169 | bvc := { |
| 170 | { |
| 171 | bvci := 220, |
| 172 | cell_id := { |
| 173 | ra_id := { |
| 174 | lai := { |
| 175 | mcc_mnc := c_mcc_mnc, |
| 176 | lac := 13300 |
| 177 | }, |
| 178 | rac := 0 |
| 179 | }, |
| 180 | cell_id := 20962 |
| 181 | }, |
| 182 | depth := BSSGP_DECODE_DEPTH_BSSGP, |
| 183 | create_cb := refers(BSSGP_Emulation.DefaultCreateCallback) |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | } |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | const integer NUM_BVC_PER_NSE := 3; |
| 191 | type record GbInstance { |
| 192 | NS_CT vc_NS, |
| 193 | BSSGP_CT vc_BSSGP, |
| 194 | BSSGP_BVC_CT vc_BSSGP_BVC[NUM_BVC_PER_NSE], |
| 195 | BssgpConfig cfg |
| 196 | }; |
| 197 | |
| 198 | const integer NUM_PCU := 3; |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 199 | type record of GbInstance GbInstances; |
| 200 | type record of BssgpConfig BssgpConfigs; |
| 201 | type record of NSConfiguration NSConfigurations; |
| 202 | type record of BssgpCellId BssgpCellIds; |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 203 | |
| 204 | const integer NUM_SGSN := 1; |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 205 | |
| 206 | type component test_CT { |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 207 | var GbInstances g_pcu; |
| 208 | var GbInstances g_sgsn; |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 209 | |
| 210 | port BSSGP_CT_PROC_PT PROC; |
| 211 | |
Harald Welte | fbae83f | 2020-11-15 23:25:55 +0100 | [diff] [blame] | 212 | port BSSGP_BVC_MGMT_PT SGSN_MGMT; |
| 213 | port BSSGP_BVC_MGMT_PT PCU_MGMT; |
| 214 | |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 215 | port TELNETasp_PT GBPVTY; |
| 216 | |
| 217 | var boolean g_initialized := false; |
| 218 | var boolean g_use_echo := false; |
| 219 | }; |
| 220 | |
| 221 | type component BSSGP_ConnHdlr { |
| 222 | port BSSGP_PT PCU[NUM_PCU]; |
| 223 | port BSSGP_PT PCU_SIG[NUM_PCU]; |
| 224 | port BSSGP_PROC_PT PCU_PROC[NUM_PCU]; |
| 225 | port BSSGP_PT SGSN[NUM_SGSN]; |
| 226 | port BSSGP_PT SGSN_SIG[NUM_SGSN]; |
| 227 | port BSSGP_PROC_PT SGSN_PROC[NUM_SGSN]; |
| 228 | |
| 229 | var BSSGP_ConnHdlrPars g_pars; |
| 230 | timer g_Tguard; |
| 231 | var LLC_Entities llc; |
| 232 | } |
| 233 | |
| 234 | type record SGSN_ConnHdlrNetworkPars { |
| 235 | boolean expect_ptmsi, |
| 236 | boolean expect_auth, |
| 237 | boolean expect_ciph |
| 238 | }; |
| 239 | |
| 240 | type record BSSGP_ConnHdlrPars { |
| 241 | /* IMEI of the simulated ME */ |
| 242 | hexstring imei, |
| 243 | /* IMSI of the simulated MS */ |
| 244 | hexstring imsi, |
| 245 | /* MSISDN of the simulated MS (probably unused) */ |
| 246 | hexstring msisdn, |
| 247 | /* P-TMSI allocated to the simulated MS */ |
| 248 | OCT4 p_tmsi optional, |
| 249 | OCT3 p_tmsi_sig optional, |
| 250 | /* TLLI of the simulated MS */ |
| 251 | OCT4 tlli, |
| 252 | OCT4 tlli_old optional, |
| 253 | RoutingAreaIdentificationV ra optional, |
| 254 | BssgpCellIds bssgp_cell_id, |
| 255 | float t_guard |
| 256 | }; |
| 257 | |
| 258 | private function f_cellid_to_RAI(in BssgpCellId cell_id) return RoutingAreaIdentificationV { |
| 259 | /* mcc_mnc is encoded as of 24.008 10.5.5.15 */ |
| 260 | var BcdMccMnc mcc_mnc := cell_id.ra_id.lai.mcc_mnc; |
| 261 | |
| 262 | var RoutingAreaIdentificationV ret := { |
| 263 | mccDigit1 := mcc_mnc[0], |
| 264 | mccDigit2 := mcc_mnc[1], |
| 265 | mccDigit3 := mcc_mnc[2], |
| 266 | mncDigit3 := mcc_mnc[3], |
| 267 | mncDigit1 := mcc_mnc[4], |
| 268 | mncDigit2 := mcc_mnc[5], |
| 269 | lac := int2oct(cell_id.ra_id.lai.lac, 16), |
| 270 | rac := int2oct(cell_id.ra_id.rac, 8) |
| 271 | } |
| 272 | return ret; |
| 273 | }; |
| 274 | |
| 275 | private function f_init_gb_pcu(inout GbInstance gb, charstring id, integer offset) runs on test_CT { |
Harald Welte | b419d0e | 2020-11-16 16:45:05 +0100 | [diff] [blame] | 276 | var charstring ns_id := id & "-NS(PCU[" & int2str(offset) & "])"; |
| 277 | var charstring bssgp_id := id & "-BSSGP(PCU[" & int2str(offset) & "])"; |
| 278 | gb.vc_NS := NS_CT.create(ns_id); |
| 279 | gb.vc_BSSGP := BSSGP_CT.create(bssgp_id); |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 280 | /* connect lower end of BSSGP emulation with NS upper port */ |
| 281 | connect(gb.vc_BSSGP:BSCP, gb.vc_NS:NS_SP); |
| 282 | |
Harald Welte | b419d0e | 2020-11-16 16:45:05 +0100 | [diff] [blame] | 283 | gb.vc_NS.start(NSStart(mp_nsconfig_pcu[offset], ns_id)); |
| 284 | gb.vc_BSSGP.start(BssgpStart(gb.cfg, bssgp_id)); |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 285 | |
| 286 | for (var integer i := 0; i < lengthof(gb.cfg.bvc); i := i + 1) { |
| 287 | connect(self:PROC, gb.vc_BSSGP:PROC); |
| 288 | gb.vc_BSSGP_BVC[i] := f_bssgp_get_bvci_ct(gb.cfg.bvc[i].bvci, PROC); |
| 289 | disconnect(self:PROC, gb.vc_BSSGP:PROC); |
Harald Welte | fbae83f | 2020-11-15 23:25:55 +0100 | [diff] [blame] | 290 | connect(self:PCU_MGMT, gb.vc_BSSGP_BVC[i]:MGMT); |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 291 | } |
| 292 | } |
| 293 | |
| 294 | private function f_init_gb_sgsn(inout GbInstance gb, charstring id, integer offset) runs on test_CT { |
Harald Welte | b419d0e | 2020-11-16 16:45:05 +0100 | [diff] [blame] | 295 | var charstring ns_id := id & "-NS(SGSN[" & int2str(offset) & "])"; |
| 296 | var charstring bssgp_id := id & "-BSSGP(SGSN[" & int2str(offset) & "])"; |
| 297 | gb.vc_NS := NS_CT.create(ns_id); |
| 298 | gb.vc_BSSGP := BSSGP_CT.create(bssgp_id); |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 299 | /* connect lower end of BSSGP emulation with NS upper port */ |
| 300 | connect(gb.vc_BSSGP:BSCP, gb.vc_NS:NS_SP); |
| 301 | |
Harald Welte | b419d0e | 2020-11-16 16:45:05 +0100 | [diff] [blame] | 302 | gb.vc_NS.start(NSStart(mp_nsconfig_sgsn[offset], ns_id)); |
| 303 | gb.vc_BSSGP.start(BssgpStart(gb.cfg, bssgp_id)); |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 304 | |
| 305 | for (var integer i := 0; i < lengthof(gb.cfg.bvc); i := i + 1) { |
| 306 | connect(self:PROC, gb.vc_BSSGP:PROC); |
| 307 | gb.vc_BSSGP_BVC[i] := f_bssgp_get_bvci_ct(gb.cfg.bvc[i].bvci, PROC); |
| 308 | disconnect(self:PROC, gb.vc_BSSGP:PROC); |
Harald Welte | fbae83f | 2020-11-15 23:25:55 +0100 | [diff] [blame] | 309 | connect(self:SGSN_MGMT, gb.vc_BSSGP_BVC[i]:MGMT); |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
| 313 | |
| 314 | private function f_init_vty() runs on test_CT { |
| 315 | map(self:GBPVTY, system:GBPVTY); |
| 316 | f_vty_set_prompts(GBPVTY); |
| 317 | f_vty_transceive(GBPVTY, "enable"); |
| 318 | } |
| 319 | |
Harald Welte | fbae83f | 2020-11-15 23:25:55 +0100 | [diff] [blame] | 320 | type record of integer ro_integer; |
| 321 | |
| 322 | private function ro_integer_contains(ro_integer r, integer x) return boolean { |
| 323 | for (var integer j := 0; j < lengthof(r); j := j+1) { |
| 324 | if (r[j] == x) { |
| 325 | return true; |
| 326 | } |
| 327 | } |
| 328 | return false; |
| 329 | } |
| 330 | |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 331 | function f_init() runs on test_CT { |
Harald Welte | fbae83f | 2020-11-15 23:25:55 +0100 | [diff] [blame] | 332 | var ro_integer bvci_unblocked := {}; |
| 333 | var BssgpStatusIndication bsi; |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 334 | var integer i; |
| 335 | |
| 336 | if (g_initialized == true) { |
| 337 | return; |
| 338 | } |
| 339 | g_initialized := true; |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 340 | |
| 341 | g_sgsn[0].cfg := { |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 342 | nsei := mp_nsconfig_sgsn[0].nsei, |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 343 | sgsn_role := true, |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 344 | bvc := { } |
| 345 | } |
| 346 | for (i := 0; i < lengthof(mp_gbconfigs); i := i+1) { |
| 347 | g_pcu[i].cfg := mp_gbconfigs[i]; |
| 348 | /* concatenate all the PCU-side BVCs for the SGSN side */ |
| 349 | g_sgsn[0].cfg.bvc := g_sgsn[0].cfg.bvc & mp_gbconfigs[i].bvc; |
| 350 | } |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 351 | |
| 352 | f_init_vty(); |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 353 | for (i := 0; i < lengthof(mp_nsconfig_sgsn); i := i+1) { |
Harald Welte | b419d0e | 2020-11-16 16:45:05 +0100 | [diff] [blame] | 354 | f_init_gb_sgsn(g_sgsn[0], "GbProxy_Test", 0); |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 355 | } |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 356 | f_sleep(4.0); |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 357 | for (i := 0; i < lengthof(mp_nsconfig_pcu); i := i+1) { |
Harald Welte | b419d0e | 2020-11-16 16:45:05 +0100 | [diff] [blame] | 358 | f_init_gb_pcu(g_pcu[i], "GbProxy_Test", i); |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 359 | } |
Harald Welte | fbae83f | 2020-11-15 23:25:55 +0100 | [diff] [blame] | 360 | |
| 361 | /* wait until all BVC are unblocked on both sides */ |
| 362 | timer T := 5.0; |
| 363 | T.start; |
| 364 | alt { |
| 365 | [] SGSN_MGMT.receive(BssgpStatusIndication:{*, ?, BVC_S_UNBLOCKED}) -> value bsi { |
| 366 | bvci_unblocked := bvci_unblocked & { bsi.bvci }; |
| 367 | if (lengthof(bvci_unblocked) != lengthof(g_sgsn[0].cfg.bvc)) { |
| 368 | repeat; |
| 369 | } |
| 370 | } |
| 371 | [] SGSN_MGMT.receive(BssgpStatusIndication:{*, ?, ?}) { |
| 372 | repeat; |
| 373 | } |
| 374 | [] SGSN_MGMT.receive { |
| 375 | setverdict(fail, "Received unexpected message on SGSN_MGMT"); |
| 376 | mtc.stop; |
| 377 | } |
| 378 | |
| 379 | [] PCU_MGMT.receive(BssgpStatusIndication:{*, ?, BVC_S_UNBLOCKED}) -> value bsi { |
| 380 | repeat; |
| 381 | } |
| 382 | [] PCU_MGMT.receive(BssgpStatusIndication:{*, ?, ?}) { |
| 383 | repeat; |
| 384 | } |
| 385 | [] PCU_MGMT.receive(BssgpResetIndication:{0}) { |
| 386 | repeat; |
| 387 | } |
| 388 | [] PCU_MGMT.receive { |
| 389 | setverdict(fail, "Received unexpected message on PCU_MGMT"); |
| 390 | mtc.stop; |
| 391 | } |
| 392 | |
| 393 | [] T.timeout { |
| 394 | setverdict(fail, "Timeout waiting for unblock of all BVCs"); |
| 395 | mtc.stop; |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | /* iterate over list and check all BVCI */ |
| 400 | for (i := 0; i < lengthof(g_sgsn[0].cfg.bvc); i := i+1) { |
| 401 | var BssgpBvci bvci := g_sgsn[0].cfg.bvc[i].bvci; |
| 402 | if (not ro_integer_contains(bvci_unblocked, bvci)) { |
| 403 | setverdict(fail, "BVCI=", bvci, " was not unblocked during start-up"); |
| 404 | mtc.stop; |
| 405 | } |
| 406 | } |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | function f_cleanup() runs on test_CT { |
| 410 | self.stop; |
| 411 | } |
| 412 | |
| 413 | type function void_fn(charstring id) runs on BSSGP_ConnHdlr; |
| 414 | |
| 415 | /* helper function to create, connect and start a BSSGP_ConnHdlr component */ |
Harald Welte | 6d63f74 | 2020-11-15 19:44:04 +0100 | [diff] [blame] | 416 | function f_start_handler(void_fn fn, charstring id, GbInstances pcu, GbInstances sgsn, integer imsi_suffix, |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 417 | float t_guard := 30.0) |
| 418 | runs on test_CT return BSSGP_ConnHdlr { |
| 419 | var BSSGP_ConnHdlr vc_conn; |
| 420 | |
| 421 | var BSSGP_ConnHdlrPars pars := { |
| 422 | imei := f_gen_imei(imsi_suffix), |
| 423 | imsi := f_gen_imsi(imsi_suffix), |
| 424 | msisdn := f_gen_msisdn(imsi_suffix), |
| 425 | p_tmsi := omit, |
| 426 | p_tmsi_sig := omit, |
| 427 | tlli := f_gprs_tlli_random(), |
| 428 | tlli_old := omit, |
| 429 | ra := omit, |
| 430 | bssgp_cell_id := { pcu[0].cfg.bvc[0].cell_id, pcu[1].cfg.bvc[0].cell_id, pcu[2].cfg.bvc[0].cell_id }, |
| 431 | t_guard := t_guard |
| 432 | }; |
| 433 | |
| 434 | vc_conn := BSSGP_ConnHdlr.create(id); |
| 435 | // PDU side |
| 436 | connect(vc_conn:PCU[0], pcu[0].vc_BSSGP_BVC[0]:BSSGP_SP); |
| 437 | connect(vc_conn:PCU_SIG[0], pcu[0].vc_BSSGP_BVC[0]:BSSGP_SP_SIG); |
| 438 | connect(vc_conn:PCU_PROC[0], pcu[0].vc_BSSGP_BVC[0]:BSSGP_PROC); |
| 439 | connect(vc_conn:PCU[1], pcu[1].vc_BSSGP_BVC[0]:BSSGP_SP); |
| 440 | connect(vc_conn:PCU_SIG[1], pcu[1].vc_BSSGP_BVC[0]:BSSGP_SP_SIG); |
| 441 | connect(vc_conn:PCU_PROC[1], pcu[1].vc_BSSGP_BVC[0]:BSSGP_PROC); |
| 442 | connect(vc_conn:PCU[2], pcu[2].vc_BSSGP_BVC[0]:BSSGP_SP); |
| 443 | connect(vc_conn:PCU_SIG[2], pcu[2].vc_BSSGP_BVC[0]:BSSGP_SP_SIG); |
| 444 | connect(vc_conn:PCU_PROC[2], pcu[2].vc_BSSGP_BVC[0]:BSSGP_PROC); |
| 445 | // SGSN side |
| 446 | connect(vc_conn:SGSN[0], sgsn[0].vc_BSSGP_BVC[0]:BSSGP_SP); |
| 447 | connect(vc_conn:SGSN_SIG[0], sgsn[0].vc_BSSGP_BVC[0]:BSSGP_SP_SIG); |
| 448 | connect(vc_conn:SGSN_PROC[0], sgsn[0].vc_BSSGP_BVC[0]:BSSGP_PROC); |
| 449 | |
| 450 | vc_conn.start(f_handler_init(fn, id, pars)); |
| 451 | return vc_conn; |
| 452 | } |
| 453 | |
| 454 | private altstep as_Tguard() runs on BSSGP_ConnHdlr { |
| 455 | [] g_Tguard.timeout { |
| 456 | setverdict(fail, "Tguard timeout"); |
| 457 | mtc.stop; |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | /* first function called in every ConnHdlr */ |
| 462 | private function f_handler_init(void_fn fn, charstring id, BSSGP_ConnHdlrPars pars) |
| 463 | runs on BSSGP_ConnHdlr { |
Harald Welte | 1e834f3 | 2020-11-15 20:02:59 +0100 | [diff] [blame] | 464 | var integer i; |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 465 | /* do some common stuff like setting up g_pars */ |
| 466 | g_pars := pars; |
| 467 | |
| 468 | llc := f_llc_create(false); |
| 469 | |
Harald Welte | 1e834f3 | 2020-11-15 20:02:59 +0100 | [diff] [blame] | 470 | /* register for our IMSI + TLLI */ |
| 471 | for (i := 0; i < sizeof(SGSN_PROC); i := i+1) { |
| 472 | f_client_register(g_pars.imsi, g_pars.tlli, SGSN_PROC[i]); |
| 473 | } |
| 474 | for (i := 0; i < sizeof(PCU_PROC); i := i+1) { |
| 475 | f_client_register(g_pars.imsi, g_pars.tlli, PCU_PROC[i]); |
| 476 | } |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 477 | |
| 478 | g_Tguard.start(pars.t_guard); |
| 479 | activate(as_Tguard()); |
| 480 | |
| 481 | /* call the user-supplied test case function */ |
| 482 | fn.apply(id); |
| 483 | } |
| 484 | |
Harald Welte | 1e834f3 | 2020-11-15 20:02:59 +0100 | [diff] [blame] | 485 | private function f_client_register(hexstring imsi, OCT4 tlli, BSSGP_PROC_PT PT) |
| 486 | runs on BSSGP_ConnHdlr { |
| 487 | PT.call(BSSGP_register_client:{imsi, tlli}) { |
| 488 | [] PT.getreply(BSSGP_register_client:{imsi, tlli}) {}; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | private function f_client_unregister(hexstring imsi, BSSGP_PROC_PT PT) |
| 493 | runs on BSSGP_ConnHdlr { |
| 494 | PT.call(BSSGP_unregister_client:{imsi}) { |
| 495 | [] PT.getreply(BSSGP_unregister_client:{imsi}) {}; |
| 496 | } |
| 497 | } |
| 498 | |
Harald Welte | 22ef5d9 | 2020-11-16 13:35:14 +0100 | [diff] [blame] | 499 | /* Send 'tx' on PTP-BVCI from PCU; expect 'rx' on SGSN */ |
| 500 | friend function f_pcu2sgsn(template (value) PDU_BSSGP tx, template (present) PDU_BSSGP exp_rx, |
| 501 | integer pcu_idx := 0, integer sgsn_idx := 0) runs on BSSGP_ConnHdlr { |
| 502 | var PDU_BSSGP rx; |
| 503 | timer T := 1.0; |
| 504 | |
| 505 | PCU[pcu_idx].send(tx); |
| 506 | T.start; |
| 507 | alt { |
| 508 | [] SGSN[sgsn_idx].receive(exp_rx) { |
| 509 | setverdict(pass); |
| 510 | } |
| 511 | [] SGSN[sgsn_idx].receive(PDU_BSSGP:?) -> value rx { |
| 512 | setverdict(fail, "Unexpected BSSGP on SGSN side: ", rx); |
| 513 | mtc.stop; |
| 514 | } |
| 515 | [] T.timeout { |
| 516 | setverdict(fail, "Timeout waiting for BSSGP on SGSN side: ", rx); |
| 517 | mtc.stop; |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | /* Send 'tx' on PTP-BVCI from SGSN; expect 'rx' on PCU */ |
| 523 | friend function f_sgsn2pcu(template (value) PDU_BSSGP tx, template (present) PDU_BSSGP exp_rx, |
| 524 | integer sgsn_idx:= 0, integer pcu_idx := 0) runs on BSSGP_ConnHdlr { |
| 525 | var PDU_BSSGP rx; |
| 526 | timer T := 1.0; |
| 527 | |
| 528 | SGSN[sgsn_idx].send(tx); |
| 529 | T.start; |
| 530 | alt { |
| 531 | [] PCU[pcu_idx].receive(exp_rx) { |
| 532 | setverdict(pass); |
| 533 | } |
| 534 | [] PCU[pcu_idx].receive(PDU_BSSGP:?) -> value rx { |
| 535 | setverdict(fail, "Unexpected BSSGP on PCU side: ", rx); |
| 536 | mtc.stop; |
| 537 | } |
| 538 | [] T.timeout { |
| 539 | setverdict(fail, "Timeout waiting for BSSGP on PCU side: ", rx); |
| 540 | mtc.stop; |
| 541 | } |
| 542 | } |
| 543 | } |
Harald Welte | 1e834f3 | 2020-11-15 20:02:59 +0100 | [diff] [blame] | 544 | |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 545 | /* TODO: |
| 546 | * Detach without Attach |
| 547 | * SM procedures without attach / RAU |
| 548 | * ATTACH / RAU |
| 549 | ** with / without authentication |
| 550 | ** with / without P-TMSI allocation |
| 551 | * re-transmissions of LLC frames |
| 552 | * PDP Context activation |
| 553 | ** with different GGSN config in SGSN VTY |
| 554 | ** with different PDP context type (v4/v6/v46) |
| 555 | ** timeout from GGSN |
| 556 | ** multiple / secondary PDP context |
| 557 | */ |
| 558 | |
| 559 | private function f_TC_BVC_bringup(charstring id) runs on BSSGP_ConnHdlr { |
| 560 | f_sleep(5.0); |
| 561 | setverdict(pass); |
| 562 | } |
| 563 | |
| 564 | testcase TC_BVC_bringup() runs on test_CT { |
| 565 | var BSSGP_ConnHdlr vc_conn; |
| 566 | f_init(); |
| 567 | |
| 568 | vc_conn := f_start_handler(refers(f_TC_BVC_bringup), testcasename(), g_pcu, g_sgsn, 51); |
| 569 | vc_conn.done; |
| 570 | |
| 571 | f_cleanup(); |
| 572 | } |
| 573 | |
| 574 | friend function f_bssgp_suspend(integer ran_idx := 0) runs on BSSGP_ConnHdlr return OCT1 { |
| 575 | timer T := 5.0; |
| 576 | var PDU_BSSGP rx_pdu; |
| 577 | PCU_SIG[ran_idx].send(ts_BSSGP_SUSPEND(g_pars.tlli, g_pars.bssgp_cell_id[ran_idx].ra_id)); |
| 578 | T.start; |
| 579 | alt { |
| 580 | [] PCU_SIG[ran_idx].receive(tr_BSSGP_SUSPEND_ACK(g_pars.tlli, g_pars.bssgp_cell_id[ran_idx].ra_id, ?)) -> value rx_pdu { |
| 581 | return rx_pdu.pDU_BSSGP_SUSPEND_ACK.suspend_Reference_Number.suspend_Reference_Number_value; |
| 582 | } |
| 583 | [] PCU_SIG[ran_idx].receive(tr_BSSGP_SUSPEND_NACK(g_pars.tlli, g_pars.bssgp_cell_id[ran_idx].ra_id, ?)) -> value rx_pdu { |
| 584 | setverdict(fail, "SUSPEND-NACK in response to SUSPEND for TLLI ", g_pars.tlli); |
| 585 | mtc.stop; |
| 586 | } |
| 587 | [] T.timeout { |
| 588 | setverdict(fail, "No SUSPEND-ACK in response to SUSPEND for TLLI ", g_pars.tlli); |
| 589 | mtc.stop; |
| 590 | } |
| 591 | } |
| 592 | return '00'O; |
| 593 | } |
| 594 | |
| 595 | friend function f_bssgp_resume(OCT1 susp_ref, integer ran_idx := 0) runs on BSSGP_ConnHdlr { |
| 596 | timer T := 5.0; |
| 597 | PCU_SIG[ran_idx].send(ts_BSSGP_RESUME(g_pars.tlli, g_pars.bssgp_cell_id[ran_idx].ra_id, susp_ref)); |
| 598 | T.start; |
| 599 | alt { |
| 600 | [] PCU_SIG[ran_idx].receive(tr_BSSGP_RESUME_ACK(g_pars.tlli, g_pars.bssgp_cell_id[ran_idx].ra_id)); |
| 601 | [] PCU_SIG[ran_idx].receive(tr_BSSGP_RESUME_NACK(g_pars.tlli, g_pars.bssgp_cell_id[ran_idx].ra_id, |
| 602 | ?)) { |
| 603 | setverdict(fail, "RESUME-NACK in response to RESUME for TLLI ", g_pars.tlli); |
| 604 | mtc.stop; |
| 605 | } |
| 606 | [] T.timeout { |
| 607 | setverdict(fail, "No RESUME-ACK in response to SUSPEND for TLLI ", g_pars.tlli); |
| 608 | mtc.stop; |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | |
Harald Welte | 9268601 | 2020-11-15 21:45:49 +0100 | [diff] [blame] | 614 | /* send uplink-unitdata of a variety of different sizes; expect it to show up on SGSN */ |
| 615 | private function f_TC_ul_unitdata(charstring id) runs on BSSGP_ConnHdlr { |
| 616 | var integer i; |
| 617 | |
| 618 | for (i := 0; i < 1024; i := i+1) { |
| 619 | var octetstring payload := f_rnd_octstring(i); |
| 620 | var template (value) PDU_BSSGP pdu_tx := ts_BSSGP_UL_UD(g_pars.tlli, g_pars.bssgp_cell_id[0], payload); |
| 621 | /* we cannot use pdu_tx as there are some subtle differences in the length field :/ */ |
| 622 | var template (present) PDU_BSSGP pdu_rx := tr_BSSGP_UL_UD(g_pars.tlli, g_pars.bssgp_cell_id[0], payload); |
| 623 | |
Harald Welte | 22ef5d9 | 2020-11-16 13:35:14 +0100 | [diff] [blame] | 624 | f_pcu2sgsn(pdu_tx, pdu_rx); |
Harald Welte | 9268601 | 2020-11-15 21:45:49 +0100 | [diff] [blame] | 625 | } |
| 626 | setverdict(pass); |
| 627 | } |
| 628 | |
| 629 | testcase TC_ul_unitdata() runs on test_CT |
| 630 | { |
| 631 | var BSSGP_ConnHdlr vc_conn; |
| 632 | f_init(); |
| 633 | |
| 634 | vc_conn := f_start_handler(refers(f_TC_ul_unitdata), testcasename(), g_pcu, g_sgsn, 1); |
| 635 | vc_conn.done; |
| 636 | /* TODO: start multiple handlers (UEs) on various cells on same and other NSEs */ |
| 637 | |
| 638 | f_cleanup(); |
| 639 | } |
| 640 | |
Harald Welte | 78d8db9 | 2020-11-15 23:27:27 +0100 | [diff] [blame] | 641 | /* send downlink-unitdata of a variety of different sizes; expect it to show up on PCU */ |
| 642 | private function f_TC_dl_unitdata(charstring id) runs on BSSGP_ConnHdlr { |
| 643 | var integer i; |
| 644 | |
| 645 | for (i := 0; i < 1024; i := i+1) { |
| 646 | var octetstring payload := f_rnd_octstring(i); |
| 647 | var template (value) PDU_BSSGP pdu_tx := |
| 648 | ts_BSSGP_DL_UD(g_pars.tlli, payload, omit, ts_BSSGP_IMSI(g_pars.imsi)); |
| 649 | /* we cannot use pdu_tx as there are some subtle differences in the length field :/ */ |
| 650 | var template (present) PDU_BSSGP pdu_rx := |
| 651 | tr_BSSGP_DL_UD(g_pars.tlli, payload, tr_BSSGP_IMSI(g_pars.imsi)); |
| 652 | |
Harald Welte | 22ef5d9 | 2020-11-16 13:35:14 +0100 | [diff] [blame] | 653 | f_sgsn2pcu(pdu_tx, pdu_rx); |
Harald Welte | 78d8db9 | 2020-11-15 23:27:27 +0100 | [diff] [blame] | 654 | } |
| 655 | setverdict(pass); |
| 656 | } |
| 657 | |
| 658 | testcase TC_dl_unitdata() runs on test_CT |
| 659 | { |
| 660 | var BSSGP_ConnHdlr vc_conn; |
| 661 | f_init(); |
| 662 | |
| 663 | vc_conn := f_start_handler(refers(f_TC_dl_unitdata), testcasename(), g_pcu, g_sgsn, 2); |
| 664 | vc_conn.done; |
| 665 | /* TODO: start multiple handlers (UEs) on various cells on same and other NSEs */ |
| 666 | |
| 667 | f_cleanup(); |
| 668 | } |
Harald Welte | 9268601 | 2020-11-15 21:45:49 +0100 | [diff] [blame] | 669 | |
Harald Welte | 6dc2ac4 | 2020-11-16 09:16:17 +0100 | [diff] [blame] | 670 | private function f_TC_ra_capability(charstring id) runs on BSSGP_ConnHdlr { |
| 671 | var integer i; |
| 672 | |
| 673 | for (i := 0; i < 10; i := i+1) { |
| 674 | var template (value) PDU_BSSGP pdu_tx := ts_BSSGP_RA_CAP(g_pars.tlli, { ts_RaCapRec_BSSGP }); |
| 675 | /* we cannot use pdu_tx as there are some subtle differences in the length field :/ */ |
| 676 | var template (present) PDU_BSSGP pdu_rx := tr_BSSGP_RA_CAP(g_pars.tlli, { tr_RaCapRec_BSSGP }) |
| 677 | |
Harald Welte | 22ef5d9 | 2020-11-16 13:35:14 +0100 | [diff] [blame] | 678 | f_sgsn2pcu(pdu_tx, pdu_rx); |
Harald Welte | 6dc2ac4 | 2020-11-16 09:16:17 +0100 | [diff] [blame] | 679 | } |
| 680 | setverdict(pass); |
| 681 | } |
| 682 | testcase TC_ra_capability() runs on test_CT |
| 683 | { |
| 684 | var BSSGP_ConnHdlr vc_conn; |
| 685 | f_init(); |
| 686 | |
| 687 | vc_conn := f_start_handler(refers(f_TC_ra_capability), testcasename(), g_pcu, g_sgsn, 3); |
| 688 | vc_conn.done; |
| 689 | /* TODO: start multiple handlers (UEs) on various cells on same and other NSEs */ |
| 690 | |
| 691 | f_cleanup(); |
| 692 | } |
| 693 | |
Daniel Willmann | ace3ece | 2020-11-16 19:53:26 +0100 | [diff] [blame] | 694 | private function f_TC_ra_capability_upd(charstring id) runs on BSSGP_ConnHdlr { |
| 695 | var integer i; |
| 696 | var OCT1 tag; |
| 697 | for (i := 0; i < 10; i := i+1) { |
| 698 | tag := int2oct(23 + i, 1); |
| 699 | var template (value) PDU_BSSGP pdu_tx := ts_BSSGP_RA_CAP_UPD(g_pars.tlli, tag); |
| 700 | /* we cannot use pdu_tx as there are some subtle differences in the length field :/ */ |
| 701 | var template (present) PDU_BSSGP pdu_rx := tr_BSSGP_RA_CAP_UPD(g_pars.tlli, tag) |
| 702 | |
| 703 | f_pcu2sgsn(pdu_tx, pdu_rx); |
| 704 | |
| 705 | pdu_tx := ts_BSSGP_RA_CAP_UPD_ACK(g_pars.tlli, tag, '42'O); |
| 706 | /* we cannot use pdu_tx as there are some subtle differences in the length field :/ */ |
| 707 | pdu_rx := tr_BSSGP_RA_CAP_UPD_ACK(g_pars.tlli, tag, '42'O) |
| 708 | |
| 709 | f_sgsn2pcu(pdu_tx, pdu_rx); |
| 710 | } |
| 711 | setverdict(pass); |
| 712 | } |
| 713 | testcase TC_ra_capability_upd() runs on test_CT |
| 714 | { |
| 715 | var BSSGP_ConnHdlr vc_conn; |
| 716 | f_init(); |
| 717 | |
| 718 | vc_conn := f_start_handler(refers(f_TC_ra_capability_upd), testcasename(), g_pcu, g_sgsn, 3); |
| 719 | vc_conn.done; |
| 720 | /* TODO: start multiple handlers (UEs) on various cells on same and other NSEs */ |
| 721 | |
| 722 | f_cleanup(); |
| 723 | } |
| 724 | |
Harald Welte | 6dc2ac4 | 2020-11-16 09:16:17 +0100 | [diff] [blame] | 725 | |
| 726 | |
| 727 | |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 728 | control { |
| 729 | execute( TC_BVC_bringup() ); |
Harald Welte | 9268601 | 2020-11-15 21:45:49 +0100 | [diff] [blame] | 730 | execute( TC_ul_unitdata() ); |
Harald Welte | 78d8db9 | 2020-11-15 23:27:27 +0100 | [diff] [blame] | 731 | execute( TC_dl_unitdata() ); |
Harald Welte | 6dc2ac4 | 2020-11-16 09:16:17 +0100 | [diff] [blame] | 732 | execute( TC_ra_capability() ); |
Daniel Willmann | ace3ece | 2020-11-16 19:53:26 +0100 | [diff] [blame] | 733 | execute( TC_ra_capability_upd() ); |
Daniel Willmann | 423d8f4 | 2020-09-08 18:58:22 +0200 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | |
| 737 | } |