Harald Welte | 97cca2f | 2019-05-30 16:33:38 +0200 | [diff] [blame] | 1 | module BTS_Tests_LAPDm { |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 2 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 3 | import from GSM_Types all; |
| 4 | import from Osmocom_Types all; |
| 5 | import from LAPDm_RAW_PT all; |
| 6 | import from LAPDm_Types all; |
| 7 | import from BTS_Tests all; |
Harald Welte | 66110f0 | 2017-07-16 21:05:18 +0200 | [diff] [blame] | 8 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 9 | /* test that use exclusively only LAPDm over L1CTL */ |
| 10 | type component lapdm_test_CT { |
| 11 | port LAPDm_PT LAPDM; |
| 12 | var lapdm_CT lapdm_component; |
| 13 | }; |
| 14 | |
| 15 | /* contrary to BTS_Tests.ttcn, we use LAPDm_PT here, a convenience wrapper |
| 16 | * around L1CTL to perform encode/decode of abstract LAPDm frames */ |
| 17 | type component lapdm_bts_CT extends lapdm_test_CT, test_CT { |
| 18 | } |
| 19 | |
Harald Welte | 61332c0 | 2019-05-30 16:45:15 +0200 | [diff] [blame] | 20 | /********************************************************************************* |
| 21 | * Test using only L1CTL/LAPDm |
| 22 | *********************************************************************************/ |
| 23 | |
| 24 | function f_lapdm_init() runs on lapdm_test_CT { |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 25 | /* create the LAPDm component */ |
| 26 | lapdm_component := lapdm_CT.create; |
| 27 | /* connect our own LAPDM port to the LAPDM Service Provider of the LAPDm component */ |
| 28 | connect(self:LAPDM, lapdm_component:LAPDM_SP); |
| 29 | /* connect the LAPDm compoent's lower-side port to the system L1CTL port (which is internally |
| 30 | * connected to the Unix Domain Socket test port */ |
| 31 | map(lapdm_component:L1CTL, system:L1CTL); |
| 32 | |
| 33 | /* start the LAPDm parallel component calling it's local function LAPDmStart */ |
| 34 | lapdm_component.start(LAPDmStart()); |
| 35 | } |
| 36 | |
| 37 | /* master function establishing a dedicated radio channel (takes care of RACH/IMM.ASS handling) */ |
| 38 | function f_establish_dcch() runs on lapdm_test_CT { |
| 39 | var BCCH_tune_req tune_req := { arfcn := { false, 871 }, combined_ccch := true }; |
| 40 | var DCCH_establish_req est_req := { ra := 23 }; |
| 41 | |
| 42 | LAPDM.send(tune_req); |
| 43 | LAPDM.send(est_req); |
| 44 | LAPDM.receive(DCCH_establish_res:?); |
| 45 | } |
| 46 | |
| 47 | /* helper function releasing dedicated radio channel physically (no Um signaling!) */ |
| 48 | function f_release_dcch() runs on lapdm_test_CT { |
| 49 | var DCCH_release_req rel_req := {}; |
| 50 | LAPDM.send(rel_req); |
| 51 | } |
| 52 | |
| 53 | template LAPDm_ph_data t_PH_DATA(template GsmSapi sapi, template boolean sacch, template LapdmFrame frame) := { |
| 54 | sacch := sacch, |
| 55 | sapi := sapi, |
| 56 | lapdm := frame |
| 57 | } |
| 58 | /* template for a valid SABM frame */ |
| 59 | template LapdmFrame LAPDm_B_SABM(template GsmSapi sapi, octetstring payload) := { |
| 60 | ab := { |
| 61 | addr := tr_LapdmAddr(sapi, false), |
| 62 | ctrl := tr_LapdmCtrlSABM(true), |
| 63 | len := lengthof(payload), |
| 64 | m := false, |
| 65 | el := 1, |
| 66 | payload := payload |
Harald Welte | c38611b | 2019-05-30 16:33:58 +0200 | [diff] [blame] | 67 | } |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 68 | } |
Harald Welte | c38611b | 2019-05-30 16:33:58 +0200 | [diff] [blame] | 69 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 70 | /* template for a valid UA frame */ |
| 71 | template LapdmFrame tr_LAPDm_B_UA(template GsmSapi sapi, template octetstring payload) := { |
| 72 | ab := { |
| 73 | addr := tr_LapdmAddr(sapi, false), |
| 74 | ctrl := tr_LapdmCtrlUA(true), |
| 75 | len := ?, |
| 76 | m := false, |
| 77 | el := 1, |
| 78 | payload := payload |
Harald Welte | 52c713c | 2017-07-16 15:44:44 +0200 | [diff] [blame] | 79 | } |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 80 | } |
Harald Welte | 52c713c | 2017-07-16 15:44:44 +0200 | [diff] [blame] | 81 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 82 | /* template for a valid UA frame */ |
| 83 | template LapdmFrame LAPDm_B_UA(template GsmSapi sapi, octetstring payload) := { |
| 84 | ab := { |
| 85 | addr := tr_LapdmAddr(sapi, false), |
| 86 | ctrl := tr_LapdmCtrlUA(true), |
| 87 | len := lengthof(payload), |
| 88 | m := false, |
| 89 | el := 1, |
| 90 | payload := payload |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 91 | } |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 92 | } |
Harald Welte | 66110f0 | 2017-07-16 21:05:18 +0200 | [diff] [blame] | 93 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 94 | /* template for a valid UI frame */ |
| 95 | template LapdmFrame LAPDm_B_UI(template GsmSapi sapi, octetstring payload) := { |
| 96 | ab := { |
| 97 | addr := tr_LapdmAddr(sapi, true), |
| 98 | ctrl := tr_LapdmCtrlUI(false), |
| 99 | len := lengthof(payload), |
| 100 | m := false, |
| 101 | el := 1, |
| 102 | payload := payload |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 103 | } |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 104 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 105 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 106 | template LapdmFrame t_nopayload(template GsmSapi sapi) := { |
| 107 | ab := { |
| 108 | addr := tr_LapdmAddr(sapi, true), |
| 109 | ctrl := ?, |
| 110 | len := 0, |
| 111 | m := false, |
| 112 | el := 1, |
| 113 | payload := ''O |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 114 | } |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | template LapdmFrame LAPDm_B_DISC(template GsmSapi sapi) modifies t_nopayload := { |
| 118 | ab := { |
| 119 | ctrl := tr_LapdmCtrlDISC(true) |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | template LapdmFrame LAPDm_B_RR(template GsmSapi sapi, template uint3_t nr) modifies t_nopayload := { |
| 124 | ab := { |
| 125 | ctrl := tr_LapdmCtrlRR(nr, false) |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | |
| 130 | function f_test_sabm_results_in_ua(uint8_t sapi, boolean use_sacch, octetstring payload) runs on lapdm_test_CT return boolean { |
| 131 | var LAPDm_ph_data phd; |
| 132 | var boolean result := false; |
| 133 | timer T := 5.0; |
| 134 | |
| 135 | f_establish_dcch(); |
| 136 | LAPDM.send(t_PH_DATA(sapi, use_sacch, LAPDm_B_SABM(sapi, payload))); |
| 137 | log("====> expecting ", t_PH_DATA(sapi, use_sacch, LAPDm_B_UA(sapi, payload))); |
| 138 | T.start |
| 139 | alt { |
| 140 | [] LAPDM.receive(t_PH_DATA(?, use_sacch, LAPDm_B_UA(sapi, payload))) { result := true; } |
| 141 | [] LAPDM.receive(t_PH_DATA(?, use_sacch, ?)) -> value phd { log("Other msg on DCH: ", phd); repeat; } |
| 142 | [] LAPDM.receive(t_PH_DATA(?, ?, ?)) -> value phd { log("Other PH-DATA: ", phd); repeat; } |
| 143 | [] T.timeout { } |
| 144 | } |
| 145 | LAPDM.send(t_PH_DATA(sapi, use_sacch, LAPDm_B_RR(sapi, 0))); |
| 146 | f_release_dcch(); |
| 147 | return result; |
| 148 | } |
| 149 | |
| 150 | testcase TC_sabm_ua_dcch_sapi0() runs on lapdm_test_CT { |
Harald Welte | 61332c0 | 2019-05-30 16:45:15 +0200 | [diff] [blame] | 151 | f_lapdm_init(); |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 152 | if (not f_test_sabm_results_in_ua(0, false, 'FEFE'O)) { |
| 153 | setverdict(fail); |
| 154 | } |
| 155 | setverdict(pass); |
| 156 | } |
| 157 | |
| 158 | testcase TC_sabm_ua_dcch_sapi0_nopayload() runs on lapdm_test_CT { |
Harald Welte | 61332c0 | 2019-05-30 16:45:15 +0200 | [diff] [blame] | 159 | f_lapdm_init(); |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 160 | if (f_test_sabm_results_in_ua(0, false, ''O)) { |
| 161 | setverdict(fail, "Initial SABM/UA must contain L3 payload but BTS accepts without"); |
| 162 | } |
| 163 | setverdict(pass); |
| 164 | } |
| 165 | |
| 166 | testcase TC_sabm_ua_dcch_sapi3() runs on lapdm_test_CT { |
Harald Welte | 61332c0 | 2019-05-30 16:45:15 +0200 | [diff] [blame] | 167 | f_lapdm_init(); |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 168 | if (f_test_sabm_results_in_ua(3, false, 'FEFE'O)) { |
| 169 | setverdict(fail, "Initial SABM/UA must be on SAPI0, but BTS accepts SAPI=3"); |
| 170 | } |
| 171 | setverdict(pass); |
| 172 | } |
| 173 | |
| 174 | testcase TC_sabm_ua_dcch_sapi4() runs on lapdm_test_CT { |
Harald Welte | 61332c0 | 2019-05-30 16:45:15 +0200 | [diff] [blame] | 175 | f_lapdm_init(); |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 176 | if (f_test_sabm_results_in_ua(4, false, 'FEFE'O)) { |
| 177 | setverdict(fail, "Initial SABM/UA must be on SAPI0, but BTS accepts SAPI=4"); |
| 178 | } |
| 179 | setverdict(pass); |
| 180 | } |
| 181 | |
| 182 | testcase TC_sabm_contention() runs on lapdm_test_CT { |
| 183 | var LAPDm_ph_data phd; |
| 184 | const octetstring payload := '0102030405'O; |
| 185 | const GsmSapi sapi := 0; |
| 186 | const boolean use_sacch := false; |
| 187 | timer T := 5.0; |
| 188 | |
Harald Welte | 61332c0 | 2019-05-30 16:45:15 +0200 | [diff] [blame] | 189 | f_lapdm_init(); |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 190 | |
| 191 | f_establish_dcch(); |
| 192 | /* first frame is our real SABM */ |
| 193 | LAPDM.send(t_PH_DATA(sapi, use_sacch, LAPDm_B_SABM(sapi, payload))); |
| 194 | /* second frame is a SABM with different payload, which BTS has to ignore according to 8.4.1.4 */ |
| 195 | LAPDM.send(t_PH_DATA(sapi, use_sacch, LAPDm_B_SABM(sapi, 'ABCDEF'O))); |
| 196 | log("====> expecting ", t_PH_DATA(sapi, use_sacch, LAPDm_B_UA(sapi, payload))); |
| 197 | T.start |
| 198 | alt { |
| 199 | [] LAPDM.receive(t_PH_DATA(?, use_sacch, LAPDm_B_UA(sapi, payload))) { setverdict(pass); repeat; } |
| 200 | [] LAPDM.receive(t_PH_DATA(?, use_sacch, tr_LAPDm_B_UA(sapi, ?))) { |
| 201 | setverdict(fail, "Second SABM was responded to during contention resolution"); |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 202 | } |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 203 | [] LAPDM.receive { repeat }; |
| 204 | [] T.timeout { } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 205 | } |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 206 | f_release_dcch(); |
| 207 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 208 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 209 | /* we test that a re-transmitted SABM with identical payload will result in the retransmission of a |
| 210 | * UA. This is required during the contention resolution procedure as specified in 8.4.1.4 */ |
| 211 | testcase TC_sabm_retransmit() runs on lapdm_test_CT { |
| 212 | const octetstring payload := '00FEFEDEADBEEF'O; |
Harald Welte | 61332c0 | 2019-05-30 16:45:15 +0200 | [diff] [blame] | 213 | f_lapdm_init(); |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 214 | if (not f_test_sabm_results_in_ua(0, false, payload)) { |
| 215 | setverdict(fail, "UA not received for first SABM"); |
Harald Welte | 599faa1 | 2017-07-17 21:49:24 +0200 | [diff] [blame] | 216 | } |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 217 | if (not f_test_sabm_results_in_ua(0, false, payload)) { |
| 218 | setverdict(fail, "UA not received for second SABM"); |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 219 | } |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 220 | setverdict(pass); |
| 221 | } |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 222 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 223 | testcase TC_foo() runs on lapdm_test_CT { |
| 224 | var LapdmFrame lf; |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 225 | /* |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 226 | var LapdmFrame lf := valueof(LAPDm_B_UA(0, ''O)); |
| 227 | log("ENC UA: ", enc_LapdmFrame(lf)); |
| 228 | lf := valueof(LAPDm_B_UI(0, ''O)); |
| 229 | log("ENC UI B: ", enc_LapdmFrame(lf)); |
| 230 | log("ENC UI B: ", enc_LapdmFrameB(lf.b)); |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 231 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 232 | log("DEC UI AF: ", dec_LapdmAddressField('03'O)); |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 233 | */ |
Harald Welte | ffcad68 | 2017-07-30 22:51:04 +0200 | [diff] [blame] | 234 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 235 | lf := valueof(LAPDm_B_RR(0, 0)); |
| 236 | log("ENC RR: ", enc_LapdmFrame(lf)); |
Harald Welte | ffcad68 | 2017-07-30 22:51:04 +0200 | [diff] [blame] | 237 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 238 | lf := valueof(LAPDm_B_UA(0, ''O)); |
| 239 | log("ENC UA: ", enc_LapdmFrame(lf)); |
Harald Welte | ffcad68 | 2017-07-30 22:51:04 +0200 | [diff] [blame] | 240 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 241 | lf := valueof(LAPDm_B_UI(0, ''O)); |
| 242 | log("ENC UI: ", enc_LapdmFrame(lf)); |
Harald Welte | ffcad68 | 2017-07-30 22:51:04 +0200 | [diff] [blame] | 243 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 244 | log("DEC UI CU: ", dec_LapdmCtrlU('03'O)); |
| 245 | log("DEC UI CT: ", dec_LapdmCtrl('03'O)); |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 246 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 247 | log("DEC UA: ", dec_LapdmFrameAB('017301'O)); |
| 248 | log("DEC UI: ", dec_LapdmFrameAB('030301'O)); |
| 249 | log("DEC I: ", dec_LapdmFrameAB('030001'O)); |
| 250 | log("DEC S: ", dec_LapdmFrameAB('030101'O)); |
| 251 | log("DEC: ", dec_LapdmFrameAB('030301'O)); |
| 252 | log("DEC: ", dec_LapdmFrameAB('0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O)); |
| 253 | } |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 254 | |
Harald Welte | 72c81e7 | 2019-05-30 16:36:11 +0200 | [diff] [blame] | 255 | control { |
| 256 | execute(TC_foo()); |
| 257 | execute(TC_sabm_ua_dcch_sapi0()); |
| 258 | execute(TC_sabm_ua_dcch_sapi0_nopayload()); |
| 259 | execute(TC_sabm_ua_dcch_sapi3()); |
| 260 | execute(TC_sabm_ua_dcch_sapi4()); |
| 261 | execute(TC_sabm_contention()); |
| 262 | execute(TC_sabm_retransmit()); |
| 263 | } |
| 264 | |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 265 | } |