blob: fda065af5aa842d63597f75c3b90a583aa929ef8 [file] [log] [blame]
Daniel Willmann0c6f34c2018-10-24 17:26:41 +02001module BSCNAT_Tests {
Harald Welte00566f52017-11-21 16:43:49 +01002
Harald Welte34b5a952019-05-27 11:54:11 +02003/* osmo-bsc_nat test suite in TTCN-3
4 * (C) 2018-2019 sysmocom - s.f.m.c. GmbH
5 * Author: Daniel Willmann
6 * All rights reserved.
7 *
8 * Released under the terms of GNU General Public License, Version 2 or
9 * (at your option) any later version.
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
Harald Welteb3414b22017-11-23 18:22:10 +010014import from Osmocom_Types all;
15
Harald Weltec76f29f2017-11-22 12:46:46 +010016import from IPL4asp_Types all;
Harald Welte00566f52017-11-21 16:43:49 +010017
Harald Weltec76f29f2017-11-22 12:46:46 +010018import from IPA_Emulation all;
Harald Welted86cdc62017-11-22 00:45:07 +010019
Harald Welteb3414b22017-11-23 18:22:10 +010020import from MTP3asp_Types all;
21
Harald Weltec76f29f2017-11-22 12:46:46 +010022import from SCCP_Types all;
23import from SCCPasp_Types all;
24import from SCCP_Emulation all;
Harald Welted86cdc62017-11-22 00:45:07 +010025
Harald Welteb3414b22017-11-23 18:22:10 +010026import from MSC_Simulation all;
27import from BSC_MS_Simulation all;
Pau Espin Pedrol8d85ba42019-06-10 16:36:30 +020028import from BSC_MS_ConnectionHandler all;
Harald Welted86cdc62017-11-22 00:45:07 +010029
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +020030import from Osmocom_VTY_Functions all;
31import from TELNETasp_PortType all;
32
Harald Welteb3414b22017-11-23 18:22:10 +010033const integer NUM_MSC := 1;
34const integer NUM_BSC := 1;
35
36type record BscState {
37 BSC_CT BSC,
38 MSC_SCCP_MTP3_parameters sccp_pars,
39 SCCP_PAR_Address sccp_addr_own,
40 SCCP_PAR_Address sccp_addr_peer
41}
42
43type record MscState {
44 MSC_CT MSC,
45 MSC_SCCP_MTP3_parameters sccp_pars,
46 SCCP_PAR_Address sccp_addr_own
47}
Harald Welte00566f52017-11-21 16:43:49 +010048
Harald Weltec76f29f2017-11-22 12:46:46 +010049type component test_CT {
Harald Welteb3414b22017-11-23 18:22:10 +010050 var MscState msc[NUM_MSC];
51 var BscState bsc[NUM_BSC];
Harald Welte00566f52017-11-21 16:43:49 +010052
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +020053 port TELNETasp_PT BSCNATVTY;
54
Harald Weltec76f29f2017-11-22 12:46:46 +010055 var boolean g_initialized := false;
Harald Welteb3414b22017-11-23 18:22:10 +010056 var octetstring g_sio := '83'O;
Harald Weltec76f29f2017-11-22 12:46:46 +010057}
Harald Welted86cdc62017-11-22 00:45:07 +010058
Harald Weltec76f29f2017-11-22 12:46:46 +010059modulepar {
Harald Welteb3414b22017-11-23 18:22:10 +010060 PortNumber mp_bsc_port := 49999;
61 charstring mp_bsc_ip := "127.0.0.1";
62
63 PortNumber mp_msc_port := 5000;
64 charstring mp_msc_ip := "127.0.0.1";
Harald Welted86cdc62017-11-22 00:45:07 +010065
Daniel Willmannfd338332017-11-24 17:23:23 +010066 PortNumber mp_nat_port := 5000;
67 charstring mp_nat_ip := "127.0.0.1";
68
Harald Weltec76f29f2017-11-22 12:46:46 +010069 charstring mp_sccp_service_type := "mtp3_itu";
70
Harald Welteb3414b22017-11-23 18:22:10 +010071 integer mp_bsc_pc := 196;
72 integer mp_bsc_ssn := 254;
Harald Weltec76f29f2017-11-22 12:46:46 +010073
Harald Welteb3414b22017-11-23 18:22:10 +010074 integer mp_msc_pc := 185; /* 0.23.1 */
75 integer mp_msc_ssn := 254;
Harald Weltec76f29f2017-11-22 12:46:46 +010076}
Harald Welte00566f52017-11-21 16:43:49 +010077
Harald Welted86cdc62017-11-22 00:45:07 +010078/* construct a SCCP_PAR_Address with just PC + SSN and no GT */
79template (value) SCCP_PAR_Address ts_SccpAddr_PC_SSN(integer pc, integer ssn) := {
80 addressIndicator := {
81 pointCodeIndic := '1'B,
82 ssnIndicator := '1'B,
83 globalTitleIndic := '0000'B,
84 routingIndicator := '1'B
85 },
86 signPointCode := SCCP_SPC_int2bit(pc, mp_sccp_service_type, '83'O),
87 //signPointCode := SCCP_SPC_int2bit(pc, mp_sccp_service_type, g_sio),
88 subsystemNumber := ssn,
89 globalTitle := omit
90}
91
Harald Welteb3414b22017-11-23 18:22:10 +010092template MTP3_Field_sio ts_sio(octetstring sio_in) := {
93 ni := substr(oct2bit(sio_in),0,2),
94 prio := substr(oct2bit(sio_in),2,2),
95 si := substr(oct2bit(sio_in),4,4)
Harald Weltec76f29f2017-11-22 12:46:46 +010096}
97
Harald Welteb3414b22017-11-23 18:22:10 +010098template MSC_SCCP_MTP3_parameters ts_SCCP_Pars(octetstring sio, integer opc, integer dpc,
99 integer local_ssn) := {
100 sio := ts_sio(sio),
101 opc := opc,
102 dpc := dpc,
103 sls := 0,
104 sccp_serviceType := mp_sccp_service_type,
105 ssn := local_ssn
106};
107
108function f_init_BscState(inout BscState bsc_st, integer opc, integer dpc, integer local_ssn, integer remote_ssn)
109runs on test_CT {
110 bsc_st.sccp_pars := valueof(ts_SCCP_Pars(g_sio, opc, dpc, local_ssn));
111 bsc_st.sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(opc, local_ssn));
112 bsc_st.sccp_addr_peer := valueof(ts_SccpAddr_PC_SSN(dpc, remote_ssn));
Harald Weltec76f29f2017-11-22 12:46:46 +0100113}
114
Harald Welteb3414b22017-11-23 18:22:10 +0100115function f_init_MscState(inout MscState msc_st, integer opc, integer dpc, integer local_ssn, integer remote_ssn)
116runs on test_CT {
117 msc_st.sccp_pars := valueof(ts_SCCP_Pars(g_sio, opc, dpc, local_ssn));
118 msc_st.sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(opc, local_ssn));
Harald Welted86cdc62017-11-22 00:45:07 +0100119}
120
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200121function f_vty_allow_osmux(boolean allow) runs on test_CT {
122 if (allow) {
123 f_vty_config(BSCNATVTY, "mgcp", "osmux on");
124 } else {
125 f_vty_config(BSCNATVTY, "mgcp", "osmux off");
126 }
127}
128
129function f_init_vty(charstring id := "foo") runs on test_CT {
130 if (BSCNATVTY.checkstate("Mapped")) {
131 /* skip initialization if already executed once */
132 return;
133 }
134 map(self:BSCNATVTY, system:BSCNATVTY);
135 f_vty_set_prompts(BSCNATVTY);
136 f_vty_transceive(BSCNATVTY, "enable");
137}
138
Pau Espin Pedrol8d85ba42019-06-10 16:36:30 +0200139function f_init(void_fn_bsc_ms fn_bsc_ms, boolean use_osmux) runs on test_CT {
Harald Welteb3414b22017-11-23 18:22:10 +0100140 var integer i;
Harald Weltebe620f62017-11-25 00:23:54 +0100141 var charstring id;
Harald Welte00566f52017-11-21 16:43:49 +0100142
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200143 f_init_vty("VirtBSCNAT");
144 f_vty_allow_osmux(use_osmux);
145
Harald Welteb3414b22017-11-23 18:22:10 +0100146 for (i := 0; i < NUM_MSC; i := i+1) {
147 f_init_MscState(msc[i], mp_msc_pc +i, mp_bsc_pc, mp_msc_ssn, mp_bsc_ssn);
Harald Weltebe620f62017-11-25 00:23:54 +0100148 id := "MSC" & int2str(i);
Daniel Willmannc07f6f52019-03-28 13:03:55 +0100149 msc[i].MSC := MSC_CT.create(id);
Harald Weltebe620f62017-11-25 00:23:54 +0100150 msc[i].MSC.start(MSC_Simulation.main(mp_msc_ip, mp_msc_port + i, msc[i].sccp_pars, msc[i].sccp_addr_own, id));
Harald Welte00566f52017-11-21 16:43:49 +0100151 }
152
Daniel Willmann991fd782018-10-25 17:20:27 +0200153 /* Wait for bsc_nat to attach to MSC. Before that all BSC connections will be dropped */
154 f_sleep(5.0);
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200155
Harald Welteb3414b22017-11-23 18:22:10 +0100156 for (i := 0; i < NUM_BSC; i := i+1) {
157 f_init_BscState(bsc[i], mp_bsc_pc +i, mp_msc_pc, mp_bsc_ssn, mp_msc_ssn);
Harald Weltebe620f62017-11-25 00:23:54 +0100158 id := "BSC" & int2str(i);
Daniel Willmannc07f6f52019-03-28 13:03:55 +0100159 bsc[i].BSC := BSC_CT.create(id);
Pau Espin Pedrol8d85ba42019-06-10 16:36:30 +0200160 var BSC_MS_TestHdlrParams pars;
161 pars.sccp_addr_own := bsc[i].sccp_addr_own;
162 pars.sccp_addr_remote := bsc[i].sccp_addr_peer;
163 pars.use_osmux := use_osmux;
Daniel Willmannfd338332017-11-24 17:23:23 +0100164 bsc[i].BSC.start(BSC_MS_Simulation.main(mp_nat_ip, mp_nat_port, mp_bsc_ip, mp_bsc_port+i,
Pau Espin Pedrol8d85ba42019-06-10 16:36:30 +0200165 bsc[i].sccp_pars, pars, fn_bsc_ms, id));
Harald Welteb3414b22017-11-23 18:22:10 +0100166 }
Harald Welte00566f52017-11-21 16:43:49 +0100167
Harald Weltec76f29f2017-11-22 12:46:46 +0100168}
169
Pau Espin Pedrolbdcfe032019-06-10 16:54:42 +0200170function f_wait_finish(timer T) runs on test_CT {
Harald Welte2fb04792017-11-25 01:14:35 +0100171 var integer i;
Harald Welte2fb04792017-11-25 01:14:35 +0100172 alt {
173 /* wait for BSC to stop. The idea is that the BSC components terminate first */
174 [] bsc[0].BSC.done { }
175 [] T.timeout { setverdict(fail); }
176 }
Harald Weltec76f29f2017-11-22 12:46:46 +0100177
Harald Welte2fb04792017-11-25 01:14:35 +0100178 all component.stop;
179 /* terminate the MSCs */
180 for (i := 0; i < NUM_MSC; i := i+1) {
181 msc[i].MSC.stop;
Harald Welte00566f52017-11-21 16:43:49 +0100182 }
Harald Weltec76f29f2017-11-22 12:46:46 +0100183}
Harald Welte00566f52017-11-21 16:43:49 +0100184
Pau Espin Pedrolbdcfe032019-06-10 16:54:42 +0200185
186function f_TC_recv_dump(boolean use_osmux := false) runs on test_CT {
187 timer T := 30.0;
188
Pau Espin Pedrol8d85ba42019-06-10 16:36:30 +0200189 f_init(refers(bsc_ms_establish_fully), use_osmux);
Pau Espin Pedrolbdcfe032019-06-10 16:54:42 +0200190
191 f_wait_finish(T);
192}
193
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200194testcase TC_recv_dump() runs on test_CT {
195 f_TC_recv_dump();
196}
197
198testcase TC_recv_dump_osmux() runs on test_CT {
199 f_TC_recv_dump(true);
200}
201
Harald Weltec76f29f2017-11-22 12:46:46 +0100202control {
203 execute( TC_recv_dump() );
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200204 execute( TC_recv_dump_osmux() );
Harald Weltec76f29f2017-11-22 12:46:46 +0100205}
206
Harald Welte00566f52017-11-21 16:43:49 +0100207}