Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 1 | /* (C) 2019 by Harald Welte <laforge@gnumonks.org> |
| 2 | * All Rights Reserved |
| 3 | * |
| 4 | * The idea is that these tests are executed against sccp_demo_user from |
| 5 | * libosmo-sccp.git in server mode. |
| 6 | * |
| 7 | * Released under the terms of GNU General Public License, Version 2 or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 11 | */ |
| 12 | |
| 13 | module SCCP_Tests_RAW { |
| 14 | |
| 15 | import from General_Types all; |
| 16 | import from Osmocom_Types all; |
| 17 | |
| 18 | import from M3UA_Emulation all; |
| 19 | |
| 20 | import from SCCP_Types all; |
| 21 | import from SCCPasp_Types all; |
| 22 | import from SCCP_Templates all; |
| 23 | import from SCCP_Emulation all; |
| 24 | import from SCCP_CodecPort all; |
| 25 | |
| 26 | import from TELNETasp_PortType all; |
| 27 | import from Osmocom_VTY_Functions all; |
| 28 | |
| 29 | import from SCCP_Tests all; |
| 30 | |
| 31 | type component SCCP_Test_RAW_CT { |
| 32 | /* VTY to sccp_demo_user (not used yet) */ |
| 33 | port TELNETasp_PT SCCP_DEMO_USER_VTY; |
| 34 | |
| 35 | /* SCCP raw port runs on top of M3UA Emulation. |
| 36 | * "System Under Test" is libosmo-sccp's sccp_demo_user example program. */ |
| 37 | var M3UA_CT vc_M3UA; |
| 38 | port SCCP_CODEC_PT MTP3; |
| 39 | |
| 40 | var MSC_SCCP_MTP3_parameters g_param; |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 41 | |
| 42 | /*Configure T(tias) over VTY, seconds */ |
| 43 | var integer g_demo_sccp_timer_ias := 7 * 60; |
| 44 | /*Configure T(tiar) over VTY, seconds */ |
| 45 | var integer g_demo_sccp_timer_iar := 15 * 60; |
| 46 | } |
| 47 | |
| 48 | type record of charstring Commands; |
| 49 | private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {}) |
| 50 | { |
| 51 | f_vty_enter_cfg_cs7_inst(pt, 0); |
| 52 | for (var integer i := 0; i < sizeof(cmds); i := i+1) { |
| 53 | f_vty_transceive(pt, cmds[i]); |
| 54 | } |
| 55 | f_vty_transceive(pt, "end"); |
| 56 | } |
| 57 | |
| 58 | function f_init_vty() runs on SCCP_Test_RAW_CT { |
| 59 | if (SCCP_DEMO_USER_VTY.checkstate("Mapped")) { |
| 60 | /* skip initialization if already executed once */ |
| 61 | return; |
| 62 | } |
| 63 | map(self:SCCP_DEMO_USER_VTY, system:SCCP_DEMO_USER_VTY); |
| 64 | f_vty_set_prompts(SCCP_DEMO_USER_VTY); |
| 65 | f_vty_transceive(SCCP_DEMO_USER_VTY, "enable"); |
| 66 | f_cs7_inst_0_cfg(SCCP_DEMO_USER_VTY, {"sccp-timer ias " & int2str(g_demo_sccp_timer_ias), |
| 67 | "sccp-timer iar " & int2str(g_demo_sccp_timer_iar)}); |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | private function f_init_raw(SCCP_Configuration cfg) runs on SCCP_Test_RAW_CT { |
| 71 | g_param := { |
| 72 | sio := { |
| 73 | ni := substr(oct2bit(cfg.sio),0,2), |
| 74 | prio := substr(oct2bit(cfg.sio),2,2), |
| 75 | si := substr(oct2bit(cfg.sio),4,4) |
| 76 | }, |
| 77 | opc := cfg.own_pc, |
| 78 | dpc := cfg.peer_pc, |
| 79 | sls := 0, |
| 80 | sccp_serviceType := cfg.sccp_service_type, |
| 81 | ssn := cfg.own_ssn |
| 82 | }; |
| 83 | |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 84 | f_init_vty(); |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 85 | |
| 86 | /* Create and connect test components */ |
| 87 | vc_M3UA := M3UA_CT.create; |
| 88 | connect(self:MTP3, vc_M3UA:MTP3_SP_PORT); |
| 89 | map(vc_M3UA:SCTP_PORT, system:sctp); |
| 90 | |
| 91 | vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr)); |
| 92 | } |
| 93 | |
| 94 | private function f_cleanup() runs on SCCP_Test_RAW_CT { |
| 95 | all component.stop; |
| 96 | unmap(vc_M3UA:SCTP_PORT, system:sctp); |
| 97 | disconnect(vc_M3UA:MTP3_SP_PORT, self:MTP3); |
| 98 | self.stop |
| 99 | } |
| 100 | |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 101 | private function f_send_sccp(template PDU_SCCP sccp) runs on SCCP_Test_RAW_CT { |
| 102 | var SCCP_MTP3_TRANSFERreq tx := { |
| 103 | sio := g_param.sio, |
| 104 | opc := g_param.opc, |
| 105 | dpc := g_param.dpc, |
| 106 | sls := g_param.sls, |
| 107 | data := valueof(sccp) |
| 108 | }; |
| 109 | MTP3.send(tx); |
| 110 | } |
| 111 | |
| 112 | private function f_exp_sccp(template PDU_SCCP sccp) runs on SCCP_Test_RAW_CT { |
| 113 | var SCCP_MTP3_TRANSFERind rx; |
| 114 | var template SCCP_MTP3_TRANSFERind exp := { |
| 115 | sio := g_param.sio, |
| 116 | opc := g_param.dpc, |
| 117 | dpc := g_param.opc, |
| 118 | sls := g_param.sls, |
| 119 | data := sccp |
| 120 | }; |
| 121 | timer T := 10.0; |
| 122 | T.start; |
| 123 | alt { |
| 124 | [] MTP3.receive(exp) -> value rx { |
| 125 | setverdict(pass); |
| 126 | } |
| 127 | [] MTP3.receive { |
| 128 | setverdict(fail, "Unexpected MTP/SCCP received"); |
Pau Espin Pedrol | 94b7a68 | 2020-01-20 19:30:07 +0100 | [diff] [blame] | 129 | self.stop |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 130 | } |
| 131 | [] T.timeout { |
| 132 | setverdict(fail, "Timeout waiting for ", exp); |
Pau Espin Pedrol | 94b7a68 | 2020-01-20 19:30:07 +0100 | [diff] [blame] | 133 | self.stop |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 138 | private function f_establish_conn(SCCP_PAR_Address calling, SCCP_PAR_Address called) runs on SCCP_Test_RAW_CT { |
| 139 | |
| 140 | f_send_sccp(ts_SCCP_CR('000001'O, calling, called)); |
| 141 | f_exp_sccp(tr_SCCP_CC('000000'O, '000001'O)); |
| 142 | } |
| 143 | |
| 144 | private function f_tx_udt_exp(SCCP_PAR_Address calling, SCCP_PAR_Address called, octetstring data) runs on SCCP_Test_RAW_CT { |
| 145 | |
| 146 | f_send_sccp(ts_SCCP_UDT(calling, called, data)); |
| 147 | f_exp_sccp(tr_SCCP_UDT(called, calling, data)); |
| 148 | } |
| 149 | |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 150 | /* Verify sccp_demo_user answers a CR with a CC for PC and SSN set up to echo back */ |
| 151 | testcase TC_cr_cc() runs on SCCP_Test_RAW_CT { |
| 152 | var SCCP_PAR_Address calling, called; |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 153 | |
| 154 | f_init_raw(mp_sccp_cfg[0]); |
| 155 | f_sleep(1.0); |
| 156 | |
Pau Espin Pedrol | e187091 | 2020-01-17 17:30:19 +0100 | [diff] [blame] | 157 | called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn, |
| 158 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 159 | calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn, |
| 160 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 161 | f_establish_conn(calling, called); |
| 162 | } |
| 163 | |
Pau Espin Pedrol | f7ba234 | 2020-01-20 20:19:47 +0100 | [diff] [blame^] | 164 | /* Verify sccp_demo_user answers a CR with a CC for PC and SSN set up to echo back */ |
| 165 | testcase TC_udt_without_cr_cc() runs on SCCP_Test_RAW_CT { |
| 166 | var SCCP_PAR_Address calling, called; |
| 167 | var octetstring data := f_rnd_octstring(f_rnd_int(100)); |
| 168 | |
| 169 | f_init_raw(mp_sccp_cfg[0]); |
| 170 | f_sleep(1.0); |
| 171 | |
| 172 | called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn, |
| 173 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 174 | calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn, |
| 175 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 176 | |
| 177 | f_tx_udt_exp(calling, called, data); |
| 178 | } |
| 179 | |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 180 | /* Verify T(iar) triggers and releases the channel */ |
| 181 | testcase TC_tiar_timeout() runs on SCCP_Test_RAW_CT { |
| 182 | var SCCP_PAR_Address calling, called; |
| 183 | var octetstring data := f_rnd_octstring(f_rnd_int(100)); |
| 184 | |
| 185 | /* Set T(iar) in sccp_demo_user low enough that it will trigger before other side |
| 186 | has time to keep alive with a T(ias). Keep recommended ratio of |
| 187 | T(iar) >= T(ias)*2 */ |
| 188 | g_demo_sccp_timer_ias := 2; |
| 189 | g_demo_sccp_timer_iar := 5; |
Pau Espin Pedrol | e187091 | 2020-01-17 17:30:19 +0100 | [diff] [blame] | 190 | f_init_raw(mp_sccp_cfg[0]); |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 191 | f_sleep(1.0); |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 192 | |
| 193 | called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn, |
| 194 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 195 | calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn, |
| 196 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 197 | f_establish_conn(calling, called); |
| 198 | f_tx_udt_exp(calling, called, data); |
| 199 | |
| 200 | log("Waiting for first IT"); |
| 201 | f_exp_sccp(tr_SCCP_IT(?, ?)); |
| 202 | log("Waiting for second IT"); |
| 203 | f_exp_sccp(tr_SCCP_IT(?, ?)); |
| 204 | |
| 205 | log("Waiting for RLSD"); |
| 206 | f_exp_sccp(tr_SCCP_RLSD(?, ?, hex2int('0D'H))); /* Cause: Expiration of Rx Inactivity Timer */ |
| 207 | f_send_sccp(ts_SCCP_RLC('000001'O, '000000'O)); |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | control { |
| 211 | execute( TC_cr_cc() ); |
Pau Espin Pedrol | f7ba234 | 2020-01-20 20:19:47 +0100 | [diff] [blame^] | 212 | execute( TC_udt_without_cr_cc() ); |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 213 | execute( TC_tiar_timeout() ); |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | |
| 217 | } |