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; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 19 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 20 | import from MTP3asp_Types all; |
| 21 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 22 | import from SCCP_Types all; |
| 23 | import from SCCPasp_Types all; |
| 24 | import from SCCP_Emulation all; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 25 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 26 | import from MSC_Simulation all; |
| 27 | import from BSC_MS_Simulation all; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 28 | |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 29 | import from Osmocom_VTY_Functions all; |
| 30 | import from TELNETasp_PortType all; |
| 31 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 32 | const integer NUM_MSC := 1; |
| 33 | const integer NUM_BSC := 1; |
| 34 | |
| 35 | type 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 | |
| 42 | type record MscState { |
| 43 | MSC_CT MSC, |
| 44 | MSC_SCCP_MTP3_parameters sccp_pars, |
| 45 | SCCP_PAR_Address sccp_addr_own |
| 46 | } |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 47 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 48 | type component test_CT { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 49 | var MscState msc[NUM_MSC]; |
| 50 | var BscState bsc[NUM_BSC]; |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 51 | |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 52 | port TELNETasp_PT BSCNATVTY; |
| 53 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 54 | var boolean g_initialized := false; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 55 | var octetstring g_sio := '83'O; |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 56 | } |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 57 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 58 | modulepar { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 59 | 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 Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 64 | |
Daniel Willmann | fd33833 | 2017-11-24 17:23:23 +0100 | [diff] [blame] | 65 | PortNumber mp_nat_port := 5000; |
| 66 | charstring mp_nat_ip := "127.0.0.1"; |
| 67 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 68 | charstring mp_sccp_service_type := "mtp3_itu"; |
| 69 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 70 | integer mp_bsc_pc := 196; |
| 71 | integer mp_bsc_ssn := 254; |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 72 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 73 | integer mp_msc_pc := 185; /* 0.23.1 */ |
| 74 | integer mp_msc_ssn := 254; |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 75 | } |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 76 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 77 | /* construct a SCCP_PAR_Address with just PC + SSN and no GT */ |
| 78 | template (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 Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 91 | template 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 Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 97 | template 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 | |
| 107 | function f_init_BscState(inout BscState bsc_st, integer opc, integer dpc, integer local_ssn, integer remote_ssn) |
| 108 | runs 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 Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 114 | function f_init_MscState(inout MscState msc_st, integer opc, integer dpc, integer local_ssn, integer remote_ssn) |
| 115 | runs 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 Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 120 | function 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 | |
| 128 | function 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 | |
| 138 | function f_init(boolean use_osmux) runs on test_CT { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 139 | var integer i; |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 140 | var charstring id; |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 141 | |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 142 | f_init_vty("VirtBSCNAT"); |
| 143 | f_vty_allow_osmux(use_osmux); |
| 144 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 145 | 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 Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 147 | id := "MSC" & int2str(i); |
Daniel Willmann | c07f6f5 | 2019-03-28 13:03:55 +0100 | [diff] [blame] | 148 | msc[i].MSC := MSC_CT.create(id); |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 149 | 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 Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Daniel Willmann | 991fd78 | 2018-10-25 17:20:27 +0200 | [diff] [blame] | 152 | /* Wait for bsc_nat to attach to MSC. Before that all BSC connections will be dropped */ |
| 153 | f_sleep(5.0); |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 154 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 155 | 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 Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 157 | id := "BSC" & int2str(i); |
Daniel Willmann | c07f6f5 | 2019-03-28 13:03:55 +0100 | [diff] [blame] | 158 | bsc[i].BSC := BSC_CT.create(id); |
Daniel Willmann | fd33833 | 2017-11-24 17:23:23 +0100 | [diff] [blame] | 159 | bsc[i].BSC.start(BSC_MS_Simulation.main(mp_nat_ip, mp_nat_port, mp_bsc_ip, mp_bsc_port+i, |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 160 | bsc[i].sccp_pars, bsc[i].sccp_addr_own, |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 161 | bsc[i].sccp_addr_peer, use_osmux, id)); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 162 | } |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 163 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 166 | function f_TC_recv_dump(boolean use_osmux := false) runs on test_CT { |
Harald Welte | 2fb0479 | 2017-11-25 01:14:35 +0100 | [diff] [blame] | 167 | var integer i; |
| 168 | timer T := 30.0; |
| 169 | |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 170 | f_init(use_osmux); |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 171 | |
Harald Welte | 2fb0479 | 2017-11-25 01:14:35 +0100 | [diff] [blame] | 172 | 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 Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 177 | |
Harald Welte | 2fb0479 | 2017-11-25 01:14:35 +0100 | [diff] [blame] | 178 | all component.stop; |
| 179 | /* terminate the MSCs */ |
| 180 | for (i := 0; i < NUM_MSC; i := i+1) { |
| 181 | msc[i].MSC.stop; |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 182 | } |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 183 | } |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 184 | |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 185 | testcase TC_recv_dump() runs on test_CT { |
| 186 | f_TC_recv_dump(); |
| 187 | } |
| 188 | |
| 189 | testcase TC_recv_dump_osmux() runs on test_CT { |
| 190 | f_TC_recv_dump(true); |
| 191 | } |
| 192 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 193 | control { |
| 194 | execute( TC_recv_dump() ); |
Pau Espin Pedrol | f3c1222 | 2019-05-22 15:18:42 +0200 | [diff] [blame] | 195 | execute( TC_recv_dump_osmux() ); |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 196 | } |
| 197 | |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 198 | } |