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 | |
Pau Espin Pedrol | 392eaf3 | 2020-01-21 12:21:05 +0100 | [diff] [blame] | 42 | var OCT3 g_own_lref := '000001'O |
| 43 | |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 44 | /*Configure T(tias) over VTY, seconds */ |
| 45 | var integer g_demo_sccp_timer_ias := 7 * 60; |
| 46 | /*Configure T(tiar) over VTY, seconds */ |
| 47 | var integer g_demo_sccp_timer_iar := 15 * 60; |
| 48 | } |
| 49 | |
| 50 | type record of charstring Commands; |
| 51 | private function f_cs7_inst_0_cfg(TELNETasp_PT pt, Commands cmds := {}) |
| 52 | { |
| 53 | f_vty_enter_cfg_cs7_inst(pt, 0); |
| 54 | for (var integer i := 0; i < sizeof(cmds); i := i+1) { |
| 55 | f_vty_transceive(pt, cmds[i]); |
| 56 | } |
| 57 | f_vty_transceive(pt, "end"); |
| 58 | } |
| 59 | |
| 60 | function f_init_vty() runs on SCCP_Test_RAW_CT { |
| 61 | if (SCCP_DEMO_USER_VTY.checkstate("Mapped")) { |
| 62 | /* skip initialization if already executed once */ |
| 63 | return; |
| 64 | } |
| 65 | map(self:SCCP_DEMO_USER_VTY, system:SCCP_DEMO_USER_VTY); |
| 66 | f_vty_set_prompts(SCCP_DEMO_USER_VTY); |
| 67 | f_vty_transceive(SCCP_DEMO_USER_VTY, "enable"); |
| 68 | f_cs7_inst_0_cfg(SCCP_DEMO_USER_VTY, {"sccp-timer ias " & int2str(g_demo_sccp_timer_ias), |
| 69 | "sccp-timer iar " & int2str(g_demo_sccp_timer_iar)}); |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 70 | } |
| 71 | |
Pau Espin Pedrol | 2748679 | 2023-10-30 18:13:20 +0100 | [diff] [blame] | 72 | function f_vty_cmd_connect_req(integer conn_id) runs on SCCP_Test_RAW_CT { |
| 73 | f_vty_transceive(SCCP_DEMO_USER_VTY, "sccp-user"); |
| 74 | f_vty_transceive(SCCP_DEMO_USER_VTY, "connect-req " & int2str(conn_id)); |
| 75 | f_vty_transceive(SCCP_DEMO_USER_VTY, "end"); |
| 76 | } |
| 77 | |
| 78 | function f_vty_cmd_disconnect_req(integer conn_id) runs on SCCP_Test_RAW_CT { |
| 79 | f_vty_transceive(SCCP_DEMO_USER_VTY, "sccp-user"); |
| 80 | f_vty_transceive(SCCP_DEMO_USER_VTY, "disconnect-req " & int2str(conn_id)); |
| 81 | f_vty_transceive(SCCP_DEMO_USER_VTY, "end"); |
| 82 | } |
| 83 | |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 84 | private function f_init_raw(SCCP_Configuration cfg) runs on SCCP_Test_RAW_CT { |
| 85 | g_param := { |
| 86 | sio := { |
| 87 | ni := substr(oct2bit(cfg.sio),0,2), |
| 88 | prio := substr(oct2bit(cfg.sio),2,2), |
| 89 | si := substr(oct2bit(cfg.sio),4,4) |
| 90 | }, |
| 91 | opc := cfg.own_pc, |
| 92 | dpc := cfg.peer_pc, |
| 93 | sls := 0, |
| 94 | sccp_serviceType := cfg.sccp_service_type, |
| 95 | ssn := cfg.own_ssn |
| 96 | }; |
| 97 | |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 98 | f_init_vty(); |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 99 | |
| 100 | /* Create and connect test components */ |
| 101 | vc_M3UA := M3UA_CT.create; |
| 102 | connect(self:MTP3, vc_M3UA:MTP3_SP_PORT); |
| 103 | map(vc_M3UA:SCTP_PORT, system:sctp); |
| 104 | |
| 105 | vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr)); |
| 106 | } |
| 107 | |
| 108 | private function f_cleanup() runs on SCCP_Test_RAW_CT { |
| 109 | all component.stop; |
| 110 | unmap(vc_M3UA:SCTP_PORT, system:sctp); |
| 111 | disconnect(vc_M3UA:MTP3_SP_PORT, self:MTP3); |
| 112 | self.stop |
| 113 | } |
| 114 | |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 115 | private function f_send_sccp(template PDU_SCCP sccp) runs on SCCP_Test_RAW_CT { |
| 116 | var SCCP_MTP3_TRANSFERreq tx := { |
| 117 | sio := g_param.sio, |
| 118 | opc := g_param.opc, |
| 119 | dpc := g_param.dpc, |
| 120 | sls := g_param.sls, |
| 121 | data := valueof(sccp) |
| 122 | }; |
| 123 | MTP3.send(tx); |
| 124 | } |
| 125 | |
Pau Espin Pedrol | e30d543 | 2020-01-21 13:47:32 +0100 | [diff] [blame] | 126 | private function tr_SCCP_MTP3_TRANSFERind(template PDU_SCCP sccp) |
| 127 | runs on SCCP_Test_RAW_CT return template SCCP_MTP3_TRANSFERind { |
Pau Espin Pedrol | 392eaf3 | 2020-01-21 12:21:05 +0100 | [diff] [blame] | 128 | |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 129 | var template SCCP_MTP3_TRANSFERind exp := { |
| 130 | sio := g_param.sio, |
| 131 | opc := g_param.dpc, |
| 132 | dpc := g_param.opc, |
| 133 | sls := g_param.sls, |
| 134 | data := sccp |
| 135 | }; |
Pau Espin Pedrol | e30d543 | 2020-01-21 13:47:32 +0100 | [diff] [blame] | 136 | return exp; |
| 137 | } |
| 138 | |
| 139 | private function f_exp_sccp(template PDU_SCCP sccp) |
| 140 | runs on SCCP_Test_RAW_CT return SCCP_MTP3_TRANSFERind { |
| 141 | var template SCCP_MTP3_TRANSFERind exp := tr_SCCP_MTP3_TRANSFERind(sccp); |
| 142 | var SCCP_MTP3_TRANSFERind rx; |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 143 | timer T := 10.0; |
| 144 | T.start; |
| 145 | alt { |
| 146 | [] MTP3.receive(exp) -> value rx { |
Pau Espin Pedrol | 392eaf3 | 2020-01-21 12:21:05 +0100 | [diff] [blame] | 147 | return rx; |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 148 | } |
| 149 | [] MTP3.receive { |
| 150 | setverdict(fail, "Unexpected MTP/SCCP received"); |
Pau Espin Pedrol | 94b7a68 | 2020-01-20 19:30:07 +0100 | [diff] [blame] | 151 | self.stop |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 152 | } |
| 153 | [] T.timeout { |
| 154 | setverdict(fail, "Timeout waiting for ", exp); |
Pau Espin Pedrol | 94b7a68 | 2020-01-20 19:30:07 +0100 | [diff] [blame] | 155 | self.stop |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 156 | } |
| 157 | } |
Pau Espin Pedrol | 392eaf3 | 2020-01-21 12:21:05 +0100 | [diff] [blame] | 158 | return rx; |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 159 | } |
| 160 | |
Pau Espin Pedrol | 392eaf3 | 2020-01-21 12:21:05 +0100 | [diff] [blame] | 161 | private function f_establish_conn(SCCP_PAR_Address calling, SCCP_PAR_Address called) |
| 162 | runs on SCCP_Test_RAW_CT return OCT3 { |
| 163 | var SCCP_MTP3_TRANSFERind mtp3_rx; |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 164 | |
Pau Espin Pedrol | 392eaf3 | 2020-01-21 12:21:05 +0100 | [diff] [blame] | 165 | f_send_sccp(ts_SCCP_CR(g_own_lref, calling, called)); |
| 166 | mtp3_rx := f_exp_sccp(tr_SCCP_CC(?, g_own_lref)); |
| 167 | |
| 168 | return mtp3_rx.data.connconfirm.sourceLocRef; |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | private function f_tx_udt_exp(SCCP_PAR_Address calling, SCCP_PAR_Address called, octetstring data) runs on SCCP_Test_RAW_CT { |
| 172 | |
| 173 | f_send_sccp(ts_SCCP_UDT(calling, called, data)); |
| 174 | f_exp_sccp(tr_SCCP_UDT(called, calling, data)); |
| 175 | } |
| 176 | |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 177 | /* Verify sccp_demo_user answers a CR with a CC for PC and SSN set up to echo back */ |
| 178 | testcase TC_cr_cc() runs on SCCP_Test_RAW_CT { |
| 179 | var SCCP_PAR_Address calling, called; |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 180 | |
| 181 | f_init_raw(mp_sccp_cfg[0]); |
| 182 | f_sleep(1.0); |
| 183 | |
Pau Espin Pedrol | e187091 | 2020-01-17 17:30:19 +0100 | [diff] [blame] | 184 | called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn, |
| 185 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 186 | calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn, |
| 187 | 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] | 188 | f_establish_conn(calling, called); |
Pau Espin Pedrol | 392eaf3 | 2020-01-21 12:21:05 +0100 | [diff] [blame] | 189 | setverdict(pass); |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 190 | } |
| 191 | |
Pau Espin Pedrol | 1269b1b | 2020-01-21 12:58:48 +0100 | [diff] [blame] | 192 | /* Verify sccp_demo_user inactivty timers are not armed upon dealing with |
Alexander Couzens | 3b2b32e | 2022-11-22 12:55:05 +0000 | [diff] [blame] | 193 | * connectionless data-unit messages. Since no connection exists. */ |
Pau Espin Pedrol | f7ba234 | 2020-01-20 20:19:47 +0100 | [diff] [blame] | 194 | testcase TC_udt_without_cr_cc() runs on SCCP_Test_RAW_CT { |
| 195 | var SCCP_PAR_Address calling, called; |
Pau Espin Pedrol | 1269b1b | 2020-01-21 12:58:48 +0100 | [diff] [blame] | 196 | var SCCP_MTP3_TRANSFERind rx; |
Harald Welte | 67881ae | 2022-04-12 22:52:47 +0200 | [diff] [blame] | 197 | var octetstring data := f_rnd_octstring_rnd_len(100); |
Pau Espin Pedrol | f7ba234 | 2020-01-20 20:19:47 +0100 | [diff] [blame] | 198 | |
Pau Espin Pedrol | 1269b1b | 2020-01-21 12:58:48 +0100 | [diff] [blame] | 199 | /* Keep recommended ratio of T(iar) >= T(ias)*2, but anyway no IT |
| 200 | should be received in this case. */ |
| 201 | g_demo_sccp_timer_ias := 1; |
| 202 | g_demo_sccp_timer_iar := 3; |
Pau Espin Pedrol | f7ba234 | 2020-01-20 20:19:47 +0100 | [diff] [blame] | 203 | f_init_raw(mp_sccp_cfg[0]); |
| 204 | f_sleep(1.0); |
| 205 | |
| 206 | called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn, |
| 207 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 208 | calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn, |
| 209 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 210 | |
| 211 | f_tx_udt_exp(calling, called, data); |
Pau Espin Pedrol | 1269b1b | 2020-01-21 12:58:48 +0100 | [diff] [blame] | 212 | |
| 213 | /* Make sure no SCCP message is received at all, since no connection is active. */ |
| 214 | timer T := int2float(g_demo_sccp_timer_iar + 1); |
| 215 | T.start; |
| 216 | alt { |
| 217 | [] MTP3.receive { |
| 218 | setverdict(fail, "Unexpected MTP/SCCP received"); |
| 219 | self.stop; |
| 220 | } |
| 221 | [] T.timeout {} |
| 222 | } |
Pau Espin Pedrol | 392eaf3 | 2020-01-21 12:21:05 +0100 | [diff] [blame] | 223 | setverdict(pass); |
Pau Espin Pedrol | f7ba234 | 2020-01-20 20:19:47 +0100 | [diff] [blame] | 224 | } |
| 225 | |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 226 | /* Verify T(iar) triggers and releases the channel */ |
| 227 | testcase TC_tiar_timeout() runs on SCCP_Test_RAW_CT { |
| 228 | var SCCP_PAR_Address calling, called; |
Pau Espin Pedrol | 392eaf3 | 2020-01-21 12:21:05 +0100 | [diff] [blame] | 229 | var OCT3 remote_lref; |
Harald Welte | 67881ae | 2022-04-12 22:52:47 +0200 | [diff] [blame] | 230 | var octetstring data := f_rnd_octstring_rnd_len(100); |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 231 | |
| 232 | /* Set T(iar) in sccp_demo_user low enough that it will trigger before other side |
| 233 | has time to keep alive with a T(ias). Keep recommended ratio of |
| 234 | T(iar) >= T(ias)*2 */ |
| 235 | g_demo_sccp_timer_ias := 2; |
| 236 | g_demo_sccp_timer_iar := 5; |
Pau Espin Pedrol | e187091 | 2020-01-17 17:30:19 +0100 | [diff] [blame] | 237 | f_init_raw(mp_sccp_cfg[0]); |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 238 | f_sleep(1.0); |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 239 | |
| 240 | called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn, |
| 241 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 242 | calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn, |
| 243 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
Pau Espin Pedrol | 392eaf3 | 2020-01-21 12:21:05 +0100 | [diff] [blame] | 244 | remote_lref := f_establish_conn(calling, called); |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 245 | f_tx_udt_exp(calling, called, data); |
| 246 | |
| 247 | log("Waiting for first IT"); |
Pau Espin Pedrol | 392eaf3 | 2020-01-21 12:21:05 +0100 | [diff] [blame] | 248 | f_exp_sccp(tr_SCCP_IT(remote_lref, g_own_lref)); |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 249 | log("Waiting for second IT"); |
Pau Espin Pedrol | 392eaf3 | 2020-01-21 12:21:05 +0100 | [diff] [blame] | 250 | f_exp_sccp(tr_SCCP_IT(remote_lref, g_own_lref)); |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 251 | |
| 252 | log("Waiting for RLSD"); |
Pau Espin Pedrol | 392eaf3 | 2020-01-21 12:21:05 +0100 | [diff] [blame] | 253 | f_exp_sccp(tr_SCCP_RLSD(remote_lref, g_own_lref, hex2int('0D'H))); /* Cause: Expiration of Rx Inactivity Timer */ |
| 254 | f_send_sccp(ts_SCCP_RLC(g_own_lref, remote_lref)); |
| 255 | setverdict(pass); |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 256 | } |
| 257 | |
Pau Espin Pedrol | e30d543 | 2020-01-21 13:47:32 +0100 | [diff] [blame] | 258 | /* Verify T(iar) triggers and releases the channel */ |
| 259 | testcase TC_it_avoids_tiar() runs on SCCP_Test_RAW_CT { |
| 260 | var SCCP_PAR_Address calling, called; |
| 261 | var OCT3 remote_lref; |
| 262 | var boolean it_received := false; |
Alexander Couzens | 9e8e96f | 2022-11-22 15:52:18 +0000 | [diff] [blame] | 263 | var SCCP_MTP3_TRANSFERind rx; |
Pau Espin Pedrol | e30d543 | 2020-01-21 13:47:32 +0100 | [diff] [blame] | 264 | |
| 265 | g_demo_sccp_timer_ias := 1; |
| 266 | g_demo_sccp_timer_iar := 3; |
| 267 | f_init_raw(mp_sccp_cfg[0]); |
| 268 | f_sleep(1.0); |
| 269 | |
| 270 | called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn, |
| 271 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 272 | calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn, |
| 273 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 274 | remote_lref := f_establish_conn(calling, called); |
| 275 | |
| 276 | timer T_total := 7.0; /* Higher than g_demo_sccp_timer_iar */ |
| 277 | timer T_tias := 1.0; /* Lower than g_demo_sccp_timer_iar */ |
| 278 | T_total.start; |
| 279 | T_tias.start; |
| 280 | alt { |
| 281 | [] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(tr_SCCP_IT(remote_lref, g_own_lref))) { |
| 282 | it_received := true; |
| 283 | repeat; |
| 284 | } |
| 285 | [] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(tr_SCCP_RLSD(remote_lref, g_own_lref, hex2int('0D'H)))) { |
| 286 | setverdict(fail, "Unexpected SCCP RLSD received"); |
| 287 | self.stop; |
| 288 | } |
Alexander Couzens | 9e8e96f | 2022-11-22 15:52:18 +0000 | [diff] [blame] | 289 | [] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(*)) -> value rx { |
| 290 | setverdict(fail, "Unexpected MTP/SCCP TRANSFERind received: ", rx); |
| 291 | self.stop; |
| 292 | } |
Pau Espin Pedrol | e30d543 | 2020-01-21 13:47:32 +0100 | [diff] [blame] | 293 | [] MTP3.receive { |
| 294 | setverdict(fail, "Unexpected MTP/SCCP received"); |
| 295 | self.stop; |
| 296 | } |
| 297 | [] T_tias.timeout { |
| 298 | f_send_sccp(ts_SCCP_IT(g_own_lref, remote_lref)); |
| 299 | T_tias.start; |
| 300 | repeat; |
| 301 | } |
| 302 | [] T_total.timeout { |
| 303 | /* We kept the connection alive only with IT messages for a while, cool! */ |
| 304 | T_tias.stop; |
| 305 | setverdict(pass); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | if (not it_received) { |
| 310 | setverdict(fail, "Didn't receive any IT (Tias) from peer"); |
| 311 | } |
| 312 | |
| 313 | /* After we stop sending IT, we should be receiving an RLSD triggered from T(iar) */ |
| 314 | log("Waiting for RLSD"); |
| 315 | alt { |
| 316 | [] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(tr_SCCP_IT(remote_lref, g_own_lref))) { |
| 317 | repeat; |
| 318 | } |
| 319 | [] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(tr_SCCP_RLSD(remote_lref, g_own_lref, hex2int('0D'H)))) { |
| 320 | f_send_sccp(ts_SCCP_RLC(g_own_lref, remote_lref)); |
| 321 | setverdict(pass); |
| 322 | } |
| 323 | [] MTP3.receive { |
| 324 | setverdict(fail, "Unexpected MTP/SCCP received"); |
| 325 | self.stop; |
| 326 | } |
| 327 | } |
| 328 | } |
| 329 | |
Harald Welte | 4038d4c | 2021-10-26 14:37:54 +0200 | [diff] [blame] | 330 | private function f_tx_xudt_exp(SCCP_PAR_Address calling, SCCP_PAR_Address called, octetstring data) runs on SCCP_Test_RAW_CT { |
| 331 | var template PDU_SCCP exp_rx; |
| 332 | f_send_sccp(ts_SCCP_XUDT(calling, called, data)); |
| 333 | exp_rx := (tr_SCCP_UDT(called, calling, data), tr_SCCP_XUDT(called, calling, data)); |
| 334 | f_exp_sccp(exp_rx); |
| 335 | } |
| 336 | |
| 337 | /* Test if the IUT SCCP code processes an XUDT [treat it like UDT] and answers back. */ |
| 338 | testcase TC_process_rx_xudt() runs on SCCP_Test_RAW_CT { |
| 339 | var SCCP_PAR_Address calling, called; |
Harald Welte | 67881ae | 2022-04-12 22:52:47 +0200 | [diff] [blame] | 340 | var octetstring data := f_rnd_octstring_rnd_len(100); |
Harald Welte | 4038d4c | 2021-10-26 14:37:54 +0200 | [diff] [blame] | 341 | |
| 342 | f_init_raw(mp_sccp_cfg[0]); |
| 343 | f_sleep(1.0); |
| 344 | |
| 345 | called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn, |
| 346 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 347 | calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn, |
| 348 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 349 | |
| 350 | /* Make sure an XUDT is echoed back just like an UDT */ |
| 351 | f_tx_xudt_exp(calling, called, data); |
| 352 | setverdict(pass); |
| 353 | } |
| 354 | |
Pau Espin Pedrol | 0c613ab | 2023-09-19 14:39:34 +0200 | [diff] [blame] | 355 | private function f_tx_ludt_exp(SCCP_PAR_Address calling, SCCP_PAR_Address called, octetstring data) runs on SCCP_Test_RAW_CT { |
| 356 | var template PDU_SCCP exp_rx; |
| 357 | f_send_sccp(ts_SCCP_LUDT(calling, called, data)); |
| 358 | exp_rx := tr_SCCP_LUDT(called, calling, data); |
| 359 | f_exp_sccp(exp_rx); |
| 360 | } |
| 361 | |
| 362 | /* Test if the IUT SCCP code processes a LUDT [treat it like UDT] and answers back. */ |
| 363 | testcase TC_process_rx_ludt() runs on SCCP_Test_RAW_CT { |
| 364 | var SCCP_PAR_Address calling, called; |
| 365 | var octetstring data := f_rnd_octstring(1000); |
| 366 | |
| 367 | f_init_raw(mp_sccp_cfg[0]); |
| 368 | f_sleep(1.0); |
| 369 | |
| 370 | called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, mp_sccp_cfg[0].peer_ssn, |
| 371 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 372 | calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, mp_sccp_cfg[0].own_ssn, |
| 373 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 374 | |
| 375 | /* Make sure an LUDT is echoed back just like an UDT */ |
| 376 | f_tx_ludt_exp(calling, called, data); |
| 377 | setverdict(pass); |
| 378 | } |
| 379 | |
Harald Welte | 24f921b | 2021-02-10 19:37:45 +0100 | [diff] [blame] | 380 | function f_scmg_xceive(SCCP_PAR_Address calling, SCCP_PAR_Address called, |
| 381 | template (value) PDU_SCMG_message tx, |
Harald Welte | aed9f94 | 2021-05-13 21:54:58 +0200 | [diff] [blame] | 382 | template (omit) PDU_SCMG_message rx_exp, |
| 383 | boolean accept_other_called_resp := false) runs on SCCP_Test_RAW_CT |
Harald Welte | 24f921b | 2021-02-10 19:37:45 +0100 | [diff] [blame] | 384 | { |
| 385 | var boolean exp_something := true; |
Alexander Couzens | 9e8e96f | 2022-11-22 15:52:18 +0000 | [diff] [blame] | 386 | var SCCP_MTP3_TRANSFERind rx; |
Harald Welte | 24f921b | 2021-02-10 19:37:45 +0100 | [diff] [blame] | 387 | timer T := 5.0; |
| 388 | |
| 389 | if (istemplatekind(rx_exp, "omit")) { |
| 390 | exp_something := false; |
| 391 | } |
| 392 | |
| 393 | MTP3.clear; |
| 394 | f_send_sccp(ts_SCCP_UDT(calling, called, enc_PDU_SCMG_message(valueof(tx)))); |
| 395 | T.start; |
| 396 | alt { |
| 397 | [exp_something] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(tr_SCCP_UDT(called, calling, decmatch rx_exp))) { |
| 398 | setverdict(pass); |
| 399 | } |
Harald Welte | aed9f94 | 2021-05-13 21:54:58 +0200 | [diff] [blame] | 400 | [exp_something and accept_other_called_resp] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(tr_SCCP_UDT(called, ?, decmatch rx_exp))) { |
| 401 | setverdict(pass); |
| 402 | } |
Alexander Couzens | 9e8e96f | 2022-11-22 15:52:18 +0000 | [diff] [blame] | 403 | [] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(tr_SCCP_UDT(called, calling, ?))) -> value rx { |
| 404 | setverdict(fail, "Received unexpected SCCP/MTP3 TRANSFERind (specific): ", rx, " but waiting for (specific) ", rx_exp); |
| 405 | } |
| 406 | [] MTP3.receive(tr_SCCP_MTP3_TRANSFERind(*)) -> value rx { |
| 407 | setverdict(fail, "Received unexpected SCCP/MTP3 TRANSFERind (*): ", rx, " but waiting for ", rx_exp); |
Harald Welte | 24f921b | 2021-02-10 19:37:45 +0100 | [diff] [blame] | 408 | } |
| 409 | [] MTP3.receive { |
| 410 | setverdict(fail, "Received unexpected waiting for ", rx_exp); |
| 411 | } |
| 412 | [exp_something] T.timeout { |
| 413 | setverdict(fail, "Timeout waiting for ", rx_exp); |
| 414 | } |
| 415 | [not exp_something] T.timeout { |
| 416 | setverdict(pass); |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | } |
| 421 | |
| 422 | /* Test is SST(SSN=1) returns SSA */ |
| 423 | testcase TC_scmg_sst_ssn1() runs on SCCP_Test_RAW_CT { |
| 424 | var SCCP_PAR_Address calling, called; |
| 425 | var template (value) PDU_SCMG_message tx; |
| 426 | var template (present) PDU_SCMG_message rx_exp; |
| 427 | |
| 428 | f_init_raw(mp_sccp_cfg[0]); |
| 429 | f_sleep(1.0); |
| 430 | |
| 431 | called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, 1, |
| 432 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 433 | calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, 1, |
| 434 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 435 | |
| 436 | tx := ts_SCMG_SST(1, mp_sccp_cfg[0].peer_pc); |
| 437 | rx_exp := ts_SCMG_SSA(1, mp_sccp_cfg[0].peer_pc); |
| 438 | f_scmg_xceive(calling, called, tx, rx_exp); |
| 439 | } |
| 440 | |
| 441 | /* Test is SST(SSN=valid) returns SSA */ |
| 442 | testcase TC_scmg_sst_ssn_valid() runs on SCCP_Test_RAW_CT { |
| 443 | var SCCP_PAR_Address calling, called; |
| 444 | var template (value) PDU_SCMG_message tx; |
| 445 | var template (present) PDU_SCMG_message rx_exp; |
| 446 | |
| 447 | f_init_raw(mp_sccp_cfg[0]); |
| 448 | f_sleep(1.0); |
| 449 | |
| 450 | called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, 1, |
| 451 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 452 | calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, 1, |
| 453 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 454 | |
| 455 | tx := ts_SCMG_SST(mp_sccp_cfg[0].peer_ssn, mp_sccp_cfg[0].peer_pc); |
| 456 | rx_exp := ts_SCMG_SSA(mp_sccp_cfg[0].peer_ssn, mp_sccp_cfg[0].peer_pc); |
| 457 | f_scmg_xceive(calling, called, tx, rx_exp); |
| 458 | } |
| 459 | |
| 460 | |
| 461 | /* Test is SST(SSN=invalid) returns nothing */ |
| 462 | testcase TC_scmg_sst_ssn_invalid() runs on SCCP_Test_RAW_CT { |
| 463 | var SCCP_PAR_Address calling, called; |
| 464 | var template (value) PDU_SCMG_message tx; |
| 465 | var template (omit) PDU_SCMG_message rx_exp; |
| 466 | |
| 467 | f_init_raw(mp_sccp_cfg[0]); |
| 468 | f_sleep(1.0); |
| 469 | |
| 470 | called := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].peer_pc, 1, |
| 471 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 472 | calling := valueof(ts_SccpAddr_PC_SSN(mp_sccp_cfg[0].own_pc, 1, |
| 473 | mp_sccp_cfg[0].sio, mp_sccp_cfg[0].sccp_service_type)); |
| 474 | |
| 475 | tx := ts_SCMG_SST(123, mp_sccp_cfg[0].peer_pc); |
| 476 | rx_exp := omit; |
| 477 | f_scmg_xceive(calling, called, tx, rx_exp); |
| 478 | } |
| 479 | |
Harald Welte | aed9f94 | 2021-05-13 21:54:58 +0200 | [diff] [blame] | 480 | /* Test CallingParty(only SSN) solicits response (OS#5146) */ |
| 481 | testcase TC_callingparty_ssn_only() runs on SCCP_Test_RAW_CT { |
| 482 | var SCCP_PAR_Address calling, called; |
| 483 | var template (value) PDU_SCMG_message tx; |
| 484 | var template (present) PDU_SCMG_message rx_exp; |
| 485 | |
| 486 | f_init_raw(mp_sccp_cfg[0]); |
| 487 | f_sleep(1.0); |
| 488 | |
| 489 | called := valueof(ts_SccpAddr_SSN(1)); |
| 490 | calling := valueof(ts_SccpAddr_SSN(1)); |
| 491 | |
| 492 | tx := ts_SCMG_SST(1, mp_sccp_cfg[0].peer_pc); |
| 493 | rx_exp := ts_SCMG_SSA(1, mp_sccp_cfg[0].peer_pc); |
| 494 | f_scmg_xceive(calling, called, tx, rx_exp, accept_other_called_resp:=true); |
| 495 | } |
Harald Welte | 24f921b | 2021-02-10 19:37:45 +0100 | [diff] [blame] | 496 | |
| 497 | |
Pau Espin Pedrol | 2748679 | 2023-10-30 18:13:20 +0100 | [diff] [blame] | 498 | /* Test user initiating a conn (eg RUA), which triggers SCCP CR. While waiting |
| 499 | * for CC, user decides it timed out (eg. RUA side timeout) which makes it move to |
| 500 | * WAIT_CONN_CONF state. In that state, wait for CC and then submit an RLSD and |
| 501 | * wait for ack. */ |
| 502 | testcase TC_cr_timeout_cc_too_late() runs on SCCP_Test_RAW_CT { |
| 503 | var SCCP_MTP3_TRANSFERind mtp3_rx; |
| 504 | var integer conn_id := 1234; |
| 505 | var OCT3 remote_lref; |
| 506 | |
| 507 | f_init_raw(mp_sccp_cfg[0]); |
| 508 | f_sleep(1.0); |
| 509 | |
| 510 | f_vty_cmd_connect_req(conn_id); |
| 511 | mtp3_rx := f_exp_sccp(tr_SCCP_CR(?, ?, ?)); |
| 512 | |
| 513 | /* Emulate disconnection from the user: */ |
| 514 | f_vty_cmd_disconnect_req(conn_id); |
| 515 | remote_lref := mtp3_rx.data.connrequest.sourceLocRef; |
| 516 | |
| 517 | /* Now send CC, user should send RLSD to us: */ |
| 518 | f_send_sccp(ts_SCCP_CC(g_own_lref, remote_lref)); |
| 519 | log("Waiting for RLSD"); |
| 520 | /* Cause set hardcoded by osmo_sccp_demo_user VTY code, nothing to test here: */ |
| 521 | var template (present) integer cause := ?; |
| 522 | f_exp_sccp(tr_SCCP_RLSD(remote_lref, g_own_lref, cause)); |
| 523 | f_send_sccp(ts_SCCP_RLC(g_own_lref, remote_lref)); |
| 524 | |
| 525 | setverdict(pass); |
| 526 | } |
| 527 | |
| 528 | |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 529 | control { |
| 530 | execute( TC_cr_cc() ); |
Pau Espin Pedrol | f7ba234 | 2020-01-20 20:19:47 +0100 | [diff] [blame] | 531 | execute( TC_udt_without_cr_cc() ); |
Pau Espin Pedrol | a2473da | 2020-01-20 13:20:58 +0100 | [diff] [blame] | 532 | execute( TC_tiar_timeout() ); |
Pau Espin Pedrol | e30d543 | 2020-01-21 13:47:32 +0100 | [diff] [blame] | 533 | execute( TC_it_avoids_tiar() ); |
Harald Welte | 4038d4c | 2021-10-26 14:37:54 +0200 | [diff] [blame] | 534 | execute( TC_process_rx_xudt() ); |
Pau Espin Pedrol | 0c613ab | 2023-09-19 14:39:34 +0200 | [diff] [blame] | 535 | execute( TC_process_rx_ludt() ); |
Harald Welte | 24f921b | 2021-02-10 19:37:45 +0100 | [diff] [blame] | 536 | |
| 537 | execute( TC_scmg_sst_ssn1() ); |
| 538 | execute( TC_scmg_sst_ssn_valid() ); |
| 539 | execute( TC_scmg_sst_ssn_invalid() ); |
Harald Welte | aed9f94 | 2021-05-13 21:54:58 +0200 | [diff] [blame] | 540 | |
| 541 | execute( TC_callingparty_ssn_only() ); |
Pau Espin Pedrol | 2748679 | 2023-10-30 18:13:20 +0100 | [diff] [blame] | 542 | execute( TC_cr_timeout_cc_too_late() ); |
Harald Welte | 9adf57b | 2020-01-10 12:33:44 +0100 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | |
| 546 | } |