From 8d85ba4baad12e558b16d2e879847b3297f56ccc Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Mon, 10 Jun 2019 16:36:30 +0200 Subject: [PATCH] bscnat: Refactor BSC_MS side code to allow different actions per test Each test can now plug in different actions to be done by the emulated BSC_MS, by passing a function to f_init(). Old hardcoded behaviour (main()) is renamed and used in already existing tests. Change-Id: Ic82ca333267535c5859e6439deacbf3b1d1fe391 --- bsc-nat/BSCNAT_Tests.ttcn | 12 ++++--- bsc-nat/BSC_MS_ConnectionHandler.ttcn | 21 ++++++++---- bsc-nat/BSC_MS_Simulation.ttcn | 49 +++++++++++++++++---------- 3 files changed, 54 insertions(+), 28 deletions(-) diff --git a/bsc-nat/BSCNAT_Tests.ttcn b/bsc-nat/BSCNAT_Tests.ttcn index 6b0c757ad..fda065af5 100644 --- a/bsc-nat/BSCNAT_Tests.ttcn +++ b/bsc-nat/BSCNAT_Tests.ttcn @@ -25,6 +25,7 @@ import from SCCP_Emulation all; import from MSC_Simulation all; import from BSC_MS_Simulation all; +import from BSC_MS_ConnectionHandler all; import from Osmocom_VTY_Functions all; import from TELNETasp_PortType all; @@ -135,7 +136,7 @@ function f_init_vty(charstring id := "foo") runs on test_CT { f_vty_transceive(BSCNATVTY, "enable"); } -function f_init(boolean use_osmux) runs on test_CT { +function f_init(void_fn_bsc_ms fn_bsc_ms, boolean use_osmux) runs on test_CT { var integer i; var charstring id; @@ -156,9 +157,12 @@ function f_init(boolean use_osmux) runs on test_CT { f_init_BscState(bsc[i], mp_bsc_pc +i, mp_msc_pc, mp_bsc_ssn, mp_msc_ssn); id := "BSC" & int2str(i); bsc[i].BSC := BSC_CT.create(id); + var BSC_MS_TestHdlrParams pars; + pars.sccp_addr_own := bsc[i].sccp_addr_own; + pars.sccp_addr_remote := bsc[i].sccp_addr_peer; + pars.use_osmux := use_osmux; bsc[i].BSC.start(BSC_MS_Simulation.main(mp_nat_ip, mp_nat_port, mp_bsc_ip, mp_bsc_port+i, - bsc[i].sccp_pars, bsc[i].sccp_addr_own, - bsc[i].sccp_addr_peer, use_osmux, id)); + bsc[i].sccp_pars, pars, fn_bsc_ms, id)); } } @@ -182,7 +186,7 @@ function f_wait_finish(timer T) runs on test_CT { function f_TC_recv_dump(boolean use_osmux := false) runs on test_CT { timer T := 30.0; - f_init(use_osmux); + f_init(refers(bsc_ms_establish_fully), use_osmux); f_wait_finish(T); } diff --git a/bsc-nat/BSC_MS_ConnectionHandler.ttcn b/bsc-nat/BSC_MS_ConnectionHandler.ttcn index 7f2ebcd21..f7126fdc9 100644 --- a/bsc-nat/BSC_MS_ConnectionHandler.ttcn +++ b/bsc-nat/BSC_MS_ConnectionHandler.ttcn @@ -25,6 +25,8 @@ import from MGCP_Types all; import from MGCP_Templates all; import from SDP_Types all; +type function void_fn_bsc_ms(charstring id) runs on BSC_MS_ConnHdlr; + /* this component represents a single subscriber connection at the MSC. * There is a 1:1 mapping between SCCP connections and RAN_ConnHdlr components. * We inherit all component variables, ports, functions, ... from RAN_ConnHdlr */ @@ -34,8 +36,15 @@ type component BSC_MS_ConnHdlr extends RAN_ConnHdlr { var MgcpConnectionId g_mgcp_conn_id; var SDP_Message g_sdp; var BSC_State g_state; + var BSC_MS_TestHdlrParams g_pars; } +type record BSC_MS_TestHdlrParams { + SCCP_PAR_Address sccp_addr_own, + SCCP_PAR_Address sccp_addr_remote, + boolean use_osmux +}; + /* Callback function from general RAN_Emulation whenever a new incoming * SCCP connection arrivces. Must create + start a new component */ private function CreateCallback(BSSAP_N_CONNECT_ind conn_ind, charstring id) @@ -90,7 +99,7 @@ type enumerated BSC_State { } /* main function processing various incoming events */ -function main(SCCP_PAR_Address sccp_addr_own, SCCP_PAR_Address sccp_addr_remote, boolean use_osmux) +function bsc_ms_establish_fully(charstring id) runs on BSC_MS_ConnHdlr { var PDU_BSSAP bssap; var MgcpCommand mgcp_cmd; @@ -104,8 +113,8 @@ runs on BSC_MS_ConnHdlr { /* generate and send the Complete Layer3 Info */ bssap := f_gen_cl3('901770123456789'H); var BSSAP_Conn_Req creq := { - addr_peer := sccp_addr_remote, - addr_own := sccp_addr_own, + addr_peer := g_pars.sccp_addr_remote, + addr_own := g_pars.sccp_addr_own, bssap := bssap } g_state := BSC_STATE_WAIT_ASS_REQ; @@ -130,12 +139,12 @@ runs on BSC_MS_ConnHdlr { /* respond with CRCX_ACK */ g_state := BSC_STATE_WAIT_MDCX; - if (use_osmux != f_MgcpCmd_contains_par(mgcp_cmd, "X-OSMUX")) { - setverdict(fail, log2str("Received Osmux CID presence doesn't match presence expectancy (", use_osmux, ")")); + if (g_pars.use_osmux != f_MgcpCmd_contains_par(mgcp_cmd, "X-OSMUX")) { + setverdict(fail, log2str("Received Osmux CID presence doesn't match presence expectancy (", g_pars.use_osmux, ")")); self.stop; } - if (use_osmux) { + if (g_pars.use_osmux) { osmux_cid := f_MgcpCmd_extract_osmux_cid(mgcp_cmd); mgcp_resp := ts_CRCX_ACK_osmux(mgcp_cmd.line.trans_id, g_mgcp_conn_id, osmux_cid, g_sdp); } else { diff --git a/bsc-nat/BSC_MS_Simulation.ttcn b/bsc-nat/BSC_MS_Simulation.ttcn index d4e37a468..5feaf0e2e 100644 --- a/bsc-nat/BSC_MS_Simulation.ttcn +++ b/bsc-nat/BSC_MS_Simulation.ttcn @@ -31,9 +31,7 @@ type component BSC_CT { /* test port to SCCP emulation */ port SCCPasp_PT SCCP; - var SCCP_PAR_Address g_sccp_addr_own; - var SCCP_PAR_Address g_sccp_addr_remote; - var boolean g_use_osmux; + var BSC_MS_TestHdlrParams g_pars; var charstring g_bsc_num_str; } @@ -42,21 +40,41 @@ modulepar { integer mp_num_iterations := 10; } +/* helper function to create and connect a BSC_MS_ConnHdlr component */ +private function f_connect_handler(inout BSC_MS_ConnHdlr vc_conn) runs on BSC_CT { + /* connect client BSSAP port to BSSAP dispatcher */ + connect(vc_conn:BSSAP, vc_BSSMAP:CLIENT); +} + +private function f_start_handler(void_fn_bsc_ms fn, charstring id, template (omit) BSC_MS_TestHdlrParams pars := omit) +runs on BSC_CT return BSC_MS_ConnHdlr { + var BSC_MS_ConnHdlr vc_conn; + vc_conn := BSC_MS_ConnHdlr.create(id); + f_connect_handler(vc_conn); + vc_conn.start(f_handler_init(fn, id, pars)); + return vc_conn; +} + +/* first function inside ConnHdlr component; sets g_pars + starts function */ +private function f_handler_init(void_fn_bsc_ms fn, charstring id, template (omit) BSC_MS_TestHdlrParams pars := omit) +runs on BSC_MS_ConnHdlr { + if (isvalue(pars)) { + g_pars := valueof(pars); + } + fn.apply(id); +} + function main(charstring remote_ip, PortNumber remote_port, charstring local_ip, PortNumber local_port, MSC_SCCP_MTP3_parameters sccp_pars, - SCCP_PAR_Address sccp_addr_own, - SCCP_PAR_Address sccp_addr_remote, - boolean use_osmux, charstring id) runs on BSC_CT + BSC_MS_TestHdlrParams pars, + void_fn_bsc_ms fn, charstring id) runs on BSC_CT { var integer i := 0; timer T := 1.0; var IPA_CCM_Parameters ccm_pars := IPA_Emulation.c_IPA_default_ccm_pars; ccm_pars.name := id; - - g_sccp_addr_own := sccp_addr_own; - g_sccp_addr_remote := sccp_addr_remote; - g_use_osmux := use_osmux; + g_pars := pars; /* create components for IPA/SCCP/BSS[M]AP stack */ vc_IPA := IPA_Emulation_CT.create(id & "-IPA"); @@ -84,7 +102,7 @@ function main(charstring remote_ip, PortNumber remote_port, T.timeout; for (i := 0; i < mp_num_iterations; i := i+1) { - f_start_BSC_MS(id & "-MS-" & int2str(i)); + f_start_BSC_MS(fn, id & "-MS-" & int2str(i)); } /* explicitly stop all components that we started above */ @@ -93,15 +111,10 @@ function main(charstring remote_ip, PortNumber remote_port, vc_SCCP.stop; } -function f_start_BSC_MS(charstring id) runs on BSC_CT { +function f_start_BSC_MS(void_fn_bsc_ms fn, charstring id) runs on BSC_CT { var BSC_MS_ConnHdlr vc_conn; - - /* start new component */ - vc_conn := BSC_MS_ConnHdlr.create(id); - /* connect client BSSAP port to BSSAP dispatcher */ - connect(vc_conn:BSSAP, vc_BSSMAP:CLIENT); /* start component */ - vc_conn.start(BSC_MS_ConnectionHandler.main(g_sccp_addr_own, g_sccp_addr_remote, g_use_osmux)); + vc_conn := f_start_handler(fn, id, g_pars); /* blocking wait until component terminates. If you want to start MSs in parallel, * you have to remove this statement here */ vc_conn.done;