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 | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 9 | import from LLC_Templates all; |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 10 | |
| 11 | modulepar { |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame^] | 12 | /* number of BVCs to bring up in one Gb instance */ |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 13 | integer mp_num_bvc := 10; |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame^] | 14 | /* number of UEs to start in each PTP BVC */ |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 15 | integer mp_num_ue_in_bvc := 10; |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame^] | 16 | /* NS configurations; one per NSE; each with any number of NSVC */ |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 17 | NSConfigurations mp_nsconfig := { |
| 18 | { |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 19 | nsei := 123, |
| 20 | role_sgsn := false, |
Harald Welte | 90f1974 | 2020-11-06 19:34:40 +0100 | [diff] [blame] | 21 | handle_sns := false, |
| 22 | nsvc := { |
| 23 | { |
| 24 | provider := { |
| 25 | fr := { |
| 26 | netdev := "hdlc1", |
| 27 | dlci := 123 |
| 28 | } |
| 29 | }, |
| 30 | nsvci := 123 |
| 31 | } |
| 32 | } |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 33 | } |
| 34 | }; |
| 35 | } |
| 36 | |
| 37 | type record GbInstance { |
| 38 | NS_CT vc_NS, |
| 39 | BSSGP_CT vc_BSSGP, |
| 40 | BssgpConfig cfg |
| 41 | }; |
| 42 | |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 43 | type record of GbInstance GbInstances; |
| 44 | type record of NSConfiguration NSConfigurations; |
| 45 | type record of BssgpCellId BssgpCellIds; |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 46 | |
| 47 | |
| 48 | type component test_CT { |
| 49 | var GbInstances g_gb; |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 50 | port BSSGP_CT_PROC_PT BSSGP_PROC[16]; |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 51 | }; |
| 52 | |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame^] | 53 | /* initialize one Gb interface */ |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 54 | private function f_init_gb(inout GbInstance gb, charstring id, integer offset) runs on test_CT { |
| 55 | var charstring id_idx := id & int2str(offset); |
| 56 | gb.vc_NS := NS_CT.create(id_idx & "-NSemu"); |
| 57 | gb.vc_BSSGP := BSSGP_CT.create(id_idx & "-BSSGPemu"); |
| 58 | connect(gb.vc_BSSGP:BSCP, gb.vc_NS:NS_SP); |
| 59 | gb.vc_NS.start(NSStart(mp_nsconfig[offset], id_idx)); |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 60 | connect(self:BSSGP_PROC[offset], gb.vc_BSSGP:PROC); |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 61 | gb.vc_BSSGP.start(BssgpStart(gb.cfg, testcasename())); |
| 62 | } |
| 63 | |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame^] | 64 | /* generate a BVC dynamically, using distinct number ranges for BVCI, CID, LAC, ... */ |
| 65 | private function f_gen_bvc(integer base, integer idx) return BssgpBvcConfig { |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 66 | var BssgpBvcConfig bvc := { |
| 67 | bvci := base + 100 + idx, |
| 68 | cell_id := { |
| 69 | ra_id := { |
| 70 | lai := { |
| 71 | mcc_mnc := '262F42'H, |
| 72 | lac := base + 300 + idx |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 73 | }, |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 74 | rac := 1 |
| 75 | }, |
| 76 | cell_id := base + 600 + idx |
| 77 | }, |
Harald Welte | 4d112c9 | 2020-11-12 19:48:31 +0100 | [diff] [blame] | 78 | depth := BSSGP_DECODE_DEPTH_LLC, |
| 79 | create_cb := refers(BSSGP_Emulation.DefaultCreateCallback) |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 80 | }; |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 81 | return bvc; |
| 82 | } |
| 83 | |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 84 | /*********************************************************************** |
| 85 | * UE simulation component |
| 86 | ***********************************************************************/ |
| 87 | |
| 88 | type component UE_CT extends BSSGP_Client_CT { |
| 89 | var UE_Pars g_pars; |
| 90 | timer g_Tguard; |
| 91 | var LLC_Entities llc; |
| 92 | } |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 93 | type record of UE_CT ro_ue; |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 94 | |
| 95 | type record UE_Pars { |
| 96 | hexstring imsi, |
Harald Welte | 681949b | 2021-01-28 18:49:42 +0100 | [diff] [blame] | 97 | OCT4 tlli, |
| 98 | float tguard |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | type function void_fn(charstring id) runs on UE_CT; |
| 102 | |
Harald Welte | 681949b | 2021-01-28 18:49:42 +0100 | [diff] [blame] | 103 | private altstep as_ue_tguard() runs on UE_CT { |
| 104 | [] g_Tguard.timeout { |
| 105 | setverdict(fail, "Tguard timeout after ", g_pars.tguard); |
| 106 | self.stop; |
| 107 | } |
| 108 | } |
| 109 | |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame^] | 110 | /* 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] | 111 | function f_handler_init(void_fn fn, charstring id, UE_Pars pars) runs on UE_CT { |
| 112 | g_pars := pars; |
| 113 | llc := f_llc_create(false); |
| 114 | f_bssgp_client_register(g_pars.imsi, g_pars.tlli); |
Harald Welte | 681949b | 2021-01-28 18:49:42 +0100 | [diff] [blame] | 115 | g_Tguard.start(g_pars.tguard); |
| 116 | activate(as_ue_tguard()); |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 117 | |
Harald Welte | 02cdc7c | 2021-02-03 17:46:38 +0100 | [diff] [blame] | 118 | log(id, " Waiting for BVC-UNBLOCK"); |
| 119 | timer T := 15.0; |
| 120 | T.start; |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 121 | alt { |
| 122 | [] BSSGP[0].receive(BssgpStatusIndication:{*,?,BVC_S_UNBLOCKED}) { } |
| 123 | [] BSSGP[0].receive { repeat; } |
Harald Welte | 02cdc7c | 2021-02-03 17:46:38 +0100 | [diff] [blame] | 124 | [] T.timeout { |
| 125 | setverdict(fail, id, " Timeout waiting for BVC-UNBLOCK"); |
| 126 | self.stop; |
| 127 | } |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 128 | } |
| 129 | |
Harald Welte | 02cdc7c | 2021-02-03 17:46:38 +0100 | [diff] [blame] | 130 | log (id, " Entering main loop"); |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame^] | 131 | fn.apply(id); |
Harald Welte | 02cdc7c | 2021-02-03 17:46:38 +0100 | [diff] [blame] | 132 | log (id, "Leaving main loop"); |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame^] | 133 | f_bssgp_client_unregister(g_pars.imsi); |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 134 | } |
| 135 | |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame^] | 136 | /* start a single UE component; connect it to BSSGP */ |
Harald Welte | 5e78788 | 2021-02-03 17:44:13 +0100 | [diff] [blame] | 137 | function f_start_ue(void_fn fn, charstring id, GbInstance gb, 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] | 138 | runs on test_CT return UE_CT |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 139 | { |
| 140 | var UE_CT ue_comp; |
| 141 | var UE_Pars ue_pars := { |
| 142 | imsi := f_gen_imsi(imsi_suffix), |
Harald Welte | 681949b | 2021-01-28 18:49:42 +0100 | [diff] [blame] | 143 | tlli := f_gprs_tlli_random(), |
| 144 | tguard := t_guard |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | ue_comp := UE_CT.create(id); |
| 148 | connect(ue_comp:BSSGP[0], bvc_comp:BSSGP_SP); |
| 149 | connect(ue_comp:BSSGP_SIG[0], bvc_comp:BSSGP_SP_SIG); |
| 150 | connect(ue_comp:BSSGP_PROC[0], bvc_comp:BSSGP_PROC); |
| 151 | ue_comp.start(f_handler_init(fn, id, ue_pars)); |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 152 | |
| 153 | return ue_comp; |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 154 | } |
| 155 | |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 156 | |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame^] | 157 | /* main test case body function; start Gb instances, start UE_CTs on top; wait for termination */ |
| 158 | private function f_tc_body(void_fn ue_fn, integer ue_per_bvc := mp_num_ue_in_bvc, |
| 159 | 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] | 160 | var ro_ue ues := {}; |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 161 | |
| 162 | for (var integer i := 0; i < lengthof(mp_nsconfig); i := i+1) { |
| 163 | g_gb[i].cfg := { |
| 164 | nsei := mp_nsconfig[i].nsei, |
| 165 | sgsn_role := false, |
| 166 | bvc := { } |
| 167 | }; |
| 168 | /* create 'mp_num_bvc' number of BVCs */ |
| 169 | for (var integer j := 0; j < mp_num_bvc; j := j+1) { |
| 170 | g_gb[i].cfg.bvc := g_gb[i].cfg.bvc & { f_gen_bvc(i * 1000, j) }; |
| 171 | } |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 172 | log("Initializing Gb interface ", i, ": NSEI=", g_gb[i].cfg.nsei); |
Harald Welte | de6f3ee | 2020-11-11 19:01:46 +0100 | [diff] [blame] | 173 | f_init_gb(g_gb[i], "gb", i); |
| 174 | } |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 175 | |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 176 | for (var integer i := 0; i < lengthof(mp_nsconfig); i := i+1) { |
| 177 | for (var integer j := 0; j < mp_num_bvc; j := j+1) { |
| 178 | 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^] | 179 | for (var integer k := 0; k < ue_per_bvc; k := k+1) { |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 180 | 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] | 181 | var UE_CT ue; |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame^] | 182 | ue := f_start_ue(ue_fn, id, g_gb[i], i*10000+j*100+k, bvc_comp, |
| 183 | ue_tguard); |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 184 | ues := ues & { ue }; |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 185 | /* 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^] | 186 | f_sleep(delay_between_ue); |
Harald Welte | 5e78788 | 2021-02-03 17:44:13 +0100 | [diff] [blame] | 187 | /* FIXME: as the BSSGP emulation is already running, we must not |
| 188 | * take too long to start the UE components. If we do, the |
| 189 | * BVC_S_UNBLOCKED notification will arrive before the components |
| 190 | * all are running, meaning we never get that one :( */ |
Harald Welte | d6de984 | 2020-11-12 21:50:10 +0100 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | } |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 194 | |
| 195 | /* wait for all UE components to terminate */ |
| 196 | for (var integer i := 0; i < lengthof(ues); i := i + 1) { |
| 197 | ues[i].done; |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 198 | } |
Harald Welte | 056858a | 2021-01-28 18:44:53 +0100 | [diff] [blame] | 199 | setverdict(pass); |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 200 | } |
| 201 | |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame^] | 202 | private function f_ul_ud(charstring id) runs on UE_CT |
| 203 | { |
| 204 | for (var integer num_pkts := 0; num_pkts < 50; num_pkts := num_pkts + 1) { |
| 205 | var integer ran_index := 0; |
| 206 | //BSSGP[ran_index].send(ts_BSSGP_UL_UD(g_pars.tlli, g_pars.bssgp_cell_id[ran_index], llc_enc)); |
| 207 | BSSGP[ran_index].send(ts_LLC_UI(f_rnd_octstring(512), '0000'B, '1'B, 0)) |
| 208 | f_sleep(0.5); |
| 209 | /* 512 bytes + 32 bytes HDR every 0.5s (1088/s) means about 8704/s per UE */ |
| 210 | /* at 100 UE that ends up about 870 kBps */ |
| 211 | } |
| 212 | } |
| 213 | /* Generate uplink-unitdata traffic */ |
| 214 | testcase TC_ul_ud() runs on test_CT |
| 215 | { |
| 216 | f_tc_body(refers(f_ul_ud)); |
| 217 | } |
| 218 | |
| 219 | |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 220 | control { |
Harald Welte | f1f23bf | 2021-02-03 18:08:29 +0100 | [diff] [blame^] | 221 | execute( TC_ul_ud() ); |
Harald Welte | 023b61b | 2020-09-12 20:41:05 +0200 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | } |