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 | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 3 | import from Osmocom_Types all; |
| 4 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 5 | import from IPL4asp_Types all; |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 6 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 7 | import from IPA_Emulation all; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 8 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 9 | import from MTP3asp_Types all; |
| 10 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 11 | import from SCCP_Types all; |
| 12 | import from SCCPasp_Types all; |
| 13 | import from SCCP_Emulation all; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 14 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 15 | import from MSC_Simulation all; |
| 16 | import from BSC_MS_Simulation all; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 17 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 18 | const integer NUM_MSC := 1; |
| 19 | const integer NUM_BSC := 1; |
| 20 | |
| 21 | type record BscState { |
| 22 | BSC_CT BSC, |
| 23 | MSC_SCCP_MTP3_parameters sccp_pars, |
| 24 | SCCP_PAR_Address sccp_addr_own, |
| 25 | SCCP_PAR_Address sccp_addr_peer |
| 26 | } |
| 27 | |
| 28 | type record MscState { |
| 29 | MSC_CT MSC, |
| 30 | MSC_SCCP_MTP3_parameters sccp_pars, |
| 31 | SCCP_PAR_Address sccp_addr_own |
| 32 | } |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 33 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 34 | type component test_CT { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 35 | var MscState msc[NUM_MSC]; |
| 36 | var BscState bsc[NUM_BSC]; |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 37 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 38 | var boolean g_initialized := false; |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 39 | var octetstring g_sio := '83'O; |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 40 | } |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 41 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 42 | modulepar { |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 43 | PortNumber mp_bsc_port := 49999; |
| 44 | charstring mp_bsc_ip := "127.0.0.1"; |
| 45 | |
| 46 | PortNumber mp_msc_port := 5000; |
| 47 | charstring mp_msc_ip := "127.0.0.1"; |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 48 | |
Daniel Willmann | fd33833 | 2017-11-24 17:23:23 +0100 | [diff] [blame] | 49 | PortNumber mp_nat_port := 5000; |
| 50 | charstring mp_nat_ip := "127.0.0.1"; |
| 51 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 52 | charstring mp_sccp_service_type := "mtp3_itu"; |
| 53 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 54 | integer mp_bsc_pc := 196; |
| 55 | integer mp_bsc_ssn := 254; |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 56 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 57 | integer mp_msc_pc := 185; /* 0.23.1 */ |
| 58 | integer mp_msc_ssn := 254; |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 59 | } |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 60 | |
Harald Welte | d86cdc6 | 2017-11-22 00:45:07 +0100 | [diff] [blame] | 61 | /* construct a SCCP_PAR_Address with just PC + SSN and no GT */ |
| 62 | template (value) SCCP_PAR_Address ts_SccpAddr_PC_SSN(integer pc, integer ssn) := { |
| 63 | addressIndicator := { |
| 64 | pointCodeIndic := '1'B, |
| 65 | ssnIndicator := '1'B, |
| 66 | globalTitleIndic := '0000'B, |
| 67 | routingIndicator := '1'B |
| 68 | }, |
| 69 | signPointCode := SCCP_SPC_int2bit(pc, mp_sccp_service_type, '83'O), |
| 70 | //signPointCode := SCCP_SPC_int2bit(pc, mp_sccp_service_type, g_sio), |
| 71 | subsystemNumber := ssn, |
| 72 | globalTitle := omit |
| 73 | } |
| 74 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 75 | template MTP3_Field_sio ts_sio(octetstring sio_in) := { |
| 76 | ni := substr(oct2bit(sio_in),0,2), |
| 77 | prio := substr(oct2bit(sio_in),2,2), |
| 78 | si := substr(oct2bit(sio_in),4,4) |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 79 | } |
| 80 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 81 | template MSC_SCCP_MTP3_parameters ts_SCCP_Pars(octetstring sio, integer opc, integer dpc, |
| 82 | integer local_ssn) := { |
| 83 | sio := ts_sio(sio), |
| 84 | opc := opc, |
| 85 | dpc := dpc, |
| 86 | sls := 0, |
| 87 | sccp_serviceType := mp_sccp_service_type, |
| 88 | ssn := local_ssn |
| 89 | }; |
| 90 | |
| 91 | function f_init_BscState(inout BscState bsc_st, integer opc, integer dpc, integer local_ssn, integer remote_ssn) |
| 92 | runs on test_CT { |
| 93 | bsc_st.sccp_pars := valueof(ts_SCCP_Pars(g_sio, opc, dpc, local_ssn)); |
| 94 | bsc_st.sccp_addr_own := valueof(ts_SccpAddr_PC_SSN(opc, local_ssn)); |
| 95 | 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] | 96 | } |
| 97 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 98 | function f_init_MscState(inout MscState msc_st, integer opc, integer dpc, integer local_ssn, integer remote_ssn) |
| 99 | runs on test_CT { |
| 100 | msc_st.sccp_pars := valueof(ts_SCCP_Pars(g_sio, opc, dpc, local_ssn)); |
| 101 | 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] | 102 | } |
| 103 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 104 | function f_init() runs on test_CT { |
| 105 | var integer i; |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 106 | var charstring id; |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 107 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 108 | for (i := 0; i < NUM_MSC; i := i+1) { |
| 109 | f_init_MscState(msc[i], mp_msc_pc +i, mp_bsc_pc, mp_msc_ssn, mp_bsc_ssn); |
| 110 | msc[i].MSC := MSC_CT.create; |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 111 | id := "MSC" & int2str(i); |
| 112 | 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] | 113 | } |
| 114 | |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 115 | for (i := 0; i < NUM_BSC; i := i+1) { |
| 116 | f_init_BscState(bsc[i], mp_bsc_pc +i, mp_msc_pc, mp_bsc_ssn, mp_msc_ssn); |
| 117 | bsc[i].BSC := BSC_CT.create; |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 118 | id := "BSC" & int2str(i); |
Daniel Willmann | fd33833 | 2017-11-24 17:23:23 +0100 | [diff] [blame] | 119 | 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] | 120 | bsc[i].sccp_pars, bsc[i].sccp_addr_own, |
Harald Welte | be620f6 | 2017-11-25 00:23:54 +0100 | [diff] [blame] | 121 | bsc[i].sccp_addr_peer, id)); |
Harald Welte | b3414b2 | 2017-11-23 18:22:10 +0100 | [diff] [blame] | 122 | } |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 123 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | testcase TC_recv_dump() runs on test_CT { |
Harald Welte | 2fb0479 | 2017-11-25 01:14:35 +0100 | [diff] [blame] | 127 | var integer i; |
| 128 | timer T := 30.0; |
| 129 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 130 | f_init(); |
| 131 | |
Harald Welte | 2fb0479 | 2017-11-25 01:14:35 +0100 | [diff] [blame] | 132 | alt { |
| 133 | /* wait for BSC to stop. The idea is that the BSC components terminate first */ |
| 134 | [] bsc[0].BSC.done { } |
| 135 | [] T.timeout { setverdict(fail); } |
| 136 | } |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 137 | |
Harald Welte | 2fb0479 | 2017-11-25 01:14:35 +0100 | [diff] [blame] | 138 | all component.stop; |
| 139 | /* terminate the MSCs */ |
| 140 | for (i := 0; i < NUM_MSC; i := i+1) { |
| 141 | msc[i].MSC.stop; |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 142 | } |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 143 | } |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 144 | |
Harald Welte | c76f29f | 2017-11-22 12:46:46 +0100 | [diff] [blame] | 145 | control { |
| 146 | execute( TC_recv_dump() ); |
| 147 | } |
| 148 | |
Harald Welte | 00566f5 | 2017-11-21 16:43:49 +0100 | [diff] [blame] | 149 | } |