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