blob: 47d894b57f7d259cc8ab2c52d45345d2720a1af3 [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;
Pau Espin Pedrold1d49532019-06-10 18:09:16 +020019import from RAN_Emulation all;
Harald Welted86cdc62017-11-22 00:45:07 +010020
Harald Welteb3414b22017-11-23 18:22:10 +010021import from MTP3asp_Types all;
22
Harald Weltec76f29f2017-11-22 12:46:46 +010023import from SCCP_Types all;
24import from SCCPasp_Types all;
25import from SCCP_Emulation all;
Harald Welted86cdc62017-11-22 00:45:07 +010026
Harald Welteb3414b22017-11-23 18:22:10 +010027import from MSC_Simulation all;
Pau Espin Pedrold1d49532019-06-10 18:09:16 +020028import from MSC_ConnectionHandler all;
Harald Welteb3414b22017-11-23 18:22:10 +010029import from BSC_MS_Simulation all;
Pau Espin Pedrol8d85ba42019-06-10 16:36:30 +020030import from BSC_MS_ConnectionHandler all;
Harald Welted86cdc62017-11-22 00:45:07 +010031
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +020032import from Osmocom_VTY_Functions all;
33import from TELNETasp_PortType all;
34
Harald Welteb3414b22017-11-23 18:22:10 +010035const integer NUM_MSC := 1;
36const integer NUM_BSC := 1;
37
38type record BscState {
39 BSC_CT BSC,
40 MSC_SCCP_MTP3_parameters sccp_pars,
41 SCCP_PAR_Address sccp_addr_own,
42 SCCP_PAR_Address sccp_addr_peer
43}
44
45type record MscState {
46 MSC_CT MSC,
47 MSC_SCCP_MTP3_parameters sccp_pars,
48 SCCP_PAR_Address sccp_addr_own
49}
Harald Welte00566f52017-11-21 16:43:49 +010050
Harald Weltec76f29f2017-11-22 12:46:46 +010051type component test_CT {
Harald Welteb3414b22017-11-23 18:22:10 +010052 var MscState msc[NUM_MSC];
53 var BscState bsc[NUM_BSC];
Harald Welte00566f52017-11-21 16:43:49 +010054
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +020055 port TELNETasp_PT BSCNATVTY;
56
Harald Weltec76f29f2017-11-22 12:46:46 +010057 var boolean g_initialized := false;
Harald Welteb3414b22017-11-23 18:22:10 +010058 var octetstring g_sio := '83'O;
Harald Weltec76f29f2017-11-22 12:46:46 +010059}
Harald Welted86cdc62017-11-22 00:45:07 +010060
Harald Weltec76f29f2017-11-22 12:46:46 +010061modulepar {
Harald Welteb3414b22017-11-23 18:22:10 +010062 PortNumber mp_bsc_port := 49999;
63 charstring mp_bsc_ip := "127.0.0.1";
64
65 PortNumber mp_msc_port := 5000;
66 charstring mp_msc_ip := "127.0.0.1";
Harald Welted86cdc62017-11-22 00:45:07 +010067
Daniel Willmannfd338332017-11-24 17:23:23 +010068 PortNumber mp_nat_port := 5000;
69 charstring mp_nat_ip := "127.0.0.1";
70
Harald Weltec76f29f2017-11-22 12:46:46 +010071 charstring mp_sccp_service_type := "mtp3_itu";
72
Harald Welteb3414b22017-11-23 18:22:10 +010073 integer mp_bsc_pc := 196;
74 integer mp_bsc_ssn := 254;
Harald Weltec76f29f2017-11-22 12:46:46 +010075
Harald Welteb3414b22017-11-23 18:22:10 +010076 integer mp_msc_pc := 185; /* 0.23.1 */
77 integer mp_msc_ssn := 254;
Harald Weltec76f29f2017-11-22 12:46:46 +010078}
Harald Welte00566f52017-11-21 16:43:49 +010079
Harald Welted86cdc62017-11-22 00:45:07 +010080/* construct a SCCP_PAR_Address with just PC + SSN and no GT */
81template (value) SCCP_PAR_Address ts_SccpAddr_PC_SSN(integer pc, integer ssn) := {
82 addressIndicator := {
83 pointCodeIndic := '1'B,
84 ssnIndicator := '1'B,
85 globalTitleIndic := '0000'B,
86 routingIndicator := '1'B
87 },
88 signPointCode := SCCP_SPC_int2bit(pc, mp_sccp_service_type, '83'O),
89 //signPointCode := SCCP_SPC_int2bit(pc, mp_sccp_service_type, g_sio),
90 subsystemNumber := ssn,
91 globalTitle := omit
92}
93
Harald Welteb3414b22017-11-23 18:22:10 +010094template MTP3_Field_sio ts_sio(octetstring sio_in) := {
95 ni := substr(oct2bit(sio_in),0,2),
96 prio := substr(oct2bit(sio_in),2,2),
97 si := substr(oct2bit(sio_in),4,4)
Harald Weltec76f29f2017-11-22 12:46:46 +010098}
99
Harald Welteb3414b22017-11-23 18:22:10 +0100100template MSC_SCCP_MTP3_parameters ts_SCCP_Pars(octetstring sio, integer opc, integer dpc,
101 integer local_ssn) := {
102 sio := ts_sio(sio),
103 opc := opc,
104 dpc := dpc,
105 sls := 0,
106 sccp_serviceType := mp_sccp_service_type,
107 ssn := local_ssn
108};
109
110function f_init_BscState(inout BscState bsc_st, integer opc, integer dpc, integer local_ssn, integer remote_ssn)
111runs on test_CT {
112 bsc_st.sccp_pars := valueof(ts_SCCP_Pars(g_sio, opc, dpc, local_ssn));
113 bsc_st.sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(opc, local_ssn));
114 bsc_st.sccp_addr_peer := valueof(ts_SccpAddr_PC_SSN(dpc, remote_ssn));
Harald Weltec76f29f2017-11-22 12:46:46 +0100115}
116
Harald Welteb3414b22017-11-23 18:22:10 +0100117function f_init_MscState(inout MscState msc_st, integer opc, integer dpc, integer local_ssn, integer remote_ssn)
118runs on test_CT {
119 msc_st.sccp_pars := valueof(ts_SCCP_Pars(g_sio, opc, dpc, local_ssn));
120 msc_st.sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(opc, local_ssn));
Harald Welted86cdc62017-11-22 00:45:07 +0100121}
122
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200123function f_vty_allow_osmux(boolean allow) runs on test_CT {
124 if (allow) {
125 f_vty_config(BSCNATVTY, "mgcp", "osmux on");
126 } else {
127 f_vty_config(BSCNATVTY, "mgcp", "osmux off");
128 }
129}
130
131function f_init_vty(charstring id := "foo") runs on test_CT {
132 if (BSCNATVTY.checkstate("Mapped")) {
133 /* skip initialization if already executed once */
134 return;
135 }
136 map(self:BSCNATVTY, system:BSCNATVTY);
137 f_vty_set_prompts(BSCNATVTY);
138 f_vty_transceive(BSCNATVTY, "enable");
139}
140
Pau Espin Pedrold1d49532019-06-10 18:09:16 +0200141function f_init(void_fn_bsc_ms fn_bsc_ms, BssmapCreateCallback cb_msc, boolean use_osmux) runs on test_CT {
Harald Welteb3414b22017-11-23 18:22:10 +0100142 var integer i;
Harald Weltebe620f62017-11-25 00:23:54 +0100143 var charstring id;
Harald Welte00566f52017-11-21 16:43:49 +0100144
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200145 f_init_vty("VirtBSCNAT");
146 f_vty_allow_osmux(use_osmux);
147
Harald Welteb3414b22017-11-23 18:22:10 +0100148 for (i := 0; i < NUM_MSC; i := i+1) {
149 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 +0100150 id := "MSC" & int2str(i);
Daniel Willmannc07f6f52019-03-28 13:03:55 +0100151 msc[i].MSC := MSC_CT.create(id);
Pau Espin Pedrold1d49532019-06-10 18:09:16 +0200152 msc[i].MSC.start(MSC_Simulation.main(mp_msc_ip, mp_msc_port + i,
153 msc[i].sccp_pars, msc[i].sccp_addr_own,
154 cb_msc, id));
Harald Welte00566f52017-11-21 16:43:49 +0100155 }
156
Daniel Willmann991fd782018-10-25 17:20:27 +0200157 /* Wait for bsc_nat to attach to MSC. Before that all BSC connections will be dropped */
158 f_sleep(5.0);
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200159
Harald Welteb3414b22017-11-23 18:22:10 +0100160 for (i := 0; i < NUM_BSC; i := i+1) {
161 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 +0100162 id := "BSC" & int2str(i);
Daniel Willmannc07f6f52019-03-28 13:03:55 +0100163 bsc[i].BSC := BSC_CT.create(id);
Pau Espin Pedrol8d85ba42019-06-10 16:36:30 +0200164 var BSC_MS_TestHdlrParams pars;
165 pars.sccp_addr_own := bsc[i].sccp_addr_own;
166 pars.sccp_addr_remote := bsc[i].sccp_addr_peer;
167 pars.use_osmux := use_osmux;
Daniel Willmannfd338332017-11-24 17:23:23 +0100168 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 +0200169 bsc[i].sccp_pars, pars, fn_bsc_ms, id));
Harald Welteb3414b22017-11-23 18:22:10 +0100170 }
Harald Welte00566f52017-11-21 16:43:49 +0100171
Harald Weltec76f29f2017-11-22 12:46:46 +0100172}
173
Pau Espin Pedrolbdcfe032019-06-10 16:54:42 +0200174function f_wait_finish(timer T) runs on test_CT {
Harald Welte2fb04792017-11-25 01:14:35 +0100175 var integer i;
Harald Welte2fb04792017-11-25 01:14:35 +0100176 alt {
177 /* wait for BSC to stop. The idea is that the BSC components terminate first */
178 [] bsc[0].BSC.done { }
179 [] T.timeout { setverdict(fail); }
180 }
Harald Weltec76f29f2017-11-22 12:46:46 +0100181
Harald Welte2fb04792017-11-25 01:14:35 +0100182 all component.stop;
183 /* terminate the MSCs */
184 for (i := 0; i < NUM_MSC; i := i+1) {
185 msc[i].MSC.stop;
Harald Welte00566f52017-11-21 16:43:49 +0100186 }
Harald Weltec76f29f2017-11-22 12:46:46 +0100187}
Harald Welte00566f52017-11-21 16:43:49 +0100188
Pau Espin Pedrolbdcfe032019-06-10 16:54:42 +0200189
190function f_TC_recv_dump(boolean use_osmux := false) runs on test_CT {
191 timer T := 30.0;
192
Pau Espin Pedrold1d49532019-06-10 18:09:16 +0200193 f_init(refers(bsc_ms_establish_fully),
194 refers(CreateCallback_establish_fully),
195 use_osmux);
Pau Espin Pedrolbdcfe032019-06-10 16:54:42 +0200196
197 f_wait_finish(T);
198}
199
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200200testcase TC_recv_dump() runs on test_CT {
201 f_TC_recv_dump();
202}
203
204testcase TC_recv_dump_osmux() runs on test_CT {
205 f_TC_recv_dump(true);
206}
207
Harald Weltec76f29f2017-11-22 12:46:46 +0100208control {
209 execute( TC_recv_dump() );
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200210 execute( TC_recv_dump_osmux() );
Harald Weltec76f29f2017-11-22 12:46:46 +0100211}
212
Harald Welte00566f52017-11-21 16:43:49 +0100213}