Daniel Willmann | 0c6f34c | 2018-10-24 17:26:41 +0200 | [diff] [blame] | 1 | module BSCNAT_Tests { |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 2 | |
Harald Welte | 34b5a95 | 2019-05-27 11:54:11 +0200 | [diff] [blame] | 3 | /* 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 Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 14 | import from Osmocom_Types all; |
| 15 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 16 | import from IPL4asp_Types all; |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 17 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 18 | import from IPA_Emulation all; |
Pau Espin Pedrol | d1d4953 | 2019-06-10 18:09:16 +0200 | [diff] [blame] | 19 | import from RAN_Emulation all; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 20 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 21 | import from MTP3asp_Types all; |
| 22 | |
Pau Espin Pedrol | 8ab9a79 | 2019-06-10 21:02:03 +0200 | [diff] [blame] | 23 | import from Osmocom_CTRL_Functions all; |
| 24 | import from Osmocom_CTRL_Types all; |
| 25 | import from Osmocom_CTRL_Adapter all; |
| 26 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 27 | import from SCCP_Types all; |
| 28 | import from SCCPasp_Types all; |
| 29 | import from SCCP_Emulation all; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 30 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 31 | import from MSC_Simulation all; |
Pau Espin Pedrol | d1d4953 | 2019-06-10 18:09:16 +0200 | [diff] [blame] | 32 | import from MSC_ConnectionHandler all; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 33 | import from BSC_MS_Simulation all; |
Pau Espin Pedrol | 8d85ba4 | 2019-06-10 16:36:30 +0200 | [diff] [blame] | 34 | import from BSC_MS_ConnectionHandler all; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 35 | |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 36 | import from Osmocom_VTY_Functions all; |
| 37 | import from TELNETasp_PortType all; |
| 38 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 39 | const integer NUM_MSC := 1; |
| 40 | const integer NUM_BSC := 1; |
| 41 | |
| 42 | type record BscState { |
| 43 | BSC_CT BSC, |
| 44 | MSC_SCCP_MTP3_parameters sccp_pars, |
| 45 | SCCP_PAR_Address sccp_addr_own, |
| 46 | SCCP_PAR_Address sccp_addr_peer |
| 47 | } |
| 48 | |
| 49 | type record MscState { |
| 50 | MSC_CT MSC, |
| 51 | MSC_SCCP_MTP3_parameters sccp_pars, |
| 52 | SCCP_PAR_Address sccp_addr_own |
| 53 | } |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 54 | |
Pau Espin Pedrol | 8ab9a79 | 2019-06-10 21:02:03 +0200 | [diff] [blame] | 55 | type component test_CT extends CTRL_Adapter_CT { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 56 | var MscState msc[NUM_MSC]; |
| 57 | var BscState bsc[NUM_BSC]; |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 58 | |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 59 | port TELNETasp_PT BSCNATVTY; |
| 60 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 61 | var boolean g_initialized := false; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 62 | var octetstring g_sio := '83'O; |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 63 | } |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 64 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 65 | modulepar { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 66 | PortNumber mp_bsc_port := 49999; |
| 67 | charstring mp_bsc_ip := "127.0.0.1"; |
| 68 | |
| 69 | PortNumber mp_msc_port := 5000; |
| 70 | charstring mp_msc_ip := "127.0.0.1"; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 71 | |
Pau Espin Pedrol | 8ab9a79 | 2019-06-10 21:02:03 +0200 | [diff] [blame] | 72 | /* port number to which to establish the IPA CTRL connection */ |
| 73 | integer mp_nat_ctrl_port := 4250; |
| 74 | /* port number to which to establish the SCCPLite connection */ |
Daniel Willmann | fd33833 | 2017-11-24 17:23:23 +0100 | [diff] [blame] | 75 | PortNumber mp_nat_port := 5000; |
| 76 | charstring mp_nat_ip := "127.0.0.1"; |
| 77 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 78 | charstring mp_sccp_service_type := "mtp3_itu"; |
| 79 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 80 | integer mp_bsc_pc := 196; |
| 81 | integer mp_bsc_ssn := 254; |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 82 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 83 | integer mp_msc_pc := 185; /* 0.23.1 */ |
| 84 | integer mp_msc_ssn := 254; |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 85 | } |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 86 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 87 | /* construct a SCCP_PAR_Address with just PC + SSN and no GT */ |
| 88 | template (value) SCCP_PAR_Address ts_SccpAddr_PC_SSN(integer pc, integer ssn) := { |
| 89 | addressIndicator := { |
| 90 | pointCodeIndic := '1'B, |
| 91 | ssnIndicator := '1'B, |
| 92 | globalTitleIndic := '0000'B, |
| 93 | routingIndicator := '1'B |
| 94 | }, |
| 95 | signPointCode := SCCP_SPC_int2bit(pc, mp_sccp_service_type, '83'O), |
| 96 | //signPointCode := SCCP_SPC_int2bit(pc, mp_sccp_service_type, g_sio), |
| 97 | subsystemNumber := ssn, |
| 98 | globalTitle := omit |
| 99 | } |
| 100 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 101 | template MTP3_Field_sio ts_sio(octetstring sio_in) := { |
| 102 | ni := substr(oct2bit(sio_in),0,2), |
| 103 | prio := substr(oct2bit(sio_in),2,2), |
| 104 | si := substr(oct2bit(sio_in),4,4) |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 105 | } |
| 106 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 107 | template MSC_SCCP_MTP3_parameters ts_SCCP_Pars(octetstring sio, integer opc, integer dpc, |
| 108 | integer local_ssn) := { |
| 109 | sio := ts_sio(sio), |
| 110 | opc := opc, |
| 111 | dpc := dpc, |
| 112 | sls := 0, |
| 113 | sccp_serviceType := mp_sccp_service_type, |
| 114 | ssn := local_ssn |
| 115 | }; |
| 116 | |
| 117 | function f_init_BscState(inout BscState bsc_st, integer opc, integer dpc, integer local_ssn, integer remote_ssn) |
| 118 | runs on test_CT { |
| 119 | bsc_st.sccp_pars := valueof(ts_SCCP_Pars(g_sio, opc, dpc, local_ssn)); |
| 120 | bsc_st.sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(opc, local_ssn)); |
| 121 | bsc_st.sccp_addr_peer := valueof(ts_SccpAddr_PC_SSN(dpc, remote_ssn)); |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 122 | } |
| 123 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 124 | function f_init_MscState(inout MscState msc_st, integer opc, integer dpc, integer local_ssn, integer remote_ssn) |
| 125 | runs on test_CT { |
| 126 | msc_st.sccp_pars := valueof(ts_SCCP_Pars(g_sio, opc, dpc, local_ssn)); |
| 127 | msc_st.sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(opc, local_ssn)); |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 128 | } |
| 129 | |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 130 | function f_vty_allow_osmux(boolean allow) runs on test_CT { |
| 131 | if (allow) { |
| 132 | f_vty_config(BSCNATVTY, "mgcp", "osmux on"); |
| 133 | } else { |
| 134 | f_vty_config(BSCNATVTY, "mgcp", "osmux off"); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | function f_init_vty(charstring id := "foo") runs on test_CT { |
| 139 | if (BSCNATVTY.checkstate("Mapped")) { |
| 140 | /* skip initialization if already executed once */ |
| 141 | return; |
| 142 | } |
| 143 | map(self:BSCNATVTY, system:BSCNATVTY); |
| 144 | f_vty_set_prompts(BSCNATVTY); |
| 145 | f_vty_transceive(BSCNATVTY, "enable"); |
| 146 | } |
| 147 | |
Pau Espin Pedrol | a839604 | 2019-06-10 19:21:52 +0200 | [diff] [blame] | 148 | function f_init(void_fn_bsc_ms fn_bsc_ms, void_fn_bsc fn_bsc, BssmapCreateCallback cb_msc, boolean use_osmux) runs on test_CT { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 149 | var integer i; |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 150 | var charstring id; |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 151 | |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 152 | f_init_vty("VirtBSCNAT"); |
| 153 | f_vty_allow_osmux(use_osmux); |
Pau Espin Pedrol | 8ab9a79 | 2019-06-10 21:02:03 +0200 | [diff] [blame] | 154 | f_ipa_ctrl_start(mp_nat_ip, mp_nat_ctrl_port); |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 155 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 156 | for (i := 0; i < NUM_MSC; i := i+1) { |
| 157 | f_init_MscState(msc[i], mp_msc_pc +i, mp_bsc_pc, mp_msc_ssn, mp_bsc_ssn); |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 158 | id := "MSC" & int2str(i); |
Daniel Willmann | c07f6f5 | 2019-03-28 13:03:55 +0100 | [diff] [blame] | 159 | msc[i].MSC := MSC_CT.create(id); |
Pau Espin Pedrol | d1d4953 | 2019-06-10 18:09:16 +0200 | [diff] [blame] | 160 | msc[i].MSC.start(MSC_Simulation.main(mp_msc_ip, mp_msc_port + i, |
| 161 | msc[i].sccp_pars, msc[i].sccp_addr_own, |
| 162 | cb_msc, id)); |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Daniel Willmann | 991fd78 | 2018-10-25 17:20:27 +0200 | [diff] [blame] | 165 | /* Wait for bsc_nat to attach to MSC. Before that all BSC connections will be dropped */ |
| 166 | f_sleep(5.0); |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 167 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 168 | for (i := 0; i < NUM_BSC; i := i+1) { |
| 169 | f_init_BscState(bsc[i], mp_bsc_pc +i, mp_msc_pc, mp_bsc_ssn, mp_msc_ssn); |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 170 | id := "BSC" & int2str(i); |
Daniel Willmann | c07f6f5 | 2019-03-28 13:03:55 +0100 | [diff] [blame] | 171 | bsc[i].BSC := BSC_CT.create(id); |
Pau Espin Pedrol | 8d85ba4 | 2019-06-10 16:36:30 +0200 | [diff] [blame] | 172 | var BSC_MS_TestHdlrParams pars; |
| 173 | pars.sccp_addr_own := bsc[i].sccp_addr_own; |
| 174 | pars.sccp_addr_remote := bsc[i].sccp_addr_peer; |
| 175 | pars.use_osmux := use_osmux; |
Daniel Willmann | fd33833 | 2017-11-24 17:23:23 +0100 | [diff] [blame] | 176 | bsc[i].BSC.start(BSC_MS_Simulation.main(mp_nat_ip, mp_nat_port, mp_bsc_ip, mp_bsc_port+i, |
Pau Espin Pedrol | a839604 | 2019-06-10 19:21:52 +0200 | [diff] [blame] | 177 | bsc[i].sccp_pars, pars, fn_bsc_ms, fn_bsc, id)); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 178 | } |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 179 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Pau Espin Pedrol | bdcfe03 | 2019-06-10 16:54:42 +0200 | [diff] [blame] | 182 | function f_wait_finish(timer T) runs on test_CT { |
Harald Welte | 2fb0479 | 2017-11-25 01:14:35 +0100 | [diff] [blame] | 183 | var integer i; |
Harald Welte | 2fb0479 | 2017-11-25 01:14:35 +0100 | [diff] [blame] | 184 | alt { |
| 185 | /* wait for BSC to stop. The idea is that the BSC components terminate first */ |
| 186 | [] bsc[0].BSC.done { } |
| 187 | [] T.timeout { setverdict(fail); } |
| 188 | } |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 189 | |
Harald Welte | 2fb0479 | 2017-11-25 01:14:35 +0100 | [diff] [blame] | 190 | all component.stop; |
| 191 | /* terminate the MSCs */ |
| 192 | for (i := 0; i < NUM_MSC; i := i+1) { |
| 193 | msc[i].MSC.stop; |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 194 | } |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 195 | } |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 196 | |
Pau Espin Pedrol | bdcfe03 | 2019-06-10 16:54:42 +0200 | [diff] [blame] | 197 | |
| 198 | function f_TC_recv_dump(boolean use_osmux := false) runs on test_CT { |
| 199 | timer T := 30.0; |
| 200 | |
Pau Espin Pedrol | d1d4953 | 2019-06-10 18:09:16 +0200 | [diff] [blame] | 201 | f_init(refers(bsc_ms_establish_fully), |
Pau Espin Pedrol | a839604 | 2019-06-10 19:21:52 +0200 | [diff] [blame] | 202 | refers(bsc_do_nothing), |
Pau Espin Pedrol | d1d4953 | 2019-06-10 18:09:16 +0200 | [diff] [blame] | 203 | refers(CreateCallback_establish_fully), |
| 204 | use_osmux); |
Pau Espin Pedrol | bdcfe03 | 2019-06-10 16:54:42 +0200 | [diff] [blame] | 205 | |
| 206 | f_wait_finish(T); |
| 207 | } |
| 208 | |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 209 | testcase TC_recv_dump() runs on test_CT { |
| 210 | f_TC_recv_dump(); |
| 211 | } |
| 212 | |
| 213 | testcase TC_recv_dump_osmux() runs on test_CT { |
| 214 | f_TC_recv_dump(true); |
| 215 | } |
| 216 | |
Pau Espin Pedrol | 8ab9a79 | 2019-06-10 21:02:03 +0200 | [diff] [blame] | 217 | testcase TC_ctrl_location() runs on test_CT { |
| 218 | timer T := 30.0; |
| 219 | |
| 220 | f_init(refers(bsc_ms_do_nothing), |
| 221 | refers(bsc_ctrl_location), |
| 222 | refers(CreateCallback_establish_fully), |
| 223 | false); |
| 224 | |
| 225 | f_ctrl_exp_trap(IPA_CTRL, "net.0.bsc.0.bts.0.location-state", |
| 226 | "1234567,fix3d,0.340000,0.560000,0.780000,operational,unlocked,on,001,01", |
| 227 | 10.0); |
| 228 | f_ctrl_set(IPA_CTRL, "net.0.bsc.0.rf_locked", "1"); |
| 229 | |
| 230 | f_wait_finish(T); |
| 231 | } |
| 232 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 233 | control { |
| 234 | execute( TC_recv_dump() ); |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 235 | execute( TC_recv_dump_osmux() ); |
Pau Espin Pedrol | 8ab9a79 | 2019-06-10 21:02:03 +0200 | [diff] [blame] | 236 | execute( TC_ctrl_location() ); |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 237 | } |
| 238 | |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 239 | } |