blob: 5f58bc302ff36faea2a568bba6499e1b16d8273a [file] [log] [blame]
Harald Welte023b61b2020-09-12 20:41:05 +02001module FR_Tests {
2
3import from General_Types all;
4import from Osmocom_Types all;
5import from Osmocom_Gb_Types all;
6
7import from NS_Emulation all;
8import from BSSGP_Emulation all;
Harald Welted6de9842020-11-12 21:50:10 +01009import from LLC_Templates all;
Harald Welte023b61b2020-09-12 20:41:05 +020010
11modulepar {
Harald Weltef1f23bf2021-02-03 18:08:29 +010012 /* number of BVCs to bring up in one Gb instance */
Harald Weltede6f3ee2020-11-11 19:01:46 +010013 integer mp_num_bvc := 10;
Harald Weltef1f23bf2021-02-03 18:08:29 +010014 /* number of UEs to start in each PTP BVC */
Harald Welted6de9842020-11-12 21:50:10 +010015 integer mp_num_ue_in_bvc := 10;
Harald Weltef1f23bf2021-02-03 18:08:29 +010016 /* NS configurations; one per NSE; each with any number of NSVC */
Harald Welte023b61b2020-09-12 20:41:05 +020017 NSConfigurations mp_nsconfig := {
18 {
Harald Welte023b61b2020-09-12 20:41:05 +020019 nsei := 123,
20 role_sgsn := false,
Harald Welte90f19742020-11-06 19:34:40 +010021 handle_sns := false,
22 nsvc := {
23 {
24 provider := {
25 fr := {
26 netdev := "hdlc1",
27 dlci := 123
28 }
29 },
30 nsvci := 123
31 }
32 }
Harald Welte023b61b2020-09-12 20:41:05 +020033 }
34 };
35}
36
37type record GbInstance {
38 NS_CT vc_NS,
39 BSSGP_CT vc_BSSGP,
40 BssgpConfig cfg
41};
42
Harald Weltede6f3ee2020-11-11 19:01:46 +010043type record of GbInstance GbInstances;
44type record of NSConfiguration NSConfigurations;
45type record of BssgpCellId BssgpCellIds;
Harald Welte023b61b2020-09-12 20:41:05 +020046
47
48type component test_CT {
49 var GbInstances g_gb;
Harald Welted6de9842020-11-12 21:50:10 +010050 port BSSGP_CT_PROC_PT BSSGP_PROC[16];
Harald Welte023b61b2020-09-12 20:41:05 +020051};
52
Harald Weltef1f23bf2021-02-03 18:08:29 +010053/* initialize one Gb interface */
Harald Welte023b61b2020-09-12 20:41:05 +020054private 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 Welted6de9842020-11-12 21:50:10 +010060 connect(self:BSSGP_PROC[offset], gb.vc_BSSGP:PROC);
Harald Welte023b61b2020-09-12 20:41:05 +020061 gb.vc_BSSGP.start(BssgpStart(gb.cfg, testcasename()));
62}
63
Harald Weltef1f23bf2021-02-03 18:08:29 +010064/* generate a BVC dynamically, using distinct number ranges for BVCI, CID, LAC, ... */
65private function f_gen_bvc(integer base, integer idx) return BssgpBvcConfig {
Harald Weltede6f3ee2020-11-11 19:01:46 +010066 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 Welte023b61b2020-09-12 20:41:05 +020073 },
Harald Weltede6f3ee2020-11-11 19:01:46 +010074 rac := 1
75 },
76 cell_id := base + 600 + idx
77 },
Harald Welte4d112c92020-11-12 19:48:31 +010078 depth := BSSGP_DECODE_DEPTH_LLC,
79 create_cb := refers(BSSGP_Emulation.DefaultCreateCallback)
Harald Welte023b61b2020-09-12 20:41:05 +020080 };
Harald Weltede6f3ee2020-11-11 19:01:46 +010081 return bvc;
82}
83
Harald Welted6de9842020-11-12 21:50:10 +010084/***********************************************************************
85 * UE simulation component
86 ***********************************************************************/
87
88type component UE_CT extends BSSGP_Client_CT {
89 var UE_Pars g_pars;
90 timer g_Tguard;
91 var LLC_Entities llc;
92}
Harald Welte056858a2021-01-28 18:44:53 +010093type record of UE_CT ro_ue;
Harald Welted6de9842020-11-12 21:50:10 +010094
95type record UE_Pars {
96 hexstring imsi,
Harald Welte681949b2021-01-28 18:49:42 +010097 OCT4 tlli,
98 float tguard
Harald Welted6de9842020-11-12 21:50:10 +010099};
100
101type function void_fn(charstring id) runs on UE_CT;
102
Harald Welte681949b2021-01-28 18:49:42 +0100103private 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 Weltef1f23bf2021-02-03 18:08:29 +0100110/* first function executed in UE_CT; creates LLC context, registers with BSSGP, starts Tguard */
Harald Welted6de9842020-11-12 21:50:10 +0100111function 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 Welte681949b2021-01-28 18:49:42 +0100115 g_Tguard.start(g_pars.tguard);
116 activate(as_ue_tguard());
Harald Welted6de9842020-11-12 21:50:10 +0100117
Harald Welte02cdc7c2021-02-03 17:46:38 +0100118 log(id, " Waiting for BVC-UNBLOCK");
119 timer T := 15.0;
120 T.start;
Harald Welted6de9842020-11-12 21:50:10 +0100121 alt {
122 [] BSSGP[0].receive(BssgpStatusIndication:{*,?,BVC_S_UNBLOCKED}) { }
123 [] BSSGP[0].receive { repeat; }
Harald Welte02cdc7c2021-02-03 17:46:38 +0100124 [] T.timeout {
125 setverdict(fail, id, " Timeout waiting for BVC-UNBLOCK");
126 self.stop;
127 }
Harald Welted6de9842020-11-12 21:50:10 +0100128 }
129
Harald Welte02cdc7c2021-02-03 17:46:38 +0100130 log (id, " Entering main loop");
Harald Weltef1f23bf2021-02-03 18:08:29 +0100131 fn.apply(id);
Harald Welte02cdc7c2021-02-03 17:46:38 +0100132 log (id, "Leaving main loop");
Harald Weltef1f23bf2021-02-03 18:08:29 +0100133 f_bssgp_client_unregister(g_pars.imsi);
Harald Welted6de9842020-11-12 21:50:10 +0100134}
135
Harald Weltef1f23bf2021-02-03 18:08:29 +0100136/* start a single UE component; connect it to BSSGP */
Harald Welte5e787882021-02-03 17:44:13 +0100137function f_start_ue(void_fn fn, charstring id, GbInstance gb, integer imsi_suffix, BSSGP_BVC_CT bvc_comp, float t_guard := 40.0)
Harald Welte056858a2021-01-28 18:44:53 +0100138runs on test_CT return UE_CT
Harald Welted6de9842020-11-12 21:50:10 +0100139{
140 var UE_CT ue_comp;
141 var UE_Pars ue_pars := {
142 imsi := f_gen_imsi(imsi_suffix),
Harald Welte681949b2021-01-28 18:49:42 +0100143 tlli := f_gprs_tlli_random(),
144 tguard := t_guard
Harald Welted6de9842020-11-12 21:50:10 +0100145 };
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 Welte056858a2021-01-28 18:44:53 +0100152
153 return ue_comp;
Harald Welted6de9842020-11-12 21:50:10 +0100154}
155
Harald Weltede6f3ee2020-11-11 19:01:46 +0100156
Harald Weltef1f23bf2021-02-03 18:08:29 +0100157/* main test case body function; start Gb instances, start UE_CTs on top; wait for termination */
158private 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 Welte056858a2021-01-28 18:44:53 +0100160 var ro_ue ues := {};
Harald Weltede6f3ee2020-11-11 19:01:46 +0100161
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 Welted6de9842020-11-12 21:50:10 +0100172 log("Initializing Gb interface ", i, ": NSEI=", g_gb[i].cfg.nsei);
Harald Weltede6f3ee2020-11-11 19:01:46 +0100173 f_init_gb(g_gb[i], "gb", i);
174 }
Harald Welte056858a2021-01-28 18:44:53 +0100175
Harald Welted6de9842020-11-12 21:50:10 +0100176 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 Weltef1f23bf2021-02-03 18:08:29 +0100179 for (var integer k := 0; k < ue_per_bvc; k := k+1) {
Harald Welted6de9842020-11-12 21:50:10 +0100180 var charstring id := "gb" & int2str(i) & "-bvc" & int2str(g_gb[i].cfg.bvc[j].bvci) & "-UEsim" & int2str(k);
Harald Welte056858a2021-01-28 18:44:53 +0100181 var UE_CT ue;
Harald Weltef1f23bf2021-02-03 18:08:29 +0100182 ue := f_start_ue(ue_fn, id, g_gb[i], i*10000+j*100+k, bvc_comp,
183ue_tguard);
Harald Welte056858a2021-01-28 18:44:53 +0100184 ues := ues & { ue };
Harald Welted6de9842020-11-12 21:50:10 +0100185 /* a bit of staggering to ensure the timers above don't run all at the same time */
Harald Weltef1f23bf2021-02-03 18:08:29 +0100186 f_sleep(delay_between_ue);
Harald Welte5e787882021-02-03 17:44:13 +0100187 /* 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 Welted6de9842020-11-12 21:50:10 +0100191 }
192 }
193 }
Harald Welte056858a2021-01-28 18:44:53 +0100194
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 Welte023b61b2020-09-12 20:41:05 +0200198 }
Harald Welte056858a2021-01-28 18:44:53 +0100199 setverdict(pass);
Harald Welte023b61b2020-09-12 20:41:05 +0200200}
201
Harald Weltef1f23bf2021-02-03 18:08:29 +0100202private 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 */
214testcase TC_ul_ud() runs on test_CT
215{
216 f_tc_body(refers(f_ul_ud));
217}
218
219
Harald Welte106ba342021-02-03 18:15:19 +0100220/* test bring-up of all BVCs */
221private function f_pass(charstring id) runs on UE_CT
222{
223 setverdict(pass);
224}
225testcase TC_bvc_bringup() runs on test_CT
226{
227 f_tc_body(refers(f_pass), ue_per_bvc := 1, ue_tguard := 20.0);
228}
229
230
Harald Welte023b61b2020-09-12 20:41:05 +0200231control {
Harald Welte106ba342021-02-03 18:15:19 +0100232 execute( TC_bvc_bringup() );
Harald Weltef1f23bf2021-02-03 18:08:29 +0100233 execute( TC_ul_ud() );
Harald Welte023b61b2020-09-12 20:41:05 +0200234}
235
236}