Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 1 | module BSC_Tests { |
| 2 | |
| 3 | import from Osmocom_Types all; |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 4 | import from GSM_Types all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 5 | import from IPL4asp_Types all; |
| 6 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 7 | import from BSSAP_Adapter all; |
| 8 | import from BSSAP_CodecPort all; |
| 9 | import from BSSMAP_Templates all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 10 | import from IPA_Emulation all; |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 11 | import from IPA_Types all; |
| 12 | import from RSL_Types all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 13 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 14 | import from RSL_Tests all; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 15 | |
Harald Welte | 696ddb6 | 2017-12-08 14:01:43 +0100 | [diff] [blame] | 16 | const integer NUM_BTS := 1; |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 17 | const float T3101_MAX := 12.0; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 18 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 19 | type component test_CT extends BSSAP_Adapter_CT { |
| 20 | var IPA_Client bts[NUM_BTS]; |
| 21 | port IPA_RSL_PT IPA_RSL[NUM_BTS]; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 22 | |
| 23 | var boolean g_initialized := false; |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 24 | timer T_guard := 30.0; |
| 25 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | modulepar { |
Harald Welte | 696ddb6 | 2017-12-08 14:01:43 +0100 | [diff] [blame] | 29 | charstring mp_bsc_ip := "127.0.0.1"; |
| 30 | integer mp_bsc_rsl_port := 3003; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 31 | } |
| 32 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 33 | type record IPA_Client { |
| 34 | IPA_Emulation_CT vc_IPA, |
| 35 | IPA_CCM_Parameters ccm_pars, |
| 36 | charstring id |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 37 | } |
| 38 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 39 | function f_ipa_rsl_start(inout IPA_Client clnt, charstring bsc_host, PortNumber bsc_port, integer i) |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 40 | runs on test_CT { |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 41 | timer T := 10.0; |
| 42 | |
| 43 | clnt.id := "IPA" & int2str(i); |
| 44 | clnt.vc_IPA := IPA_Emulation_CT.create(clnt.id & "-IPA"); |
| 45 | clnt.ccm_pars := c_IPA_default_ccm_pars; |
| 46 | clnt.ccm_pars.name := "Osmocom TTCN-3 BTS Simulator"; |
| 47 | clnt.ccm_pars.unit_id := int2str(1234+i) & "/0/0"; |
| 48 | |
| 49 | map(clnt.vc_IPA:IPA_PORT, system:IPA_CODEC_PT); |
| 50 | connect(clnt.vc_IPA:IPA_RSL_PORT, self:IPA_RSL[i]); |
| 51 | |
| 52 | clnt.vc_IPA.start(IPA_Emulation.main_client(bsc_host, bsc_port, "", -1, clnt.ccm_pars)); |
| 53 | |
| 54 | /* wait for IPA RSL link to connect and send ID ACK */ |
| 55 | T.start; |
| 56 | alt { |
| 57 | [] IPA_RSL[i].receive(ASP_IPA_Event:{up_down := ASP_IPA_EVENT_ID_ACK}) { |
| 58 | T.stop; |
| 59 | IPA_RSL[i].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_PAGING_LOAD_IND(23))); |
| 60 | } |
| 61 | [] IPA_RSL[i].receive { repeat } |
| 62 | [] T.timeout { |
| 63 | setverdict(fail, "Timeout waiting for ASP_IPA_EVENT_ID_ACK"); |
| 64 | self.stop; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | function f_sleep(float seconds) { |
| 70 | timer T := seconds; |
| 71 | T.start; |
| 72 | T.timeout; |
| 73 | } |
| 74 | |
| 75 | altstep as_Tguard() runs on test_CT { |
| 76 | [] T_guard.timeout { setverdict(fail, "Timeout of T_guard"); } |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | function f_init() runs on test_CT { |
| 80 | var integer i; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 81 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 82 | if (g_initialized) { |
| 83 | return; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 84 | } |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 85 | g_initialized := true; |
| 86 | |
| 87 | /* Call a function of our 'parent component' BSSAP_Adapter_CT to start the |
| 88 | * MSC-side BSSAP emulation */ |
| 89 | f_bssap_init("VirtMSC"); |
| 90 | |
| 91 | f_sleep(5.0); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 92 | |
Harald Welte | 696ddb6 | 2017-12-08 14:01:43 +0100 | [diff] [blame] | 93 | for (i := 0; i < NUM_BTS; i := i+1) { |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 94 | f_ipa_rsl_start(bts[i], mp_bsc_ip, mp_bsc_rsl_port, i); |
Harald Welte | 696ddb6 | 2017-12-08 14:01:43 +0100 | [diff] [blame] | 95 | } |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 96 | f_sleep(0.5); |
Harald Welte | 696ddb6 | 2017-12-08 14:01:43 +0100 | [diff] [blame] | 97 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 98 | T_guard.start; |
| 99 | activate(as_Tguard()); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 100 | } |
| 101 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 102 | function f_exp_ipa_rx(integer bts_nr, template RSL_Message t_rx, float t_secs := 2.0, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) |
| 103 | runs on test_CT return RSL_Message { |
| 104 | var ASP_RSL_Unitdata rx_rsl_ud; |
| 105 | timer T := t_secs; |
| 106 | |
| 107 | T.start; |
| 108 | alt { |
| 109 | [] IPA_RSL[bts_nr].receive(tr_ASP_RSL_UD(sid, t_rx)) -> value rx_rsl_ud { |
| 110 | T.stop; |
| 111 | } |
| 112 | [] IPA_RSL[bts_nr].receive { repeat; } |
| 113 | [] T.timeout { setverdict(fail, "Timeout expecting ", t_rx); } |
| 114 | } |
| 115 | return rx_rsl_ud.rsl; |
| 116 | } |
| 117 | |
| 118 | function f_ipa_tx(integer bts_nr, template RSL_Message t_tx, IpaStreamId sid := IPAC_PROTO_RSL_TRX0) |
| 119 | runs on test_CT { |
| 120 | IPA_RSL[bts_nr].send(ts_ASP_RSL_UD(sid, t_tx)); |
| 121 | } |
| 122 | |
| 123 | |
| 124 | testcase TC_chan_act_noreply() runs on test_CT { |
| 125 | var BSSAP_N_UNITDATA_ind ud_ind; |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 126 | |
| 127 | f_init(); |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 128 | f_bssap_reset(); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 129 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 130 | IPA_RSL[0].send(ts_ASP_RSL_UD(IPAC_PROTO_RSL_TRX0,ts_RSL_CHAN_RQD('23'O, 23))); |
| 131 | f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV)); |
| 132 | setverdict(pass); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 133 | } |
| 134 | |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 135 | /* CHAN RQD -> CHAN ACT -> CHAN ACT ACK -> RF CHAN REL */ |
| 136 | testcase TC_chan_act_ack_noest() runs on test_CT { |
| 137 | var RSL_Message rx_rsl; |
| 138 | |
| 139 | f_init(); |
| 140 | f_bssap_reset(); |
| 141 | |
| 142 | /* Send CHAN RQD and wait for allocation; acknowledge it */ |
| 143 | f_ipa_tx(0, ts_RSL_CHAN_RQD('23'O, 23)); |
| 144 | rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV)); |
| 145 | var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr; |
| 146 | f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 23)); |
| 147 | |
| 148 | /* expect BSC to disable the channel again if there's no RLL EST IND */ |
| 149 | rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX); |
| 150 | |
| 151 | setverdict(pass); |
| 152 | } |
| 153 | |
| 154 | /* Test behavior if MSC never answers to CR */ |
| 155 | testcase TC_chan_act_ack_est_ind_noreply() runs on test_CT { |
| 156 | var RSL_Message rx_rsl; |
| 157 | |
| 158 | f_init(); |
| 159 | f_bssap_reset(); |
| 160 | |
| 161 | /* Send CHAN RQD and wait for allocation; acknowledge it */ |
| 162 | f_ipa_tx(0, ts_RSL_CHAN_RQD('23'O, 23)); |
| 163 | rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV)); |
| 164 | var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr; |
| 165 | f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 23)); |
| 166 | |
| 167 | var octetstring l3 := '00010203040506'O |
| 168 | f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3)); |
| 169 | |
| 170 | BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))); |
| 171 | |
| 172 | /* expect BSC to disable the channel again if there's no response from MSC */ |
| 173 | rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX); |
| 174 | |
| 175 | setverdict(pass); |
| 176 | } |
| 177 | |
| 178 | /* Test behavior if MSC answers with CREF to CR */ |
| 179 | testcase TC_chan_act_ack_est_ind_refused() runs on test_CT { |
| 180 | var BSSAP_N_CONNECT_ind rx_c_ind; |
| 181 | var RSL_Message rx_rsl; |
| 182 | |
| 183 | f_init(); |
| 184 | f_bssap_reset(); |
| 185 | |
| 186 | /* Send CHAN RQD and wait for allocation; acknowledge it */ |
| 187 | f_ipa_tx(0, ts_RSL_CHAN_RQD('23'O, 23)); |
| 188 | rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_CHAN_ACTIV)); |
| 189 | var RslChannelNr chan_nr := rx_rsl.ies[0].body.chan_nr; |
| 190 | f_ipa_tx(0, ts_RSL_CHAN_ACT_ACK(chan_nr, 23)); |
| 191 | |
| 192 | var octetstring l3 := '00010203040506'O |
| 193 | f_ipa_tx(0, ts_RSL_EST_IND(chan_nr, valueof(ts_RslLinkID_DCCH(0)), l3)); |
| 194 | |
| 195 | BSSAP.receive(tr_BSSAP_CONNECT_ind(?, ?, tr_BSSMAP_ComplL3(l3))) -> value rx_c_ind; |
| 196 | BSSAP.send(ts_BSSAP_DISC_req(rx_c_ind.connectionId, 0)); |
| 197 | |
| 198 | /* expect BSC to disable the channel */ |
| 199 | rx_rsl := f_exp_ipa_rx(0, tr_RSL_MsgTypeD(RSL_MT_RF_CHAN_REL), T3101_MAX); |
| 200 | |
| 201 | setverdict(pass); |
| 202 | } |
| 203 | |
| 204 | |
| 205 | |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 206 | control { |
Harald Welte | ae02669 | 2017-12-09 01:03:01 +0100 | [diff] [blame^] | 207 | execute( TC_chan_act_noreply() ); |
| 208 | execute( TC_chan_act_ack_noest() ); |
| 209 | execute( TC_chan_act_ack_est_ind_noreply() ); |
| 210 | execute( TC_chan_act_ack_est_ind_refused() ); |
Harald Welte | 28d943e | 2017-11-25 15:00:50 +0100 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | } |