Harald Welte | a0895f9 | 2018-03-08 11:51:23 +0100 | [diff] [blame] | 1 | module PCU_Tests { |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 2 | |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 3 | import from General_Types all; |
| 4 | import from Osmocom_Types all; |
| 5 | import from GSM_Types all; |
| 6 | import from GSM_RR_Types all; |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 7 | import from Osmocom_Gb_Types all; |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 8 | import from BSSGP_Types all; |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 9 | import from BSSGP_Emulation all; |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 10 | import from NS_Types all; |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 11 | import from NS_Emulation all; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 12 | import from LLC_Types all; |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 13 | import from LLC_Templates all; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 14 | import from RLCMAC_Types all; |
| 15 | import from RLCMAC_CSN1_Types all; |
| 16 | import from LAPDm_RAW_PT all; |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 17 | import from GPRS_Context all; |
| 18 | import from GPRS_TBF all; |
Harald Welte | b669ee0 | 2018-03-09 12:50:02 +0100 | [diff] [blame] | 19 | import from L1CTL_PortType all; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 20 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 21 | modulepar { |
| 22 | BssgpConfig mp_gb_cfg := { |
Harald Welte | 7024baa | 2018-03-02 23:37:51 +0100 | [diff] [blame] | 23 | nsei := 1234, |
| 24 | bvci := 1234, |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 25 | cell_id := { |
| 26 | ra_id := { |
| 27 | lai := { |
| 28 | mcc_mnc := '26242F'H, lac := 13135 |
| 29 | }, |
| 30 | rac := 0 |
| 31 | }, |
| 32 | cell_id := 20960 |
| 33 | }, |
| 34 | sgsn_role := true |
| 35 | }; |
| 36 | } |
| 37 | |
Harald Welte | 7024baa | 2018-03-02 23:37:51 +0100 | [diff] [blame] | 38 | type component dummy_CT extends BSSGP_Client_CT { |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 39 | var lapdm_CT lapdm_component; |
| 40 | port LAPDm_PT L1; |
| 41 | |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 42 | var NS_CT ns_component; |
| 43 | var BSSGP_CT bssgp_component; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 44 | |
| 45 | var MmContext g_mmctx := { |
Harald Welte | acc93ab | 2018-03-02 21:39:09 +0100 | [diff] [blame] | 46 | tlli := 'FFFFFFFF'O, |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 47 | n_u := 0 |
| 48 | }; |
| 49 | |
| 50 | var boolean g_initialized := false; |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | function f_init() runs on dummy_CT { |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 54 | if (g_initialized == true) { |
| 55 | return; |
| 56 | } |
| 57 | g_initialized := true; |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 58 | /* create a new NS component */ |
| 59 | ns_component := NS_CT.create; |
| 60 | bssgp_component := BSSGP_CT.create; |
| 61 | /* connect our BSSGP port to the BSSGP Emulation */ |
| 62 | connect(self:BSSGP, bssgp_component:BSSGP_SP); |
Stefan Sperling | f82bbb6 | 2018-05-03 19:14:28 +0200 | [diff] [blame^] | 63 | connect(self:BSSGP_SIG, bssgp_component:BSSGP_SP_SIG); |
Harald Welte | 7024baa | 2018-03-02 23:37:51 +0100 | [diff] [blame] | 64 | connect(self:BSSGP_PROC, bssgp_component:BSSGP_PROC); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 65 | /* connect lower-end of BSSGP with BSSGP_CODEC_PORT (maps to NS_PT*/ |
| 66 | connect(bssgp_component:BSCP, ns_component:NS_SP); |
| 67 | /* connect lower-end of NS emulation to NS_CODEC_PORT (on top of IPl4) */ |
| 68 | map(ns_component:NSCP, system:NS_CODEC_PORT); |
| 69 | ns_component.start(NSStart()); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 70 | bssgp_component.start(BssgpStart(mp_gb_cfg)); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 71 | |
| 72 | lapdm_component := lapdm_CT.create; |
| 73 | connect(self:L1, lapdm_component:LAPDM_SP); |
| 74 | map(lapdm_component:L1CTL, system:L1CTL); |
| 75 | lapdm_component.start(LAPDmStart()); |
Harald Welte | 54242db | 2018-03-03 22:38:54 +0100 | [diff] [blame] | 76 | |
| 77 | f_bssgp_client_register(g_mmctx.imsi, g_mmctx.tlli, mp_gb_cfg.cell_id); |
| 78 | f_bssgp_establish(); |
| 79 | } |
| 80 | |
| 81 | function f_exit() runs on dummy_CT { |
| 82 | lapdm_component.stop; |
| 83 | ns_component.stop; |
| 84 | bssgp_component.stop; |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 85 | } |
| 86 | |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 87 | function f_bssgp_dec_and_log(in octetstring inp) { |
| 88 | log("BSSGP Input: ", inp); |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 89 | var PDU_BSSGP dec := dec_PDU_BSSGP(inp); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 90 | log("BSSGP Decoded: ", dec); |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 91 | } |
| 92 | |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 93 | testcase TC_selftest_bssgp() runs on dummy_CT { |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 94 | const octetstring c_bvc_reset_pcu := '2204820000078108088832f44000c80051e0'O; |
| 95 | const octetstring c_bvc_reset_q := '2204820000078100'O; |
| 96 | const octetstring c_status_pcu := '4107810515882204820000078103'O; |
| 97 | const octetstring c_reset_ack_q := '2304820000'O; |
| 98 | const octetstring c_reset_ack_pcu := '23048200c4'O; |
| 99 | const octetstring c_unblock_pcu := '24048200c4'O; |
| 100 | const octetstring c_unblock_ack_q := '25048200c4'O; |
| 101 | const octetstring c_fc_bvc_pcu := '261e8101058200fa038200c8018200fa1c8200c806820000'O; |
| 102 | const octetstring c_fc_bvc_ack_q := '271e8101'O; |
| 103 | const octetstring c_gmm_mo_att_req := '01bb146ddd000004088832f44000c80051e000800e003b01c001080103e5e000110a0005f4fb146ddd32f44000c8001d1b53432b37159ef9090070000dd9c6321200e00019b32c642401c0002017057bf0ec'O; |
| 104 | const octetstring c_gmm_mt_ac_req := '00bb146ddd0050001682ffff0a8204030e9c41c001081200102198c72477ea104895e8b959acc58b108182f4d045'O; |
| 105 | const octetstring c_gmm_mo_ac_resp := '01bb146ddd000004088832f44000c80051e000800e000e01c00508130122fa361f5fdd623d'O; |
| 106 | const octetstring c_gmm_mt_att_acc := '00bb146ddd0050001682ffff0a8204030e9841c005080201340432f44000c8001805f4fb146ddd0967d0'O; |
| 107 | const octetstring c_gmm_mt_det_req := '00bb146ddd0050001682ffff0a8204030e8941c00908050215f0b6'O; |
| 108 | const octetstring c_gmm_mo_att_cpl := '01fb146ddd000004088832f44000c80051e000800e000801c009080339d7bc'O; |
| 109 | |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 110 | f_bssgp_dec_and_log(c_bvc_reset_pcu); |
| 111 | f_bssgp_dec_and_log(c_bvc_reset_q); |
| 112 | f_bssgp_dec_and_log(c_status_pcu); |
| 113 | f_bssgp_dec_and_log(c_reset_ack_q); |
| 114 | f_bssgp_dec_and_log(c_reset_ack_pcu); |
| 115 | f_bssgp_dec_and_log(c_unblock_pcu); |
| 116 | f_bssgp_dec_and_log(c_unblock_ack_q); |
| 117 | f_bssgp_dec_and_log(c_fc_bvc_pcu); |
| 118 | f_bssgp_dec_and_log(c_fc_bvc_ack_q); |
| 119 | f_bssgp_dec_and_log(c_gmm_mo_att_req); |
| 120 | f_bssgp_dec_and_log(c_gmm_mt_ac_req); |
| 121 | f_bssgp_dec_and_log(c_gmm_mo_ac_resp); |
| 122 | f_bssgp_dec_and_log(c_gmm_mt_att_acc); |
| 123 | f_bssgp_dec_and_log(c_gmm_mt_det_req); |
| 124 | f_bssgp_dec_and_log(c_gmm_mo_att_cpl); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 125 | |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 126 | log(ts_BSSGP_PS_PAGING_IMSI(196, '262420123456789'H)); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | function f_ns_assert_prepr(in octetstring a, in octetstring b) { |
| 130 | log("NS Input: ", a); |
| 131 | log("NS Expected: ", b); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 132 | |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 133 | if (a != b) { |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 134 | setverdict(fail); |
| 135 | } else { |
| 136 | setverdict(pass); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | function f_ns_dec_and_log(in octetstring inp) { |
| 141 | log("NS Input: ", inp); |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 142 | var PDU_NS dec := dec_PDU_NS(inp); |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 143 | log("NS Decoded: ", dec); |
| 144 | } |
| 145 | |
| 146 | testcase TC_selftest_ns() runs on dummy_CT { |
| 147 | const octetstring c_ns_reset_pcu := '000000c4271e813d'O; |
| 148 | |
| 149 | /* single byte length to two byte length */ |
| 150 | f_ns_assert_prepr('04058101'O, '0405000101'O); |
| 151 | f_ns_assert_prepr('040589000102030405060708'O, '04050009000102030405060708'O); |
| 152 | /* two byte length to two byte length */ |
| 153 | f_ns_assert_prepr('0405000101'O, '0405000101'O); |
| 154 | /* special case: NS-UNITDATA */ |
| 155 | f_ns_assert_prepr('00aabbccddeeffaa29822342'O, '00aabbccddeeffaa2900022342'O); |
| 156 | /* multiple TLVs */ |
| 157 | f_ns_assert_prepr('234281aa4382bbbb'O, '23420001aa430002bbbb'O); |
| 158 | /* zero-length */ |
| 159 | f_ns_assert_prepr('230080'O, '23000000'O); |
| 160 | |
| 161 | f_ns_dec_and_log(c_ns_reset_pcu); |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 162 | } |
| 163 | |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 164 | const octetstring gmm_auth_req := '081200102198c72477ea104895e8b959acc58b108182'O; |
| 165 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 166 | /* Wrap downlink GMM into LLC, encode + send it via BSSGP to PCU */ |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 167 | function tx_gmm(BIT1 c_r, in octetstring gmm_pdu, BIT4 sapi := c_LLC_SAPI_LLGMM) runs on dummy_CT { |
| 168 | var PDU_LLC llc; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 169 | |
Harald Welte | 0e23a8f | 2017-12-12 16:47:48 +0100 | [diff] [blame] | 170 | //log("GMM Tx: ", dec_PDU_L3_SGSN_MS(gmm_pdu)); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 171 | |
| 172 | log(c_r, g_mmctx.n_u, gmm_pdu, sapi); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 173 | llc := valueof(ts_LLC_UI(gmm_pdu, sapi, c_r, g_mmctx.n_u)); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 174 | log(llc); |
| 175 | g_mmctx.n_u := g_mmctx.n_u + 1; |
| 176 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 177 | log(ts_BSSGP_DL_UD(g_mmctx.tlli, enc_PDU_LLC(llc))); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 178 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 179 | BSSGP.send(ts_BSSGP_DL_UD(g_mmctx.tlli, enc_PDU_LLC(llc))); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 180 | } |
| 181 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 182 | /* Establish BSSGP connection to PCU */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 183 | function f_bssgp_establish() runs on dummy_CT { |
Harald Welte | 7024baa | 2018-03-02 23:37:51 +0100 | [diff] [blame] | 184 | timer T:= 10.0; |
Harald Welte | 13d391e | 2017-07-23 19:52:33 +0200 | [diff] [blame] | 185 | |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 186 | f_init(); |
Harald Welte | 13d391e | 2017-07-23 19:52:33 +0200 | [diff] [blame] | 187 | T.start |
| 188 | alt { |
| 189 | [] BSSGP.receive(t_BssgpStsInd(?, ?, BVC_S_UNBLOCKED)) { } |
| 190 | [] BSSGP.receive { repeat; } |
| 191 | [] T.timeout { setverdict(fail); } |
| 192 | } |
| 193 | T.stop |
| 194 | log("BSSGP successfully initialized"); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 195 | } |
| 196 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 197 | /* Send PS-PAGING via BSSGP to PCU, expect it to show up on L1/Um */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 198 | testcase TC_paging() runs on dummy_CT { |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 199 | var GsmTmsi tmsi := hex2int('01234567'H); |
Harald Welte | a35a9ca | 2018-03-08 17:59:39 +0100 | [diff] [blame] | 200 | g_mmctx.imsi := '262420123456789'H; |
| 201 | g_mmctx.tlli := f_random_tlli(); |
| 202 | f_init(); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 203 | |
Stefan Sperling | f82bbb6 | 2018-05-03 19:14:28 +0200 | [diff] [blame^] | 204 | /* Send paging on signalling BVCI 0 since osmo-pcu does not support paging on PTP yet. */ |
| 205 | BSSGP_SIG.send(ts_BSSGP_PS_PAGING_IMSI(0, g_mmctx.imsi)); |
| 206 | BSSGP_SIG.send(ts_BSSGP_PS_PAGING_PTMSI(0, g_mmctx.imsi, tmsi)); |
Harald Welte | 13d391e | 2017-07-23 19:52:33 +0200 | [diff] [blame] | 207 | |
| 208 | while (true) { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 209 | var BssgpDecoded bd; |
Harald Welte | 13d391e | 2017-07-23 19:52:33 +0200 | [diff] [blame] | 210 | alt { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 211 | [] BSSGP.receive(tr_BD_L3_MT(?)) -> value bd { |
| 212 | log("BSSGP Rx: ", bd); |
Harald Welte | 13d391e | 2017-07-23 19:52:33 +0200 | [diff] [blame] | 213 | } |
| 214 | [] BSSGP.receive(t_BssgpStsInd(?, ?, BVC_S_UNBLOCKED)) { repeat; } |
| 215 | [] BSSGP.receive { repeat; } |
| 216 | } |
| 217 | } |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 218 | } |
| 219 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 220 | /* Establish an UL TBF: Tune to ARFCN, send RACH, receive AGCH, enable TBF Rx */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 221 | function f_establish_ul_tbf() runs on dummy_CT { |
| 222 | timer T := 5.0; |
| 223 | var BCCH_tune_req tune_req := { { false, 871 }, true }; |
| 224 | L1.send(tune_req); |
| 225 | /* FIXME: wait for confirm */ |
| 226 | |
Harald Welte | b669ee0 | 2018-03-09 12:50:02 +0100 | [diff] [blame] | 227 | var TBF_UL_establish_req est_req := { tbf_nr := 0, ra := hex2int('7B'H) }; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 228 | L1.send(est_req); |
| 229 | T.start; |
| 230 | /* FIXME: wait for confirm */ |
| 231 | alt { |
Harald Welte | b669ee0 | 2018-03-09 12:50:02 +0100 | [diff] [blame] | 232 | [] L1.receive(TBF_UL_establish_res:?) {} |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 233 | [] L1.receive { repeat; } |
Harald Welte | 54242db | 2018-03-03 22:38:54 +0100 | [diff] [blame] | 234 | [] T.timeout { |
| 235 | setverdict(fail, "Timeout establishing UL TBF"); |
| 236 | self.stop; |
| 237 | } |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 238 | } |
| 239 | T.stop; |
| 240 | } |
| 241 | |
Harald Welte | 9d83dd0 | 2018-03-02 17:00:22 +0100 | [diff] [blame] | 242 | /* compute a random TLLI; FIXME: what about TLLI prefix / local/foreign/...? */ |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 243 | function f_random_tlli() return GprsTlli { |
Harald Welte | acc93ab | 2018-03-02 21:39:09 +0100 | [diff] [blame] | 244 | var GprsTlli tlli := f_rnd_octstring(4); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 245 | return tlli; |
| 246 | } |
| 247 | |
Harald Welte | 7024baa | 2018-03-02 23:37:51 +0100 | [diff] [blame] | 248 | /* Compute the frame number of the uplink block based on current fn + rrbp */ |
| 249 | function f_rrbp_fn(GsmFrameNumber fn, MacRrbp rrbp) return GsmFrameNumber { |
| 250 | var integer add; |
| 251 | select (rrbp) { |
| 252 | case (RRBP_Nplus13_mod_2715648) { |
| 253 | add := 13; |
| 254 | } |
| 255 | case (RRBP_Nplus17_or_18_mod_2715648) { |
| 256 | add := 17; /* FIXME: What about 'or 18'? */ |
| 257 | } |
| 258 | case (RRBP_Nplus21_or_22_mod_2715648) { |
| 259 | add := 21; /* FIXME: What about 'or 22'? */ |
| 260 | } |
| 261 | case (RRBP_Nplus26_mod_2715648) { |
| 262 | add := 26; |
| 263 | } |
| 264 | } |
| 265 | return (fn + add) mod 2715648; |
| 266 | } |
| 267 | |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 268 | |
| 269 | function f_bssgp_wait_ul_ud(template BssgpDecoded bd_exp) runs on dummy_CT { |
| 270 | timer T := 5.0; |
| 271 | T.start; |
| 272 | alt { |
| 273 | [] BSSGP.receive(bd_exp) { |
| 274 | log("found matching BSSGP UL-UNITDATA PDU"); |
| 275 | } |
| 276 | [] T.timeout { |
| 277 | setverdict(fail, "Timeout waiting for ", bd_exp); |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | |
| 283 | function f_ul_tbf(inout UlTbfState us) runs on dummy_CT { |
| 284 | var RLCMAC_ph_data_ind dl; |
| 285 | |
| 286 | /* Establish an UL-TBF */ |
| 287 | f_establish_ul_tbf(); |
| 288 | |
| 289 | while (true) { |
| 290 | var RlcmacUlBlock blk; |
| 291 | if (f_ul_tbf_get_next_block(blk, us, g_mmctx, true) == false) { |
| 292 | break; |
| 293 | } |
| 294 | |
| 295 | /* Send the block to L1 for transmission */ |
| 296 | log("L1=", blk); |
| 297 | L1.send(RLCMAC_ph_data_req:{dyn:={tbf_id := 0, cs := us.tbf.initial_cs, block := blk}}); |
| 298 | } |
| 299 | |
| 300 | alt { |
| 301 | [] L1.receive(RLCMAC_ph_data_ind:{cs:=?, ts_nr:=?, fn:=?, block:=tr_RLCMAC_ACK_NACK(0, g_mmctx.tlli)}) -> value dl { |
| 302 | log("found matching ACK/NACK"); |
| 303 | /* send CTRL ACK in uplink */ |
| 304 | var GsmFrameNumber ul_fn := f_rrbp_fn(dl.fn, dl.block.ctrl.mac_hdr.rrbp); |
| 305 | var RlcmacUlCtrlMsg ctrl_ack := valueof(ts_RlcMacUlCtrl_PKT_CTRL_ACK(g_mmctx.tlli)); |
| 306 | var RlcmacUlBlock ul_block := valueof(ts_RLC_UL_CTRL_ACK(ctrl_ack)); |
| 307 | L1.send(ts_PH_DATA_ABS(0, CS1, dl.ts_nr, ul_fn, {false, 871}, ul_block)); |
| 308 | /* wait for the final ACK */ |
| 309 | if (dl.block.ctrl.payload.u.ul_ack_nack.gprs.ack_nack_desc.final_ack == '0'B) { |
| 310 | repeat; |
| 311 | } |
| 312 | } |
| 313 | [] L1.receive { repeat; } |
| 314 | } |
| 315 | |
| 316 | for (var integer i := 0; i < sizeof(us.tbf.llc_pdus_enc); i := i+1) { |
| 317 | f_bssgp_wait_ul_ud(tr_BD_BSSGP(tr_BSSGP_UL_UD(g_mmctx.tlli, ?, us.tbf.llc_pdus_enc[i]))); |
| 318 | } |
| 319 | setverdict(pass); |
Harald Welte | 54242db | 2018-03-03 22:38:54 +0100 | [diff] [blame] | 320 | |
| 321 | L1.send(DCCH_release_req:{}); |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 322 | } |
| 323 | |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 324 | testcase TC_rach() runs on dummy_CT { |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 325 | var BssgpBvci bvci := 196; |
Harald Welte | 7024baa | 2018-03-02 23:37:51 +0100 | [diff] [blame] | 326 | g_mmctx.imsi := '262420123456789'H; |
| 327 | g_mmctx.tlli := f_random_tlli(); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 328 | |
| 329 | f_init(); |
| 330 | |
Harald Welte | 7024baa | 2018-03-02 23:37:51 +0100 | [diff] [blame] | 331 | f_bssgp_client_register(g_mmctx.imsi, g_mmctx.tlli, mp_gb_cfg.cell_id); |
| 332 | |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 333 | f_bssgp_establish(); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | |
| 337 | testcase TC_nsem() runs on dummy_CT { |
| 338 | |
| 339 | f_bssgp_establish(); |
| 340 | |
| 341 | while (true) { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 342 | var BssgpDecoded bd; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 343 | alt { |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 344 | [] BSSGP.receive(tr_BD_BSSGP(?)) -> value bd { |
| 345 | log("BSSGP Rx: ", bd); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 346 | //log("GMM Rx: ", dec_PDU_L3_MS_SGSN(pdu.payload)); |
Harald Welte | acc93ab | 2018-03-02 21:39:09 +0100 | [diff] [blame] | 347 | g_mmctx.tlli := bd.bssgp.pDU_BSSGP_UL_UNITDATA.tLLI; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 348 | tx_gmm(LLC_CR_DL_CMD, gmm_auth_req); |
| 349 | } |
| 350 | [] BSSGP.receive(t_BssgpStsInd(?, ?, BVC_S_UNBLOCKED)) { repeat; } |
| 351 | [] BSSGP.receive { repeat; } |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | |
| 357 | function f_llc_dec_and_log(in octetstring inp) { |
| 358 | log("LLC Input: ", inp); |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 359 | var PDU_LLC dec := dec_PDU_LLC(inp); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 360 | log("LLC Decoded: ", dec); |
| 361 | } |
| 362 | |
| 363 | function f_llc_assert(in octetstring a, in octetstring b) { |
| 364 | log("LLC Input: ", a); |
| 365 | log("LLC Expected: ", b); |
| 366 | |
| 367 | if (a != b) { |
| 368 | setverdict(fail); |
| 369 | } else { |
| 370 | setverdict(pass); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | |
| 375 | testcase TC_selftest_llc() runs on dummy_CT { |
| 376 | const octetstring c_gmm_att_pcu := '01c001080103e5e000210a0005f4fb146ddd32f44000c8001d1b53432b37159ef9090070000dd9c6321200e00019b32c642401c00020170580460b'O; |
| 377 | const octetstring c_gmm_att_pcu_nofcs := '01c001080103e5e000210a0005f4fb146ddd32f44000c8001d1b53432b37159ef9090070000dd9c6321200e00019b32c642401c000201705'O; |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 378 | |
| 379 | f_llc_dec_and_log(c_gmm_att_pcu); |
| 380 | |
Harald Welte | e0abc47 | 2018-02-05 09:13:31 +0100 | [diff] [blame] | 381 | //f_llc_assert(f_LLC_append_fcs(c_gmm_att_pcu_nofcs), c_gmm_att_pcu); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 382 | |
Harald Welte | 5ac3149 | 2018-02-15 20:39:13 +0100 | [diff] [blame] | 383 | log(valueof(ts_LLC_UI(gmm_auth_req, c_LLC_SAPI_LLGMM, LLC_CR_DL_CMD, g_mmctx.n_u))); |
| 384 | log(ts_LLC_UI(gmm_auth_req, c_LLC_SAPI_LLGMM, LLC_CR_DL_CMD, g_mmctx.n_u)); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | testcase TC_selftest_rlcmac() runs on dummy_CT { |
| 388 | var RlcmacDlCtrlBlock dcb; |
| 389 | var RlcmacUlCtrlBlock ucb; |
| 390 | const octetstring c_dl_ul_ack_nack := '40240080400000000000000077628dbba14b2b2b2b2b2b'O; |
| 391 | const octetstring c_dl_data := '0f00007341c001081200102198c72477ea104895e8b959acc58b108182f4d0454300'O; |
| 392 | const octetstring c_dl_data2 := '070002165dc0012b2b2b43c0012b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b00'O; |
| 393 | const octetstring c_ul_ctrl_ack := '4006ec51b7772b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b'O; |
| 394 | const octetstring c_ul_dl_ack_nack := '4008004000000000000000701000edc0000b2b2b2b2b2b'O; |
| 395 | const octetstring c_dl_ul_assign := '482857628dbbaf0126e68800082b2b2b2b2b2b2b2b2b2b'O; |
| 396 | |
| 397 | log(c_dl_ul_ack_nack); |
| 398 | dcb := dec_RlcmacDlCtrlBlock(c_dl_ul_ack_nack); |
| 399 | log(dcb); |
| 400 | //log(dec_RlcmacDlCtrlMsg(dcb.payload)); |
| 401 | |
| 402 | f_rlcmac_dld_decenc(c_dl_data); |
| 403 | |
| 404 | f_rlcmac_dld_decenc(c_dl_data2); |
| 405 | |
| 406 | log(c_ul_ctrl_ack); |
| 407 | ucb := dec_RlcmacUlCtrlBlock(c_ul_ctrl_ack); |
| 408 | log(ucb); |
| 409 | //log(dec_RlcmacUlCtrlMsg(ucb.payload)); |
| 410 | |
| 411 | log(c_ul_dl_ack_nack); |
| 412 | ucb := dec_RlcmacUlCtrlBlock(c_ul_dl_ack_nack); |
| 413 | log(ucb); |
| 414 | //log(dec_RlcmacUlCtrlMsg(ucb.payload)); |
| 415 | |
| 416 | log(c_dl_ul_assign); |
| 417 | dcb := dec_RlcmacDlCtrlBlock(c_dl_ul_assign); |
| 418 | log(dcb); |
| 419 | //log(dec_RlcmacDlCtrlMsg(dcb.payload)); |
| 420 | |
| 421 | const octetstring c_uld_tlli_noext := '080101a61cab5201c001080103e5e000310a0005f4e61cab5232f44000c8001d1b00'O; |
| 422 | f_rlcmac_uld_decenc(c_uld_tlli_noext); |
| 423 | |
| 424 | const octetstring c_uld_tlli_ext7pad := '0001041da61cab5200201705a96e102b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b00'O; |
| 425 | log("ULD_decenc"); |
| 426 | f_rlcmac_uld_decenc(c_uld_tlli_ext7pad); |
| 427 | log("UL_decenc"); |
| 428 | f_rlcmac_ul_decenc(c_uld_tlli_ext7pad); |
| 429 | |
| 430 | f_rlcmac_ul_decenc(c_ul_dl_ack_nack); |
| 431 | } |
| 432 | |
| 433 | function f_rlcmac_ul_decenc(in octetstring buf) { |
| 434 | log("=================================="); |
| 435 | log("In: ", buf); |
| 436 | var RlcmacUlBlock udb := dec_RlcmacUlBlock(buf); |
| 437 | log("Dec: ", udb); |
| 438 | var octetstring enc := enc_RlcmacUlBlock(udb); |
| 439 | log("Enc: ", enc); |
| 440 | if (enc != buf) { setverdict(fail, "Re-encoded data doesn't equal input data"); } |
| 441 | } |
| 442 | |
| 443 | function f_rlcmac_uld_decenc(in octetstring buf) { |
| 444 | log("=================================="); |
| 445 | log("In: ", buf); |
| 446 | var RlcmacUlDataBlock udb := dec_RlcmacUlDataBlock(buf); |
| 447 | log("Dec: ", udb); |
| 448 | var octetstring enc := enc_RlcmacUlDataBlock(udb); |
| 449 | log("Enc: ", enc); |
| 450 | if (enc != buf) { setverdict(fail, "Re-encoded data doesn't equal input data"); } |
| 451 | } |
| 452 | |
| 453 | function f_rlcmac_dld_decenc(in octetstring buf) { |
| 454 | log("=================================="); |
| 455 | log("In: ", buf); |
| 456 | var RlcmacDlDataBlock udb := dec_RlcmacDlDataBlock(buf); |
| 457 | log("Dec: ", udb); |
| 458 | var octetstring enc := enc_RlcmacDlDataBlock(udb); |
| 459 | log("Enc: ", enc); |
| 460 | if (enc != buf) { setverdict(fail, "Re-encoded data doesn't equal input data"); } |
| 461 | } |
| 462 | |
| 463 | |
| 464 | testcase TC_selftest_rr() runs on dummy_CT { |
| 465 | //const octetstring c_paging_none := '06210001F02B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O |
| 466 | const octetstring c_paging_none := '1506210001F0'O; |
| 467 | const octetstring c_ia_tbf := '2d063f100fe3677bd8440000c800100b2b2b2b2b2b2b2b'O |
| 468 | log(c_paging_none); |
| 469 | log(dec_GsmRrMessage(c_paging_none)); |
| 470 | |
| 471 | log(c_ia_tbf); |
| 472 | log(dec_GsmRrMessage(c_ia_tbf)); |
| 473 | } |
| 474 | |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 475 | function f_seq_octstr(integer len) return octetstring { |
| 476 | var octetstring payload := ''O; |
| 477 | for (var integer i := 0; i < len; i := i+1 ) { |
| 478 | payload := payload & int2oct(i mod 256, 1); |
| 479 | } |
| 480 | return payload; |
| 481 | } |
| 482 | |
Harald Welte | 54242db | 2018-03-03 22:38:54 +0100 | [diff] [blame] | 483 | testcase TC_ul_tbf_single_llc_sizes() runs on dummy_CT { |
| 484 | g_mmctx.imsi := '262420123456789'H; |
| 485 | g_mmctx.tlli := f_random_tlli(); |
| 486 | f_init(); |
| 487 | |
| 488 | for (var integer len := 1; len <= 1560; len := len+1) { |
| 489 | log("Testing Uplink TBF with single LLC-PDU of ", len, " bytes"); |
| 490 | var octetstring payload := f_seq_octstr(len); |
| 491 | var UlTbfPars ul_tbf_pars := { |
| 492 | ack_mode := true, |
| 493 | initial_cs := CS1, |
| 494 | llc_pdus := { |
| 495 | valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u)) |
| 496 | } |
| 497 | } |
| 498 | var UlTbfState ul_tbf_state; |
| 499 | f_UlTbfState_init(ul_tbf_state, ul_tbf_pars); |
| 500 | f_ul_tbf(ul_tbf_state); |
| 501 | f_sleep(1.0); |
| 502 | } |
| 503 | |
| 504 | f_exit(); |
| 505 | } |
| 506 | |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 507 | testcase TC_ul_tbf() runs on dummy_CT { |
| 508 | g_mmctx.imsi := '262420123456789'H; |
| 509 | g_mmctx.tlli := f_random_tlli(); |
| 510 | f_init(); |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 511 | |
Harald Welte | 54242db | 2018-03-03 22:38:54 +0100 | [diff] [blame] | 512 | var octetstring payload := f_seq_octstr(1023); |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 513 | var UlTbfPars ul_tbf_pars := { |
| 514 | ack_mode := true, |
| 515 | initial_cs := CS1, |
| 516 | llc_pdus := { |
| 517 | valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u)), |
Harald Welte | 54242db | 2018-03-03 22:38:54 +0100 | [diff] [blame] | 518 | valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u+1)), |
| 519 | valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u+2)), |
| 520 | valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u+3)), |
| 521 | valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u+4)), |
| 522 | valueof(ts_LLC_UI(payload, c_LLC_SAPI_LLGMM, '0'B, g_mmctx.n_u+5)) |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 523 | } |
| 524 | }; |
| 525 | var UlTbfState ul_tbf_state; |
| 526 | f_UlTbfState_init(ul_tbf_state, ul_tbf_pars); |
| 527 | f_ul_tbf(ul_tbf_state); |
Harald Welte | 54242db | 2018-03-03 22:38:54 +0100 | [diff] [blame] | 528 | |
| 529 | f_exit(); |
Harald Welte | 060e27a | 2018-03-03 20:38:19 +0100 | [diff] [blame] | 530 | } |
| 531 | |
Harald Welte | b669ee0 | 2018-03-09 12:50:02 +0100 | [diff] [blame] | 532 | testcase TC_dl_tbf() runs on dummy_CT { |
| 533 | g_mmctx.imsi := '262420123456789'H; |
| 534 | g_mmctx.tlli := f_random_tlli(); |
| 535 | f_init(); |
| 536 | |
| 537 | f_establish_dl_tbf(); |
| 538 | |
| 539 | f_exit(); |
| 540 | } |
| 541 | |
| 542 | function f_wait_tbf_dl(TbfNr tbf_nr, GprsTlli tlli) runs on dummy_CT return ImmediateAssignment { |
| 543 | var LAPDm_ph_data ph_data; |
| 544 | var GsmRrMessage rr; |
| 545 | timer T := 10.0; |
| 546 | T.start; |
| 547 | alt { |
| 548 | [] L1.receive(LAPDm_ph_data:{sacch:=?,sapi:=0,lapdm:={bbis:=?}}) -> value ph_data { |
| 549 | rr := dec_GsmRrMessage(ph_data.lapdm.bbis.payload); |
| 550 | log("PCH/AGCH DL RR: ", rr); |
| 551 | if (match(rr, t_RR_IMM_ASS_TBF_DL(tlli))) { |
| 552 | var TbfPars tbf_pars := valueof(t_TbfParsInit); |
| 553 | log("Received IMM.ASS for our TLLI!"); |
| 554 | tbf_pars.tfi[rr.payload.imm_ass.pkt_chan_desc.tn] := |
| 555 | rr.payload.imm_ass.rest_octets.hh.dl.group1.tfi_assignment; |
| 556 | L1.send(TBF_DL_establish_req:{tbf_nr, tbf_pars}); |
| 557 | } else { |
| 558 | repeat; |
| 559 | } |
| 560 | } |
| 561 | [] L1.receive { repeat }; |
| 562 | [] T.timeout { |
| 563 | setverdict(fail, "Timeout waiting for IMM ASS") |
| 564 | self.stop; |
| 565 | } |
| 566 | } |
| 567 | T.stop; |
| 568 | return rr.payload.imm_ass; |
| 569 | } |
| 570 | |
| 571 | /* Establish an UL TBF: Tune to ARFCN, send RACH, receive AGCH, enable TBF Rx */ |
| 572 | function f_establish_dl_tbf() runs on dummy_CT { |
| 573 | timer T := 5.0; |
| 574 | var BCCH_tune_req tune_req := { { false, 871 }, true }; |
| 575 | L1.send(tune_req); |
| 576 | /* FIXME: wait for confirm */ |
| 577 | |
| 578 | /* sending a GMM PDU as DL-UNITDATA should trigger Paging + DL TBF Assignment */ |
| 579 | tx_gmm('1'B, '01020304'O, c_LLC_SAPI_LLGMM); |
| 580 | |
| 581 | /* Expect an IMM.ASS for PDCH on the AGCH */ |
| 582 | f_wait_tbf_dl(0, g_mmctx.tlli); |
| 583 | |
| 584 | var RLCMAC_ph_data_ind dl; |
| 585 | alt { |
| 586 | [] L1.receive(RLCMAC_ph_data_ind:{cs:=?, ts_nr:=?, fn:=?, block:=tr_RLCMAC_DATA_RRBP}) -> |
| 587 | value dl { |
| 588 | var uint6_t tfi := dl.block.data.mac_hdr.hdr_ext.tfi; |
| 589 | var GsmFrameNumber ul_fn := f_rrbp_fn(dl.fn, dl.block.data.mac_hdr.mac_hdr.rrbp); |
| 590 | var AckNackDescription an_desc := { /* FIXME: compute this based on state */ |
| 591 | final_ack := '1'B, |
| 592 | starting_seq_nr := 0, |
| 593 | receive_block_bitmap := '0000000000000000000000000000000000000000000000000000000000000001'B |
| 594 | } |
| 595 | var RlcmacUlCtrlMsg ctrl_ack; |
| 596 | ctrl_ack := valueof(ts_RlcMacUlCtrl_PKT_DL_ACK(tfi, an_desc)); |
| 597 | var RlcmacUlBlock ul_block := valueof(ts_RLC_UL_CTRL_ACK(ctrl_ack)); |
| 598 | L1.send(ts_PH_DATA_ABS(0, CS1, dl.ts_nr, ul_fn, {false, 871}, ul_block)); |
| 599 | log("Sent DL ACK: ", ul_block); |
| 600 | } |
| 601 | [] L1.receive { repeat; } |
| 602 | } |
| 603 | |
| 604 | f_sleep(10.0); |
| 605 | } |
| 606 | |
| 607 | |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 608 | control { |
Harald Welte | 6fff364 | 2017-07-22 21:36:13 +0200 | [diff] [blame] | 609 | execute(TC_selftest_bssgp()); |
| 610 | execute(TC_selftest_ns()); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 611 | execute(TC_selftest_llc()); |
| 612 | execute(TC_selftest_rr()); |
| 613 | execute(TC_selftest_rlcmac()); |
Harald Welte | 6e594f2 | 2017-07-23 16:19:35 +0200 | [diff] [blame] | 614 | execute(TC_nsem()); |
Harald Welte | 244cd8a | 2017-08-26 09:25:20 +0200 | [diff] [blame] | 615 | execute(TC_paging()); |
Harald Welte | 3a19440 | 2017-07-22 17:07:51 +0200 | [diff] [blame] | 616 | } |
| 617 | }; |