Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 1 | module FR_Tests { |
| 2 | |
| 3 | import from General_Types all; |
| 4 | import from Osmocom_Types all; |
| 5 | import from Osmocom_Gb_Types all; |
| 6 | |
| 7 | import from NS_Emulation all; |
| 8 | import from BSSGP_Emulation all; |
Harald Welte | 2711967 | 2021-02-04 14:39:54 +0100 | [diff] [blame^] | 9 | import from LLC_Types all; |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 10 | import from LLC_Templates all; |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 11 | |
| 12 | modulepar { |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 13 | /* number of BVCs to bring up in one Gb instance */ |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 14 | integer mp_num_bvc := 10; |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 15 | /* number of UEs to start in each PTP BVC */ |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 16 | integer mp_num_ue_in_bvc := 10; |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 17 | /* NS configurations; one per NSE; each with any number of NSVC */ |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 18 | NSConfigurations mp_nsconfig := { |
| 19 | { |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 20 | nsei := 123, |
| 21 | role_sgsn := false, |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 22 | handle_sns := false, |
| 23 | nsvc := { |
| 24 | { |
| 25 | provider := { |
| 26 | fr := { |
| 27 | netdev := "hdlc1", |
Harald Welte | bfff717 | 2021-02-04 10:46:55 +0100 | [diff] [blame] | 28 | dlci := 1 |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 29 | } |
| 30 | }, |
Harald Welte | bfff717 | 2021-02-04 10:46:55 +0100 | [diff] [blame] | 31 | nsvci := 101 |
| 32 | }, { |
| 33 | provider := { |
| 34 | fr := { |
| 35 | netdev := "hdlc2", |
| 36 | dlci := 2 |
| 37 | } |
| 38 | }, |
| 39 | nsvci := 102 |
| 40 | }, { |
| 41 | provider := { |
| 42 | fr := { |
| 43 | netdev := "hdlc3", |
| 44 | dlci := 3 |
| 45 | } |
| 46 | }, |
| 47 | nsvci := 103 |
| 48 | }, { |
| 49 | provider := { |
| 50 | fr := { |
| 51 | netdev := "hdlc4", |
| 52 | dlci := 4 |
| 53 | } |
| 54 | }, |
| 55 | nsvci := 104 |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 56 | } |
| 57 | } |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 58 | } |
| 59 | }; |
| 60 | } |
| 61 | |
| 62 | type record GbInstance { |
| 63 | NS_CT vc_NS, |
| 64 | BSSGP_CT vc_BSSGP, |
| 65 | BssgpConfig cfg |
| 66 | }; |
| 67 | |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 68 | type record of GbInstance GbInstances; |
| 69 | type record of NSConfiguration NSConfigurations; |
| 70 | type record of BssgpCellId BssgpCellIds; |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 71 | |
| 72 | |
| 73 | type component test_CT { |
| 74 | var GbInstances g_gb; |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 75 | port BSSGP_CT_PROC_PT BSSGP_PROC[16]; |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 76 | }; |
| 77 | |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 78 | /* initialize one Gb interface */ |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 79 | private function f_init_gb(inout GbInstance gb, charstring id, integer offset) runs on test_CT { |
| 80 | var charstring id_idx := id & int2str(offset); |
| 81 | gb.vc_NS := NS_CT.create(id_idx & "-NSemu"); |
| 82 | gb.vc_BSSGP := BSSGP_CT.create(id_idx & "-BSSGPemu"); |
| 83 | connect(gb.vc_BSSGP:BSCP, gb.vc_NS:NS_SP); |
| 84 | gb.vc_NS.start(NSStart(mp_nsconfig[offset], id_idx)); |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 85 | connect(self:BSSGP_PROC[offset], gb.vc_BSSGP:PROC); |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 86 | gb.vc_BSSGP.start(BssgpStart(gb.cfg, testcasename())); |
| 87 | } |
| 88 | |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 89 | /* generate a BVC dynamically, using distinct number ranges for BVCI, CID, LAC, ... */ |
| 90 | private function f_gen_bvc(integer base, integer idx) return BssgpBvcConfig { |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 91 | var BssgpBvcConfig bvc := { |
| 92 | bvci := base + 100 + idx, |
| 93 | cell_id := { |
| 94 | ra_id := { |
| 95 | lai := { |
| 96 | mcc_mnc := '262F42'H, |
| 97 | lac := base + 300 + idx |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 98 | }, |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 99 | rac := 1 |
| 100 | }, |
| 101 | cell_id := base + 600 + idx |
| 102 | }, |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 103 | depth := BSSGP_DECODE_DEPTH_LLC, |
| 104 | create_cb := refers(BSSGP_Emulation.DefaultCreateCallback) |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 105 | }; |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 106 | return bvc; |
| 107 | } |
| 108 | |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 109 | /*********************************************************************** |
| 110 | * UE simulation component |
| 111 | ***********************************************************************/ |
| 112 | |
| 113 | type component UE_CT extends BSSGP_Client_CT { |
| 114 | var UE_Pars g_pars; |
| 115 | timer g_Tguard; |
| 116 | var LLC_Entities llc; |
| 117 | } |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 118 | type record of UE_CT ro_ue; |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 119 | |
| 120 | type record UE_Pars { |
| 121 | hexstring imsi, |
Harald Welte | 681949b | 2021-01-28 18:49:42 +0100 | [diff] [blame] | 122 | OCT4 tlli, |
Harald Welte | 8525764 | 2021-02-04 13:19:58 +0100 | [diff] [blame] | 123 | float tguard, |
| 124 | BssgpBvci bvci, |
| 125 | BssgpCellId cell_id |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | type function void_fn(charstring id) runs on UE_CT; |
| 129 | |
Harald Welte | 681949b | 2021-01-28 18:49:42 +0100 | [diff] [blame] | 130 | private altstep as_ue_tguard() runs on UE_CT { |
| 131 | [] g_Tguard.timeout { |
| 132 | setverdict(fail, "Tguard timeout after ", g_pars.tguard); |
| 133 | self.stop; |
| 134 | } |
| 135 | } |
| 136 | |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 137 | /* first function executed in UE_CT; creates LLC context, registers with BSSGP, starts Tguard */ |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 138 | function f_handler_init(void_fn fn, charstring id, UE_Pars pars) runs on UE_CT { |
| 139 | g_pars := pars; |
| 140 | llc := f_llc_create(false); |
| 141 | f_bssgp_client_register(g_pars.imsi, g_pars.tlli); |
Harald Welte | 681949b | 2021-01-28 18:49:42 +0100 | [diff] [blame] | 142 | g_Tguard.start(g_pars.tguard); |
| 143 | activate(as_ue_tguard()); |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 144 | |
Harald Welte | 02cdc7c | 2021-02-03 17:46:38 +0100 | [diff] [blame] | 145 | log(id, " Waiting for BVC-UNBLOCK"); |
| 146 | timer T := 15.0; |
| 147 | T.start; |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 148 | alt { |
| 149 | [] BSSGP[0].receive(BssgpStatusIndication:{*,?,BVC_S_UNBLOCKED}) { } |
| 150 | [] BSSGP[0].receive { repeat; } |
Harald Welte | 02cdc7c | 2021-02-03 17:46:38 +0100 | [diff] [blame] | 151 | [] T.timeout { |
| 152 | setverdict(fail, id, " Timeout waiting for BVC-UNBLOCK"); |
| 153 | self.stop; |
| 154 | } |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 155 | } |
| 156 | |
Harald Welte | 02cdc7c | 2021-02-03 17:46:38 +0100 | [diff] [blame] | 157 | log (id, " Entering main loop"); |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 158 | fn.apply(id); |
Harald Welte | 02cdc7c | 2021-02-03 17:46:38 +0100 | [diff] [blame] | 159 | log (id, "Leaving main loop"); |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 160 | f_bssgp_client_unregister(g_pars.imsi); |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 161 | } |
| 162 | |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 163 | /* start a single UE component; connect it to BSSGP */ |
Harald Welte | 8525764 | 2021-02-04 13:19:58 +0100 | [diff] [blame] | 164 | function f_start_ue(void_fn fn, charstring id, BssgpBvcConfig bvc, integer imsi_suffix, BSSGP_BVC_CT bvc_comp, float t_guard := 40.0) |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 165 | runs on test_CT return UE_CT |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 166 | { |
| 167 | var UE_CT ue_comp; |
| 168 | var UE_Pars ue_pars := { |
| 169 | imsi := f_gen_imsi(imsi_suffix), |
Harald Welte | 681949b | 2021-01-28 18:49:42 +0100 | [diff] [blame] | 170 | tlli := f_gprs_tlli_random(), |
Harald Welte | 8525764 | 2021-02-04 13:19:58 +0100 | [diff] [blame] | 171 | tguard := t_guard, |
| 172 | bvci := bvc.bvci, |
| 173 | cell_id := bvc.cell_id |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | ue_comp := UE_CT.create(id); |
| 177 | connect(ue_comp:BSSGP[0], bvc_comp:BSSGP_SP); |
| 178 | connect(ue_comp:BSSGP_SIG[0], bvc_comp:BSSGP_SP_SIG); |
| 179 | connect(ue_comp:BSSGP_PROC[0], bvc_comp:BSSGP_PROC); |
| 180 | ue_comp.start(f_handler_init(fn, id, ue_pars)); |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 181 | |
| 182 | return ue_comp; |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 183 | } |
| 184 | |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 185 | |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 186 | /* main test case body function; start Gb instances, start UE_CTs on top; wait for termination */ |
| 187 | private function f_tc_body(void_fn ue_fn, integer ue_per_bvc := mp_num_ue_in_bvc, |
| 188 | float delay_between_ue := 0.005, float ue_tguard := 40.0) runs on test_CT { |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 189 | var ro_ue ues := {}; |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 190 | |
| 191 | for (var integer i := 0; i < lengthof(mp_nsconfig); i := i+1) { |
| 192 | g_gb[i].cfg := { |
| 193 | nsei := mp_nsconfig[i].nsei, |
| 194 | sgsn_role := false, |
| 195 | bvc := { } |
| 196 | }; |
| 197 | /* create 'mp_num_bvc' number of BVCs */ |
| 198 | for (var integer j := 0; j < mp_num_bvc; j := j+1) { |
| 199 | g_gb[i].cfg.bvc := g_gb[i].cfg.bvc & { f_gen_bvc(i * 1000, j) }; |
| 200 | } |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 201 | log("Initializing Gb interface ", i, ": NSEI=", g_gb[i].cfg.nsei); |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 202 | f_init_gb(g_gb[i], "gb", i); |
| 203 | } |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 204 | |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 205 | for (var integer i := 0; i < lengthof(mp_nsconfig); i := i+1) { |
| 206 | for (var integer j := 0; j < mp_num_bvc; j := j+1) { |
| 207 | var BSSGP_BVC_CT bvc_comp := f_bssgp_get_bvci_ct(g_gb[i].cfg.bvc[j].bvci, BSSGP_PROC[i]); |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 208 | for (var integer k := 0; k < ue_per_bvc; k := k+1) { |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 209 | var charstring id := "gb" & int2str(i) & "-bvc" & int2str(g_gb[i].cfg.bvc[j].bvci) & "-UEsim" & int2str(k); |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 210 | var UE_CT ue; |
Harald Welte | 8525764 | 2021-02-04 13:19:58 +0100 | [diff] [blame] | 211 | ue := f_start_ue(ue_fn, id, g_gb[i].cfg.bvc[j], i*10000+j*100+k, bvc_comp, |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 212 | ue_tguard); |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 213 | ues := ues & { ue }; |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 214 | /* a bit of staggering to ensure the timers above don't run all at the same time */ |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 215 | f_sleep(delay_between_ue); |
Harald Welte | 5e78788 | 2021-02-03 17:44:13 +0100 | [diff] [blame] | 216 | /* FIXME: as the BSSGP emulation is already running, we must not |
| 217 | * take too long to start the UE components. If we do, the |
| 218 | * BVC_S_UNBLOCKED notification will arrive before the components |
| 219 | * all are running, meaning we never get that one :( */ |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | } |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 223 | |
| 224 | /* wait for all UE components to terminate */ |
| 225 | for (var integer i := 0; i < lengthof(ues); i := i + 1) { |
| 226 | ues[i].done; |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 227 | } |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 228 | setverdict(pass); |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 229 | } |
| 230 | |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 231 | private function f_ul_ud(charstring id) runs on UE_CT |
| 232 | { |
| 233 | for (var integer num_pkts := 0; num_pkts < 50; num_pkts := num_pkts + 1) { |
| 234 | var integer ran_index := 0; |
| 235 | //BSSGP[ran_index].send(ts_BSSGP_UL_UD(g_pars.tlli, g_pars.bssgp_cell_id[ran_index], llc_enc)); |
| 236 | BSSGP[ran_index].send(ts_LLC_UI(f_rnd_octstring(512), '0000'B, '1'B, 0)) |
| 237 | f_sleep(0.5); |
| 238 | /* 512 bytes + 32 bytes HDR every 0.5s (1088/s) means about 8704/s per UE */ |
| 239 | /* at 100 UE that ends up about 870 kBps */ |
| 240 | } |
| 241 | } |
| 242 | /* Generate uplink-unitdata traffic */ |
| 243 | testcase TC_ul_ud() runs on test_CT |
| 244 | { |
| 245 | f_tc_body(refers(f_ul_ud)); |
| 246 | } |
| 247 | |
| 248 | |
Harald Welte | 106ba34 | 2021-02-03 18:15:19 +0100 | [diff] [blame] | 249 | /* test bring-up of all BVCs */ |
| 250 | private function f_pass(charstring id) runs on UE_CT |
| 251 | { |
| 252 | setverdict(pass); |
| 253 | } |
| 254 | testcase TC_bvc_bringup() runs on test_CT |
| 255 | { |
| 256 | f_tc_body(refers(f_pass), ue_per_bvc := 1, ue_tguard := 20.0); |
| 257 | } |
| 258 | |
| 259 | |
Harald Welte | 2711967 | 2021-02-04 14:39:54 +0100 | [diff] [blame^] | 260 | private function f_ul2dl_ud(charstring id) runs on UE_CT |
| 261 | { |
| 262 | for (var integer num_pkts := 0; num_pkts < 50; num_pkts := num_pkts + 1) { |
| 263 | var integer ran_index := 0; |
| 264 | var template (value) PDU_LLC llc_tx; |
| 265 | var template (present) PDU_LLC llc_rx_exp; |
| 266 | var PDU_LLC llc_rx; |
| 267 | timer T := 5.0; |
| 268 | |
| 269 | /* SAPI '0010'B is looped back by FRNET_Tests.ttcn */ |
| 270 | llc_tx := ts_LLC_UI(f_rnd_octstring(512), '0010'B, '1'B, 0); |
| 271 | llc_rx_exp := llc_tx; |
| 272 | llc_rx_exp.pDU_LLC_UI.fCS := ?; |
| 273 | |
| 274 | //BSSGP[ran_index].send(ts_BSSGP_UL_UD(g_pars.tlli, g_pars.cell_id, llc_enc)); |
| 275 | BSSGP[ran_index].send(llc_tx); |
| 276 | T.start; |
| 277 | alt { |
| 278 | [] BSSGP[ran_index].receive(llc_rx_exp) -> value llc_rx { } |
| 279 | [] BSSGP[ran_index].receive(PDU_LLC:?) -> value llc_rx { |
| 280 | setverdict(fail, "Unexpected LLC: ", llc_rx); |
| 281 | break; |
| 282 | } |
| 283 | [] T.timeout { |
| 284 | setverdict(fail, "Timeout waiting for ", llc_rx_exp); |
| 285 | break; |
| 286 | } |
| 287 | } |
| 288 | //f_sleep(0.1); |
| 289 | /* 512 bytes + 32 bytes HDR every 0.5s (1088/s) means about 8704/s per UE */ |
| 290 | /* at 100 UE that ends up about 870 kBps */ |
| 291 | } |
| 292 | } |
| 293 | /* Generate uplink-unitdata traffic */ |
| 294 | testcase TC_ul2dl_ud() runs on test_CT |
| 295 | { |
| 296 | f_tc_body(refers(f_ul2dl_ud), ue_tguard := 100.0); |
| 297 | } |
| 298 | |
| 299 | |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 300 | control { |
Harald Welte | 106ba34 | 2021-02-03 18:15:19 +0100 | [diff] [blame] | 301 | execute( TC_bvc_bringup() ); |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame] | 302 | execute( TC_ul_ud() ); |
Harald Welte | 2711967 | 2021-02-04 14:39:54 +0100 | [diff] [blame^] | 303 | execute( TC_ul2dl_ud() ); |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 304 | } |
| 305 | |
| 306 | } |