blob: f18216e9f2a031d2f72de05995145f45f58adb71 [file] [log] [blame]
Daniel Willmann423d8f42020-09-08 18:58:22 +02001module 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
15import from General_Types all;
16import from Osmocom_Types all;
17import from GSM_Types all;
18import from Native_Functions all;
19import from NS_Types all;
20import from NS_Emulation all;
21import from BSSGP_Types all;
22import from BSSGP_Emulation all;
23import from SCCPasp_Types all;
24import from Osmocom_Gb_Types all;
25
26import from MobileL3_CommonIE_Types all;
27import from MobileL3_GMM_SM_Types all;
28import from MobileL3_Types all;
29import from L3_Templates all;
30import from L3_Common all;
31
32import from TELNETasp_PortType all;
33import from Osmocom_VTY_Functions all;
34
35import from LLC_Types all;
36import from LLC_Templates all;
37
38import from GSM_RR_Types all;
39
Harald Welte6d63f742020-11-15 19:44:04 +010040/* mcc_mnc is 24.008 10.5.5.15 encoded. 262 42 */
41const BcdMccMnc c_mcc_mnc := '262F42'H;
42
Daniel Willmann423d8f42020-09-08 18:58:22 +020043modulepar {
44 /* IP/port on which we run our internal GSUP/HLR emulation */
Harald Welte6d63f742020-11-15 19:44:04 +010045 NSConfigurations mp_nsconfig_sgsn := {
Daniel Willmann423d8f42020-09-08 18:58:22 +020046 {
Daniel Willmann423d8f42020-09-08 18:58:22 +020047 nsei := 101,
48 role_sgsn := true,
Harald Welte90f19742020-11-06 19:34:40 +010049 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 Willmann423d8f42020-09-08 18:58:22 +020064 }
65 };
Harald Welte6d63f742020-11-15 19:44:04 +010066 NSConfigurations mp_nsconfig_pcu := {
Daniel Willmann423d8f42020-09-08 18:58:22 +020067 {
Daniel Willmann423d8f42020-09-08 18:58:22 +020068 nsei := 96,
69 role_sgsn := false,
Harald Welte90f19742020-11-06 19:34:40 +010070 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 Willmann423d8f42020-09-08 18:58:22 +020085 },
86 {
Daniel Willmann423d8f42020-09-08 18:58:22 +020087 nsei := 97,
88 role_sgsn := false,
Harald Welte90f19742020-11-06 19:34:40 +010089 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 Willmann423d8f42020-09-08 18:58:22 +0200104 },
105 {
Daniel Willmann423d8f42020-09-08 18:58:22 +0200106 nsei := 98,
107 role_sgsn := false,
Harald Welte90f19742020-11-06 19:34:40 +0100108 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 Willmann423d8f42020-09-08 18:58:22 +0200123 }
124 };
Harald Welte6d63f742020-11-15 19:44:04 +0100125 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 Willmann423d8f42020-09-08 18:58:22 +0200188};
189
190const integer NUM_BVC_PER_NSE := 3;
191type 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
198const integer NUM_PCU := 3;
Harald Welte6d63f742020-11-15 19:44:04 +0100199type record of GbInstance GbInstances;
200type record of BssgpConfig BssgpConfigs;
201type record of NSConfiguration NSConfigurations;
202type record of BssgpCellId BssgpCellIds;
Daniel Willmann423d8f42020-09-08 18:58:22 +0200203
204const integer NUM_SGSN := 1;
Daniel Willmann423d8f42020-09-08 18:58:22 +0200205
206type component test_CT {
Harald Welte6d63f742020-11-15 19:44:04 +0100207 var GbInstances g_pcu;
208 var GbInstances g_sgsn;
Daniel Willmann423d8f42020-09-08 18:58:22 +0200209
210 port BSSGP_CT_PROC_PT PROC;
211
212 port TELNETasp_PT GBPVTY;
213
214 var boolean g_initialized := false;
215 var boolean g_use_echo := false;
216};
217
218type component BSSGP_ConnHdlr {
219 port BSSGP_PT PCU[NUM_PCU];
220 port BSSGP_PT PCU_SIG[NUM_PCU];
221 port BSSGP_PROC_PT PCU_PROC[NUM_PCU];
222 port BSSGP_PT SGSN[NUM_SGSN];
223 port BSSGP_PT SGSN_SIG[NUM_SGSN];
224 port BSSGP_PROC_PT SGSN_PROC[NUM_SGSN];
225
226 var BSSGP_ConnHdlrPars g_pars;
227 timer g_Tguard;
228 var LLC_Entities llc;
229}
230
231type record SGSN_ConnHdlrNetworkPars {
232 boolean expect_ptmsi,
233 boolean expect_auth,
234 boolean expect_ciph
235};
236
237type record BSSGP_ConnHdlrPars {
238 /* IMEI of the simulated ME */
239 hexstring imei,
240 /* IMSI of the simulated MS */
241 hexstring imsi,
242 /* MSISDN of the simulated MS (probably unused) */
243 hexstring msisdn,
244 /* P-TMSI allocated to the simulated MS */
245 OCT4 p_tmsi optional,
246 OCT3 p_tmsi_sig optional,
247 /* TLLI of the simulated MS */
248 OCT4 tlli,
249 OCT4 tlli_old optional,
250 RoutingAreaIdentificationV ra optional,
251 BssgpCellIds bssgp_cell_id,
252 float t_guard
253};
254
255private function f_cellid_to_RAI(in BssgpCellId cell_id) return RoutingAreaIdentificationV {
256 /* mcc_mnc is encoded as of 24.008 10.5.5.15 */
257 var BcdMccMnc mcc_mnc := cell_id.ra_id.lai.mcc_mnc;
258
259 var RoutingAreaIdentificationV ret := {
260 mccDigit1 := mcc_mnc[0],
261 mccDigit2 := mcc_mnc[1],
262 mccDigit3 := mcc_mnc[2],
263 mncDigit3 := mcc_mnc[3],
264 mncDigit1 := mcc_mnc[4],
265 mncDigit2 := mcc_mnc[5],
266 lac := int2oct(cell_id.ra_id.lai.lac, 16),
267 rac := int2oct(cell_id.ra_id.rac, 8)
268 }
269 return ret;
270};
271
272private function f_init_gb_pcu(inout GbInstance gb, charstring id, integer offset) runs on test_CT {
273 gb.vc_NS := NS_CT.create(id & "-NS(PCU)" & int2str(offset));
274 gb.vc_BSSGP := BSSGP_CT.create(id & "-BSSGP(PCU)" & int2str(offset));
275 /* connect lower end of BSSGP emulation with NS upper port */
276 connect(gb.vc_BSSGP:BSCP, gb.vc_NS:NS_SP);
277
278 gb.vc_NS.start(NSStart(mp_nsconfig_pcu[offset]));
279 gb.vc_BSSGP.start(BssgpStart(gb.cfg, id));
280
281 for (var integer i := 0; i < lengthof(gb.cfg.bvc); i := i + 1) {
282 connect(self:PROC, gb.vc_BSSGP:PROC);
283 gb.vc_BSSGP_BVC[i] := f_bssgp_get_bvci_ct(gb.cfg.bvc[i].bvci, PROC);
284 disconnect(self:PROC, gb.vc_BSSGP:PROC);
285 }
286}
287
288private function f_init_gb_sgsn(inout GbInstance gb, charstring id, integer offset) runs on test_CT {
289 gb.vc_NS := NS_CT.create(id & "-NS(SGSN)" & int2str(offset));
290 gb.vc_BSSGP := BSSGP_CT.create(id & "-BSSGP(SGSN)" & int2str(offset));
291 /* connect lower end of BSSGP emulation with NS upper port */
292 connect(gb.vc_BSSGP:BSCP, gb.vc_NS:NS_SP);
293
294 gb.vc_NS.start(NSStart(mp_nsconfig_sgsn[offset]));
295 gb.vc_BSSGP.start(BssgpStart(gb.cfg, id));
296
297 for (var integer i := 0; i < lengthof(gb.cfg.bvc); i := i + 1) {
298 connect(self:PROC, gb.vc_BSSGP:PROC);
299 gb.vc_BSSGP_BVC[i] := f_bssgp_get_bvci_ct(gb.cfg.bvc[i].bvci, PROC);
300 disconnect(self:PROC, gb.vc_BSSGP:PROC);
301 }
302}
303
304
305private function f_init_vty() runs on test_CT {
306 map(self:GBPVTY, system:GBPVTY);
307 f_vty_set_prompts(GBPVTY);
308 f_vty_transceive(GBPVTY, "enable");
309}
310
Harald Welte6d63f742020-11-15 19:44:04 +0100311function f_init() runs on test_CT {
Daniel Willmann423d8f42020-09-08 18:58:22 +0200312 var integer i;
313
314 if (g_initialized == true) {
315 return;
316 }
317 g_initialized := true;
Daniel Willmann423d8f42020-09-08 18:58:22 +0200318
319 g_sgsn[0].cfg := {
Harald Welte6d63f742020-11-15 19:44:04 +0100320 nsei := mp_nsconfig_sgsn[0].nsei,
Daniel Willmann423d8f42020-09-08 18:58:22 +0200321 sgsn_role := true,
Harald Welte6d63f742020-11-15 19:44:04 +0100322 bvc := { }
323 }
324 for (i := 0; i < lengthof(mp_gbconfigs); i := i+1) {
325 g_pcu[i].cfg := mp_gbconfigs[i];
326 /* concatenate all the PCU-side BVCs for the SGSN side */
327 g_sgsn[0].cfg.bvc := g_sgsn[0].cfg.bvc & mp_gbconfigs[i].bvc;
328 }
Daniel Willmann423d8f42020-09-08 18:58:22 +0200329
330 f_init_vty();
Harald Welte6d63f742020-11-15 19:44:04 +0100331 for (i := 0; i < lengthof(mp_nsconfig_sgsn); i := i+1) {
332 f_init_gb_sgsn(g_sgsn[0], "GbProxy_Test-SGSN" & int2str(i), 0);
333 }
Daniel Willmann423d8f42020-09-08 18:58:22 +0200334 f_sleep(4.0);
Harald Welte6d63f742020-11-15 19:44:04 +0100335 for (i := 0; i < lengthof(mp_nsconfig_pcu); i := i+1) {
336 f_init_gb_pcu(g_pcu[i], "GbProxy_Test-PCU" & int2str(i), i);
337 }
Daniel Willmann423d8f42020-09-08 18:58:22 +0200338}
339
340function f_cleanup() runs on test_CT {
341 self.stop;
342}
343
344type function void_fn(charstring id) runs on BSSGP_ConnHdlr;
345
346/* helper function to create, connect and start a BSSGP_ConnHdlr component */
Harald Welte6d63f742020-11-15 19:44:04 +0100347function f_start_handler(void_fn fn, charstring id, GbInstances pcu, GbInstances sgsn, integer imsi_suffix,
Daniel Willmann423d8f42020-09-08 18:58:22 +0200348 float t_guard := 30.0)
349runs on test_CT return BSSGP_ConnHdlr {
350 var BSSGP_ConnHdlr vc_conn;
351
352 var BSSGP_ConnHdlrPars pars := {
353 imei := f_gen_imei(imsi_suffix),
354 imsi := f_gen_imsi(imsi_suffix),
355 msisdn := f_gen_msisdn(imsi_suffix),
356 p_tmsi := omit,
357 p_tmsi_sig := omit,
358 tlli := f_gprs_tlli_random(),
359 tlli_old := omit,
360 ra := omit,
361 bssgp_cell_id := { pcu[0].cfg.bvc[0].cell_id, pcu[1].cfg.bvc[0].cell_id, pcu[2].cfg.bvc[0].cell_id },
362 t_guard := t_guard
363 };
364
365 vc_conn := BSSGP_ConnHdlr.create(id);
366 // PDU side
367 connect(vc_conn:PCU[0], pcu[0].vc_BSSGP_BVC[0]:BSSGP_SP);
368 connect(vc_conn:PCU_SIG[0], pcu[0].vc_BSSGP_BVC[0]:BSSGP_SP_SIG);
369 connect(vc_conn:PCU_PROC[0], pcu[0].vc_BSSGP_BVC[0]:BSSGP_PROC);
370 connect(vc_conn:PCU[1], pcu[1].vc_BSSGP_BVC[0]:BSSGP_SP);
371 connect(vc_conn:PCU_SIG[1], pcu[1].vc_BSSGP_BVC[0]:BSSGP_SP_SIG);
372 connect(vc_conn:PCU_PROC[1], pcu[1].vc_BSSGP_BVC[0]:BSSGP_PROC);
373 connect(vc_conn:PCU[2], pcu[2].vc_BSSGP_BVC[0]:BSSGP_SP);
374 connect(vc_conn:PCU_SIG[2], pcu[2].vc_BSSGP_BVC[0]:BSSGP_SP_SIG);
375 connect(vc_conn:PCU_PROC[2], pcu[2].vc_BSSGP_BVC[0]:BSSGP_PROC);
376 // SGSN side
377 connect(vc_conn:SGSN[0], sgsn[0].vc_BSSGP_BVC[0]:BSSGP_SP);
378 connect(vc_conn:SGSN_SIG[0], sgsn[0].vc_BSSGP_BVC[0]:BSSGP_SP_SIG);
379 connect(vc_conn:SGSN_PROC[0], sgsn[0].vc_BSSGP_BVC[0]:BSSGP_PROC);
380
381 vc_conn.start(f_handler_init(fn, id, pars));
382 return vc_conn;
383}
384
385private altstep as_Tguard() runs on BSSGP_ConnHdlr {
386 [] g_Tguard.timeout {
387 setverdict(fail, "Tguard timeout");
388 mtc.stop;
389 }
390}
391
392/* first function called in every ConnHdlr */
393private function f_handler_init(void_fn fn, charstring id, BSSGP_ConnHdlrPars pars)
394runs on BSSGP_ConnHdlr {
395 /* do some common stuff like setting up g_pars */
396 g_pars := pars;
397
398 llc := f_llc_create(false);
399
400
401 g_Tguard.start(pars.t_guard);
402 activate(as_Tguard());
403
404 /* call the user-supplied test case function */
405 fn.apply(id);
406}
407
408/* TODO:
409 * Detach without Attach
410 * SM procedures without attach / RAU
411 * ATTACH / RAU
412 ** with / without authentication
413 ** with / without P-TMSI allocation
414 * re-transmissions of LLC frames
415 * PDP Context activation
416 ** with different GGSN config in SGSN VTY
417 ** with different PDP context type (v4/v6/v46)
418 ** timeout from GGSN
419 ** multiple / secondary PDP context
420 */
421
422private function f_TC_BVC_bringup(charstring id) runs on BSSGP_ConnHdlr {
423 f_sleep(5.0);
424 setverdict(pass);
425}
426
427testcase TC_BVC_bringup() runs on test_CT {
428 var BSSGP_ConnHdlr vc_conn;
429 f_init();
430
431 vc_conn := f_start_handler(refers(f_TC_BVC_bringup), testcasename(), g_pcu, g_sgsn, 51);
432 vc_conn.done;
433
434 f_cleanup();
435}
436
437friend function f_bssgp_suspend(integer ran_idx := 0) runs on BSSGP_ConnHdlr return OCT1 {
438 timer T := 5.0;
439 var PDU_BSSGP rx_pdu;
440 PCU_SIG[ran_idx].send(ts_BSSGP_SUSPEND(g_pars.tlli, g_pars.bssgp_cell_id[ran_idx].ra_id));
441 T.start;
442 alt {
443 [] PCU_SIG[ran_idx].receive(tr_BSSGP_SUSPEND_ACK(g_pars.tlli, g_pars.bssgp_cell_id[ran_idx].ra_id, ?)) -> value rx_pdu {
444 return rx_pdu.pDU_BSSGP_SUSPEND_ACK.suspend_Reference_Number.suspend_Reference_Number_value;
445 }
446 [] PCU_SIG[ran_idx].receive(tr_BSSGP_SUSPEND_NACK(g_pars.tlli, g_pars.bssgp_cell_id[ran_idx].ra_id, ?)) -> value rx_pdu {
447 setverdict(fail, "SUSPEND-NACK in response to SUSPEND for TLLI ", g_pars.tlli);
448 mtc.stop;
449 }
450 [] T.timeout {
451 setverdict(fail, "No SUSPEND-ACK in response to SUSPEND for TLLI ", g_pars.tlli);
452 mtc.stop;
453 }
454 }
455 return '00'O;
456}
457
458friend function f_bssgp_resume(OCT1 susp_ref, integer ran_idx := 0) runs on BSSGP_ConnHdlr {
459 timer T := 5.0;
460 PCU_SIG[ran_idx].send(ts_BSSGP_RESUME(g_pars.tlli, g_pars.bssgp_cell_id[ran_idx].ra_id, susp_ref));
461 T.start;
462 alt {
463 [] PCU_SIG[ran_idx].receive(tr_BSSGP_RESUME_ACK(g_pars.tlli, g_pars.bssgp_cell_id[ran_idx].ra_id));
464 [] PCU_SIG[ran_idx].receive(tr_BSSGP_RESUME_NACK(g_pars.tlli, g_pars.bssgp_cell_id[ran_idx].ra_id,
465?)) {
466 setverdict(fail, "RESUME-NACK in response to RESUME for TLLI ", g_pars.tlli);
467 mtc.stop;
468 }
469 [] T.timeout {
470 setverdict(fail, "No RESUME-ACK in response to SUSPEND for TLLI ", g_pars.tlli);
471 mtc.stop;
472 }
473 }
474}
475
476
477control {
478 execute( TC_BVC_bringup() );
479}
480
481
482}