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