blob: 6b0c757adc4bae4a7aa55ed9884e7121b25c41b2 [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;
Harald Welted86cdc62017-11-22 00:45:07 +010028
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +020029import from Osmocom_VTY_Functions all;
30import from TELNETasp_PortType all;
31
Harald Welteb3414b22017-11-23 18:22:10 +010032const integer NUM_MSC := 1;
33const integer NUM_BSC := 1;
34
35type record BscState {
36 BSC_CT BSC,
37 MSC_SCCP_MTP3_parameters sccp_pars,
38 SCCP_PAR_Address sccp_addr_own,
39 SCCP_PAR_Address sccp_addr_peer
40}
41
42type record MscState {
43 MSC_CT MSC,
44 MSC_SCCP_MTP3_parameters sccp_pars,
45 SCCP_PAR_Address sccp_addr_own
46}
Harald Welte00566f52017-11-21 16:43:49 +010047
Harald Weltec76f29f2017-11-22 12:46:46 +010048type component test_CT {
Harald Welteb3414b22017-11-23 18:22:10 +010049 var MscState msc[NUM_MSC];
50 var BscState bsc[NUM_BSC];
Harald Welte00566f52017-11-21 16:43:49 +010051
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +020052 port TELNETasp_PT BSCNATVTY;
53
Harald Weltec76f29f2017-11-22 12:46:46 +010054 var boolean g_initialized := false;
Harald Welteb3414b22017-11-23 18:22:10 +010055 var octetstring g_sio := '83'O;
Harald Weltec76f29f2017-11-22 12:46:46 +010056}
Harald Welted86cdc62017-11-22 00:45:07 +010057
Harald Weltec76f29f2017-11-22 12:46:46 +010058modulepar {
Harald Welteb3414b22017-11-23 18:22:10 +010059 PortNumber mp_bsc_port := 49999;
60 charstring mp_bsc_ip := "127.0.0.1";
61
62 PortNumber mp_msc_port := 5000;
63 charstring mp_msc_ip := "127.0.0.1";
Harald Welted86cdc62017-11-22 00:45:07 +010064
Daniel Willmannfd338332017-11-24 17:23:23 +010065 PortNumber mp_nat_port := 5000;
66 charstring mp_nat_ip := "127.0.0.1";
67
Harald Weltec76f29f2017-11-22 12:46:46 +010068 charstring mp_sccp_service_type := "mtp3_itu";
69
Harald Welteb3414b22017-11-23 18:22:10 +010070 integer mp_bsc_pc := 196;
71 integer mp_bsc_ssn := 254;
Harald Weltec76f29f2017-11-22 12:46:46 +010072
Harald Welteb3414b22017-11-23 18:22:10 +010073 integer mp_msc_pc := 185; /* 0.23.1 */
74 integer mp_msc_ssn := 254;
Harald Weltec76f29f2017-11-22 12:46:46 +010075}
Harald Welte00566f52017-11-21 16:43:49 +010076
Harald Welted86cdc62017-11-22 00:45:07 +010077/* construct a SCCP_PAR_Address with just PC + SSN and no GT */
78template (value) SCCP_PAR_Address ts_SccpAddr_PC_SSN(integer pc, integer ssn) := {
79 addressIndicator := {
80 pointCodeIndic := '1'B,
81 ssnIndicator := '1'B,
82 globalTitleIndic := '0000'B,
83 routingIndicator := '1'B
84 },
85 signPointCode := SCCP_SPC_int2bit(pc, mp_sccp_service_type, '83'O),
86 //signPointCode := SCCP_SPC_int2bit(pc, mp_sccp_service_type, g_sio),
87 subsystemNumber := ssn,
88 globalTitle := omit
89}
90
Harald Welteb3414b22017-11-23 18:22:10 +010091template MTP3_Field_sio ts_sio(octetstring sio_in) := {
92 ni := substr(oct2bit(sio_in),0,2),
93 prio := substr(oct2bit(sio_in),2,2),
94 si := substr(oct2bit(sio_in),4,4)
Harald Weltec76f29f2017-11-22 12:46:46 +010095}
96
Harald Welteb3414b22017-11-23 18:22:10 +010097template MSC_SCCP_MTP3_parameters ts_SCCP_Pars(octetstring sio, integer opc, integer dpc,
98 integer local_ssn) := {
99 sio := ts_sio(sio),
100 opc := opc,
101 dpc := dpc,
102 sls := 0,
103 sccp_serviceType := mp_sccp_service_type,
104 ssn := local_ssn
105};
106
107function f_init_BscState(inout BscState bsc_st, integer opc, integer dpc, integer local_ssn, integer remote_ssn)
108runs on test_CT {
109 bsc_st.sccp_pars := valueof(ts_SCCP_Pars(g_sio, opc, dpc, local_ssn));
110 bsc_st.sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(opc, local_ssn));
111 bsc_st.sccp_addr_peer := valueof(ts_SccpAddr_PC_SSN(dpc, remote_ssn));
Harald Weltec76f29f2017-11-22 12:46:46 +0100112}
113
Harald Welteb3414b22017-11-23 18:22:10 +0100114function f_init_MscState(inout MscState msc_st, integer opc, integer dpc, integer local_ssn, integer remote_ssn)
115runs on test_CT {
116 msc_st.sccp_pars := valueof(ts_SCCP_Pars(g_sio, opc, dpc, local_ssn));
117 msc_st.sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(opc, local_ssn));
Harald Welted86cdc62017-11-22 00:45:07 +0100118}
119
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200120function f_vty_allow_osmux(boolean allow) runs on test_CT {
121 if (allow) {
122 f_vty_config(BSCNATVTY, "mgcp", "osmux on");
123 } else {
124 f_vty_config(BSCNATVTY, "mgcp", "osmux off");
125 }
126}
127
128function f_init_vty(charstring id := "foo") runs on test_CT {
129 if (BSCNATVTY.checkstate("Mapped")) {
130 /* skip initialization if already executed once */
131 return;
132 }
133 map(self:BSCNATVTY, system:BSCNATVTY);
134 f_vty_set_prompts(BSCNATVTY);
135 f_vty_transceive(BSCNATVTY, "enable");
136}
137
138function f_init(boolean use_osmux) runs on test_CT {
Harald Welteb3414b22017-11-23 18:22:10 +0100139 var integer i;
Harald Weltebe620f62017-11-25 00:23:54 +0100140 var charstring id;
Harald Welte00566f52017-11-21 16:43:49 +0100141
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200142 f_init_vty("VirtBSCNAT");
143 f_vty_allow_osmux(use_osmux);
144
Harald Welteb3414b22017-11-23 18:22:10 +0100145 for (i := 0; i < NUM_MSC; i := i+1) {
146 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 +0100147 id := "MSC" & int2str(i);
Daniel Willmannc07f6f52019-03-28 13:03:55 +0100148 msc[i].MSC := MSC_CT.create(id);
Harald Weltebe620f62017-11-25 00:23:54 +0100149 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 +0100150 }
151
Daniel Willmann991fd782018-10-25 17:20:27 +0200152 /* Wait for bsc_nat to attach to MSC. Before that all BSC connections will be dropped */
153 f_sleep(5.0);
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200154
Harald Welteb3414b22017-11-23 18:22:10 +0100155 for (i := 0; i < NUM_BSC; i := i+1) {
156 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 +0100157 id := "BSC" & int2str(i);
Daniel Willmannc07f6f52019-03-28 13:03:55 +0100158 bsc[i].BSC := BSC_CT.create(id);
Daniel Willmannfd338332017-11-24 17:23:23 +0100159 bsc[i].BSC.start(BSC_MS_Simulation.main(mp_nat_ip, mp_nat_port, mp_bsc_ip, mp_bsc_port+i,
Harald Welteb3414b22017-11-23 18:22:10 +0100160 bsc[i].sccp_pars, bsc[i].sccp_addr_own,
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200161 bsc[i].sccp_addr_peer, use_osmux, id));
Harald Welteb3414b22017-11-23 18:22:10 +0100162 }
Harald Welte00566f52017-11-21 16:43:49 +0100163
Harald Weltec76f29f2017-11-22 12:46:46 +0100164}
165
Pau Espin Pedrolbdcfe032019-06-10 16:54:42 +0200166function f_wait_finish(timer T) runs on test_CT {
Harald Welte2fb04792017-11-25 01:14:35 +0100167 var integer i;
Harald Welte2fb04792017-11-25 01:14:35 +0100168 alt {
169 /* wait for BSC to stop. The idea is that the BSC components terminate first */
170 [] bsc[0].BSC.done { }
171 [] T.timeout { setverdict(fail); }
172 }
Harald Weltec76f29f2017-11-22 12:46:46 +0100173
Harald Welte2fb04792017-11-25 01:14:35 +0100174 all component.stop;
175 /* terminate the MSCs */
176 for (i := 0; i < NUM_MSC; i := i+1) {
177 msc[i].MSC.stop;
Harald Welte00566f52017-11-21 16:43:49 +0100178 }
Harald Weltec76f29f2017-11-22 12:46:46 +0100179}
Harald Welte00566f52017-11-21 16:43:49 +0100180
Pau Espin Pedrolbdcfe032019-06-10 16:54:42 +0200181
182function f_TC_recv_dump(boolean use_osmux := false) runs on test_CT {
183 timer T := 30.0;
184
185 f_init(use_osmux);
186
187 f_wait_finish(T);
188}
189
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200190testcase TC_recv_dump() runs on test_CT {
191 f_TC_recv_dump();
192}
193
194testcase TC_recv_dump_osmux() runs on test_CT {
195 f_TC_recv_dump(true);
196}
197
Harald Weltec76f29f2017-11-22 12:46:46 +0100198control {
199 execute( TC_recv_dump() );
Pau Espin Pedrolf3c12222019-05-22 15:18:42 +0200200 execute( TC_recv_dump_osmux() );
Harald Weltec76f29f2017-11-22 12:46:46 +0100201}
202
Harald Welte00566f52017-11-21 16:43:49 +0100203}