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 | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 7 | type component dummy_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 | 52c713c | 2017-07-16 15:44:44 +0200 | [diff] [blame] | 12 | function f_init() runs on dummy_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 | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 26 | function f_establish_dcch() runs on dummy_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 | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 36 | function f_release_dcch() runs on dummy_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 | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 48 | b := { |
| 49 | addr := tr_LapdmAddr(sapi, false), |
| 50 | ctrl := t_LapdmCtrlSABM(true), |
| 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) := { |
| 60 | b := { |
| 61 | addr := tr_LapdmAddr(sapi, false), |
| 62 | ctrl := t_LapdmCtrlUA(true), |
| 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 | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 72 | b := { |
| 73 | addr := tr_LapdmAddr(sapi, false), |
| 74 | ctrl := t_LapdmCtrlUA(true), |
| 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 | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 84 | b := { |
| 85 | addr := tr_LapdmAddr(sapi, true), |
| 86 | ctrl := t_LapdmCtrlUI(false), |
| 87 | len := lengthof(payload), |
| 88 | m := false, |
| 89 | el := 1, |
| 90 | payload := payload |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | function f_test_sabm_results_in_ua(uint8_t sapi, boolean use_sacch, octetstring payload) runs on dummy_CT return boolean { |
| 95 | var LAPDm_ph_data phd; |
| 96 | var boolean result := false; |
| 97 | timer T := 5.0; |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 98 | |
| 99 | f_establish_dcch(); |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 100 | LAPDM.send(t_PH_DATA(sapi, use_sacch, LAPDm_B_SABM(sapi, payload))); |
| 101 | log("====> expecting ", t_PH_DATA(sapi, use_sacch, LAPDm_B_UA(sapi, payload))); |
| 102 | T.start |
| 103 | alt { |
Harald Welte | dca7e45 | 2017-07-17 21:43:58 +0200 | [diff] [blame] | 104 | [] LAPDM.receive(t_PH_DATA(?, use_sacch, LAPDm_B_UA(sapi, payload))) { result := true; } |
| 105 | [] 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] | 106 | [] 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] | 107 | [] T.timeout { } |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 108 | } |
Harald Welte | 9e4725d | 2017-07-16 23:18:09 +0200 | [diff] [blame] | 109 | f_release_dcch(); |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 110 | return result; |
| 111 | } |
Harald Welte | 66110f0 | 2017-07-16 21:05:18 +0200 | [diff] [blame] | 112 | |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 113 | testcase TC_sabm_ua_dcch_sapi0() runs on dummy_CT { |
| 114 | f_init(); |
| 115 | if (not f_test_sabm_results_in_ua(0, false, 'FEFE'O)) { |
| 116 | setverdict(fail); |
| 117 | } |
Harald Welte | 66110f0 | 2017-07-16 21:05:18 +0200 | [diff] [blame] | 118 | setverdict(pass); |
| 119 | } |
| 120 | |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 121 | testcase TC_sabm_ua_dcch_sapi0_nopayload() runs on dummy_CT { |
| 122 | f_init(); |
Harald Welte | dca7e45 | 2017-07-17 21:43:58 +0200 | [diff] [blame] | 123 | if (f_test_sabm_results_in_ua(0, false, ''O)) { |
| 124 | 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] | 125 | } |
| 126 | setverdict(pass); |
| 127 | } |
| 128 | |
| 129 | testcase TC_sabm_ua_dcch_sapi3() runs on dummy_CT { |
| 130 | f_init(); |
Harald Welte | dca7e45 | 2017-07-17 21:43:58 +0200 | [diff] [blame] | 131 | if (f_test_sabm_results_in_ua(3, false, 'FEFE'O)) { |
| 132 | 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] | 133 | } |
| 134 | setverdict(pass); |
| 135 | } |
| 136 | |
| 137 | testcase TC_sabm_ua_dcch_sapi4() runs on dummy_CT { |
| 138 | f_init(); |
Harald Welte | dca7e45 | 2017-07-17 21:43:58 +0200 | [diff] [blame] | 139 | if (f_test_sabm_results_in_ua(4, false, 'FEFE'O)) { |
| 140 | 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] | 141 | } |
| 142 | setverdict(pass); |
| 143 | } |
| 144 | |
Harald Welte | 599faa1 | 2017-07-17 21:49:24 +0200 | [diff] [blame] | 145 | testcase TC_sabm_contention() runs on dummy_CT { |
| 146 | var LAPDm_ph_data phd; |
| 147 | const octetstring payload := '0102030405'O; |
| 148 | const GsmSapi sapi := 0; |
| 149 | const boolean use_sacch := false; |
| 150 | timer T := 5.0; |
| 151 | |
| 152 | f_init(); |
| 153 | |
| 154 | f_establish_dcch(); |
| 155 | /* first frame is our real SABM */ |
| 156 | LAPDM.send(t_PH_DATA(sapi, use_sacch, LAPDm_B_SABM(sapi, payload))); |
| 157 | /* second frame is a SABM with different payload, which BTS has to ignore according to 8.4.1.4 */ |
| 158 | LAPDM.send(t_PH_DATA(sapi, use_sacch, LAPDm_B_SABM(sapi, 'ABCDEF'O))); |
| 159 | log("====> expecting ", t_PH_DATA(sapi, use_sacch, LAPDm_B_UA(sapi, payload))); |
| 160 | T.start |
| 161 | alt { |
| 162 | [] LAPDM.receive(t_PH_DATA(?, use_sacch, LAPDm_B_UA(sapi, payload))) { setverdict(pass); repeat; } |
| 163 | [] LAPDM.receive(t_PH_DATA(?, use_sacch, tr_LAPDm_B_UA(sapi, ?))) { |
| 164 | setverdict(fail, "Second SABM was responded to during contention resolution"); |
| 165 | } |
| 166 | [] LAPDM.receive { repeat }; |
| 167 | [] T.timeout { } |
| 168 | } |
| 169 | f_release_dcch(); |
| 170 | } |
| 171 | |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 172 | |
| 173 | testcase TC_foo() runs on dummy_CT { |
| 174 | /* |
| 175 | var LapdmFrame lf := valueof(LAPDm_B_UA(0, ''O)); |
| 176 | log("ENC UA: ", enc_LapdmFrame(lf)); |
| 177 | lf := valueof(LAPDm_B_UI(0, ''O)); |
| 178 | log("ENC UI B: ", enc_LapdmFrame(lf)); |
| 179 | log("ENC UI B: ", enc_LapdmFrameB(lf.b)); |
| 180 | |
| 181 | log("DEC UI AF: ", dec_LapdmAddressField('03'O)); |
| 182 | */ |
| 183 | log("DEC UI CU: ", dec_LapdmCtrlU('03'O)); |
| 184 | log("DEC UI CT: ", dec_LapdmCtrl('03'O)); |
| 185 | |
| 186 | log("DEC UA: ", dec_LapdmFrameB('017301'O)); |
| 187 | log("DEC UI: ", dec_LapdmFrameA('030301'O)); |
| 188 | log("DEC I: ", dec_LapdmFrameA('030001'O)); |
| 189 | log("DEC S: ", dec_LapdmFrameA('030101'O)); |
| 190 | log("DEC: ", dec_LapdmFrameB('030301'O)); |
| 191 | log("DEC: ", dec_LapdmFrameB('0303012B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B2B'O)); |
| 192 | } |
| 193 | |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 194 | control { |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 195 | execute(TC_foo()); |
| 196 | execute(TC_sabm_ua_dcch_sapi0()); |
Harald Welte | d4ba7ff | 2017-07-17 21:00:48 +0200 | [diff] [blame] | 197 | execute(TC_sabm_ua_dcch_sapi0_nopayload()); |
| 198 | execute(TC_sabm_ua_dcch_sapi3()); |
| 199 | execute(TC_sabm_ua_dcch_sapi4()); |
Harald Welte | 599faa1 | 2017-07-17 21:49:24 +0200 | [diff] [blame] | 200 | execute(TC_sabm_contention()); |
Harald Welte | f654332 | 2017-07-16 07:35:10 +0200 | [diff] [blame] | 201 | } |
| 202 | } |