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; |
| 41 | } |
| 42 | |
| 43 | private function f_init_raw(SCCP_Configuration cfg) runs on SCCP_Test_RAW_CT { |
| 44 | g_param := { |
| 45 | sio := { |
| 46 | ni := substr(oct2bit(cfg.sio),0,2), |
| 47 | prio := substr(oct2bit(cfg.sio),2,2), |
| 48 | si := substr(oct2bit(cfg.sio),4,4) |
| 49 | }, |
| 50 | opc := cfg.own_pc, |
| 51 | dpc := cfg.peer_pc, |
| 52 | sls := 0, |
| 53 | sccp_serviceType := cfg.sccp_service_type, |
| 54 | ssn := cfg.own_ssn |
| 55 | }; |
| 56 | |
| 57 | map(self:SCCP_DEMO_USER_VTY, system:SCCP_DEMO_USER_VTY); |
| 58 | f_vty_set_prompts(SCCP_DEMO_USER_VTY); |
| 59 | f_vty_transceive(SCCP_DEMO_USER_VTY, "enable"); |
| 60 | |
| 61 | /* Create and connect test components */ |
| 62 | vc_M3UA := M3UA_CT.create; |
| 63 | connect(self:MTP3, vc_M3UA:MTP3_SP_PORT); |
| 64 | map(vc_M3UA:SCTP_PORT, system:sctp); |
| 65 | |
| 66 | vc_M3UA.start(f_M3UA_Emulation(cfg.sctp_addr)); |
| 67 | } |
| 68 | |
| 69 | private function f_cleanup() runs on SCCP_Test_RAW_CT { |
| 70 | all component.stop; |
| 71 | unmap(vc_M3UA:SCTP_PORT, system:sctp); |
| 72 | disconnect(vc_M3UA:MTP3_SP_PORT, self:MTP3); |
| 73 | self.stop |
| 74 | } |
| 75 | |
| 76 | /* connection oriented SCCP */ |
| 77 | const SCCP_param_ProtocolClass c_class2 := { class:='0010'B, messageHandling:='0000'B };//class 2 |
| 78 | |
| 79 | function ts_SCCP_CR(OCT3 source_lref, SCCP_PAR_Address calling, SCCP_PAR_Address called) |
| 80 | return template (value) PDU_SCCP { |
| 81 | var SCCP_param_CPartyAddressEnc calling_enc := ConvertASPAddressToEncodedAddress_itu(calling); |
| 82 | |
| 83 | var template (value) PDU_SCCP ret := { |
| 84 | connrequest := { |
| 85 | messageType := cr, |
| 86 | sourceLocRef := source_lref, |
| 87 | protClass := c_class2, |
| 88 | pointer1 := 2, |
| 89 | pointer2 := 0, /* overwritten */ |
| 90 | calledPAddress := ConvertASPAddressToEncodedAddress_itu(called), |
| 91 | optionalPart := { |
| 92 | credit := omit, |
| 93 | callingPAddress := { |
| 94 | paramName := con_SCCP_cgPA, |
| 95 | paramLength := calling_enc.paramLength, /* overwritten */ |
| 96 | addr := calling_enc.addr |
| 97 | }, |
| 98 | data := omit, |
| 99 | hopCounter := omit, |
| 100 | importance := omit |
| 101 | }, |
| 102 | eop := { paramName:= con_SCCP_eop } |
| 103 | } |
| 104 | } |
| 105 | return ret; |
| 106 | } |
| 107 | |
| 108 | template (present) PDU_SCCP tr_SCCP_CC(template (present) OCT3 dest_lref, |
| 109 | template (present) OCT3 source_lref) := { |
| 110 | connconfirm := { |
| 111 | messageType := cc, |
| 112 | destLocRef := dest_lref, |
| 113 | sourceLocRef := source_lref, |
| 114 | protClass := c_class2, |
| 115 | pointer1 := ?, |
| 116 | optionalPart := *, |
| 117 | eop := * |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | private function f_send_sccp(template PDU_SCCP sccp) runs on SCCP_Test_RAW_CT { |
| 122 | var SCCP_MTP3_TRANSFERreq tx := { |
| 123 | sio := g_param.sio, |
| 124 | opc := g_param.opc, |
| 125 | dpc := g_param.dpc, |
| 126 | sls := g_param.sls, |
| 127 | data := valueof(sccp) |
| 128 | }; |
| 129 | MTP3.send(tx); |
| 130 | } |
| 131 | |
| 132 | private function f_exp_sccp(template PDU_SCCP sccp) runs on SCCP_Test_RAW_CT { |
| 133 | var SCCP_MTP3_TRANSFERind rx; |
| 134 | var template SCCP_MTP3_TRANSFERind exp := { |
| 135 | sio := g_param.sio, |
| 136 | opc := g_param.dpc, |
| 137 | dpc := g_param.opc, |
| 138 | sls := g_param.sls, |
| 139 | data := sccp |
| 140 | }; |
| 141 | timer T := 10.0; |
| 142 | T.start; |
| 143 | alt { |
| 144 | [] MTP3.receive(exp) -> value rx { |
| 145 | setverdict(pass); |
| 146 | } |
| 147 | [] MTP3.receive { |
| 148 | setverdict(fail, "Unexpected MTP/SCCP received"); |
| 149 | } |
| 150 | [] T.timeout { |
| 151 | setverdict(fail, "Timeout waiting for ", exp); |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | /* Verify sccp_demo_user answers a CR with a CC for PC and SSN set up to echo back */ |
| 157 | testcase TC_cr_cc() runs on SCCP_Test_RAW_CT { |
| 158 | var SCCP_PAR_Address calling, called; |
| 159 | called := valueof(ts_SccpAddr_PC_SSN(sccp_cfg[0].peer_pc, sccp_cfg[0].peer_ssn, |
| 160 | sccp_cfg[0].sio, sccp_cfg[0].sccp_service_type)); |
| 161 | calling := valueof(ts_SccpAddr_PC_SSN(sccp_cfg[0].own_pc, sccp_cfg[0].own_ssn, |
| 162 | sccp_cfg[0].sio, sccp_cfg[0].sccp_service_type)); |
| 163 | f_init_raw(sccp_cfg[0]); |
| 164 | f_sleep(1.0); |
| 165 | f_send_sccp(ts_SCCP_CR('000001'O, calling, called)); |
| 166 | f_exp_sccp(tr_SCCP_CC('000001'O, ?)); |
| 167 | } |
| 168 | |
| 169 | control { |
| 170 | execute( TC_cr_cc() ); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | } |